2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-12-19 01:05:49 -05:00
|
|
|
use deno_core::op2;
|
|
|
|
use deno_core::v8;
|
2022-03-16 20:25:44 -04:00
|
|
|
use std::path::PathBuf;
|
2021-03-12 15:23:59 -05:00
|
|
|
|
2023-12-19 01:05:49 -05:00
|
|
|
deno_core::extension!(
|
|
|
|
deno_console,
|
2023-12-28 14:30:07 -05:00
|
|
|
ops = [op_is_any_arraybuffer, op_preview_entries,],
|
2023-12-19 01:05:49 -05:00
|
|
|
esm = ["01_console.js"],
|
|
|
|
);
|
2022-03-16 20:25:44 -04:00
|
|
|
|
|
|
|
pub fn get_declaration() -> PathBuf {
|
|
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts")
|
|
|
|
}
|
2023-12-19 01:05:49 -05:00
|
|
|
|
|
|
|
#[op2(fast)]
|
|
|
|
fn op_is_any_arraybuffer(value: &v8::Value) -> bool {
|
|
|
|
value.is_array_buffer() || value.is_shared_array_buffer()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[op2]
|
|
|
|
pub fn op_preview_entries<'s>(
|
|
|
|
scope: &mut v8::HandleScope<'s>,
|
|
|
|
object: &v8::Object,
|
|
|
|
slow_path: bool,
|
|
|
|
) -> v8::Local<'s, v8::Value> {
|
|
|
|
let (entries, is_key_value) = object.preview_entries(scope);
|
|
|
|
match entries {
|
|
|
|
None => v8::undefined(scope).into(),
|
|
|
|
Some(entries) => {
|
|
|
|
if !slow_path {
|
|
|
|
return entries.into();
|
|
|
|
}
|
|
|
|
|
|
|
|
let ret: [v8::Local<v8::Value>; 2] =
|
|
|
|
[entries.into(), v8::Boolean::new(scope, is_key_value).into()];
|
|
|
|
v8::Array::new_with_elements(scope, &ret).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|