mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
feat(core): implement Deno.core.isProxy() (#12288)
This commit is contained in:
parent
1dfa35b2ba
commit
26de516558
2 changed files with 33 additions and 0 deletions
|
@ -63,6 +63,9 @@ lazy_static::lazy_static! {
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
function: get_proxy_details.map_fn_to()
|
function: get_proxy_details.map_fn_to()
|
||||||
},
|
},
|
||||||
|
v8::ExternalReference {
|
||||||
|
function: is_proxy.map_fn_to()
|
||||||
|
},
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
function: memory_usage.map_fn_to(),
|
function: memory_usage.map_fn_to(),
|
||||||
},
|
},
|
||||||
|
@ -146,6 +149,7 @@ pub fn initialize_context<'s>(
|
||||||
set_func(scope, core_val, "deserialize", deserialize);
|
set_func(scope, core_val, "deserialize", deserialize);
|
||||||
set_func(scope, core_val, "getPromiseDetails", get_promise_details);
|
set_func(scope, core_val, "getPromiseDetails", get_promise_details);
|
||||||
set_func(scope, core_val, "getProxyDetails", get_proxy_details);
|
set_func(scope, core_val, "getProxyDetails", get_proxy_details);
|
||||||
|
set_func(scope, core_val, "isProxy", is_proxy);
|
||||||
set_func(scope, core_val, "memoryUsage", memory_usage);
|
set_func(scope, core_val, "memoryUsage", memory_usage);
|
||||||
set_func(scope, core_val, "callConsole", call_console);
|
set_func(scope, core_val, "callConsole", call_console);
|
||||||
set_func(scope, core_val, "createHostObject", create_host_object);
|
set_func(scope, core_val, "createHostObject", create_host_object);
|
||||||
|
@ -1119,6 +1123,14 @@ fn get_proxy_details(
|
||||||
rv.set(to_v8(scope, p).unwrap());
|
rv.set(to_v8(scope, p).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_proxy(
|
||||||
|
scope: &mut v8::HandleScope,
|
||||||
|
args: v8::FunctionCallbackArguments,
|
||||||
|
mut rv: v8::ReturnValue,
|
||||||
|
) {
|
||||||
|
rv.set(v8::Boolean::new(scope, args.get(0).is_proxy()).into())
|
||||||
|
}
|
||||||
|
|
||||||
fn throw_type_error(scope: &mut v8::HandleScope, message: impl AsRef<str>) {
|
fn throw_type_error(scope: &mut v8::HandleScope, message: impl AsRef<str>) {
|
||||||
let message = v8::String::new(scope, message.as_ref()).unwrap();
|
let message = v8::String::new(scope, message.as_ref()).unwrap();
|
||||||
let exception = v8::Exception::type_error(scope, message);
|
let exception = v8::Exception::type_error(scope, message);
|
||||||
|
|
|
@ -2273,4 +2273,25 @@ assertEquals(1, notify_return_value);
|
||||||
let mut runtime = JsRuntime::new(options);
|
let mut runtime = JsRuntime::new(options);
|
||||||
runtime.execute_script("<none>", "").unwrap();
|
runtime.execute_script("<none>", "").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_proxy() {
|
||||||
|
let mut runtime = JsRuntime::new(RuntimeOptions::default());
|
||||||
|
let all_true: v8::Global<v8::Value> = runtime
|
||||||
|
.execute_script(
|
||||||
|
"is_proxy.js",
|
||||||
|
r#"
|
||||||
|
(function () {
|
||||||
|
const { isProxy } = Deno.core;
|
||||||
|
const o = { a: 1, b: 2};
|
||||||
|
const p = new Proxy(o, {});
|
||||||
|
return isProxy(p) && !isProxy(o) && !isProxy(42);
|
||||||
|
})()
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let mut scope = runtime.handle_scope();
|
||||||
|
let all_true = v8::Local::<v8::Value>::new(&mut scope, &all_true);
|
||||||
|
assert!(all_true.is_true());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue