diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/node/global.rs | 66 | ||||
-rw-r--r-- | ext/node/ops/vm_internal.rs | 67 |
2 files changed, 75 insertions, 58 deletions
diff --git a/ext/node/global.rs b/ext/node/global.rs index d2fe7a1e5..5c95b2f8f 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -15,13 +15,13 @@ use crate::resolution::NodeResolverRc; // these mapped functions per-thread. We should revisit it in the future and // ideally remove altogether. thread_local! { - pub static GETTER_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = getter.map_fn_to(); - pub static SETTER_MAP_FN: v8::GenericNamedPropertySetterCallback<'static> = setter.map_fn_to(); - pub static QUERY_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = query.map_fn_to(); - pub static DELETER_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = deleter.map_fn_to(); - pub static ENUMERATOR_MAP_FN: v8::GenericNamedPropertyEnumeratorCallback<'static> = enumerator.map_fn_to(); - pub static DEFINER_MAP_FN: v8::GenericNamedPropertyDefinerCallback<'static> = definer.map_fn_to(); - pub static DESCRIPTOR_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = descriptor.map_fn_to(); + pub static GETTER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = getter.map_fn_to(); + pub static SETTER_MAP_FN: v8::NamedPropertySetterCallback<'static> = setter.map_fn_to(); + pub static QUERY_MAP_FN: v8::NamedPropertyGetterCallback<'static> = query.map_fn_to(); + pub static DELETER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = deleter.map_fn_to(); + pub static ENUMERATOR_MAP_FN: v8::NamedPropertyEnumeratorCallback<'static> = enumerator.map_fn_to(); + pub static DEFINER_MAP_FN: v8::NamedPropertyDefinerCallback<'static> = definer.map_fn_to(); + pub static DESCRIPTOR_MAP_FN: v8::NamedPropertyGetterCallback<'static> = descriptor.map_fn_to(); } /// Convert an ASCII string to a UTF-16 byte encoding of the string. @@ -287,9 +287,9 @@ pub fn getter<'s>( key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let this = args.this(); @@ -311,10 +311,11 @@ pub fn getter<'s>( undefined.into(), &[inner.into(), key.into(), this.into()], ) else { - return; + return v8::Intercepted::No; }; rv.set(value); + v8::Intercepted::Yes } pub fn setter<'s>( @@ -323,9 +324,9 @@ pub fn setter<'s>( value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let this = args.this(); @@ -348,10 +349,11 @@ pub fn setter<'s>( undefined.into(), &[inner.into(), key.into(), value, this.into()], ) else { - return; + return v8::Intercepted::No; }; rv.set(success); + v8::Intercepted::Yes } pub fn query<'s>( @@ -359,9 +361,9 @@ pub fn query<'s>( key: v8::Local<'s, v8::Name>, _args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let mode = current_mode(scope); @@ -373,15 +375,16 @@ pub fn query<'s>( let inner = v8::Local::new(scope, inner); let Some(true) = inner.has_own_property(scope, key) else { - return; + return v8::Intercepted::No; }; let Some(attributes) = inner.get_property_attributes(scope, key.into()) else { - return; + return v8::Intercepted::No; }; rv.set_uint32(attributes.as_u32()); + v8::Intercepted::Yes } pub fn deleter<'s>( @@ -389,9 +392,9 @@ pub fn deleter<'s>( key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let mode = current_mode(scope); @@ -404,17 +407,18 @@ pub fn deleter<'s>( let inner = v8::Local::new(scope, inner); let Some(success) = inner.delete(scope, key.into()) else { - return; + return v8::Intercepted::No; }; if args.should_throw_on_error() && !success { let message = v8::String::new(scope, "Cannot delete property").unwrap(); let exception = v8::Exception::type_error(scope, message); scope.throw_exception(exception); - return; + return v8::Intercepted::Yes; } rv.set_bool(success); + v8::Intercepted::Yes } pub fn enumerator<'s>( @@ -450,10 +454,10 @@ pub fn definer<'s>( key: v8::Local<'s, v8::Name>, descriptor: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, -) { + _rv: v8::ReturnValue, +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let mode = current_mode(scope); @@ -466,17 +470,16 @@ pub fn definer<'s>( let inner = v8::Local::new(scope, inner); let Some(success) = inner.define_property(scope, key, descriptor) else { - return; + return v8::Intercepted::No; }; if args.should_throw_on_error() && !success { let message = v8::String::new(scope, "Cannot define property").unwrap(); let exception = v8::Exception::type_error(scope, message); scope.throw_exception(exception); - return; } - rv.set_bool(success); + v8::Intercepted::Yes } pub fn descriptor<'s>( @@ -484,9 +487,9 @@ pub fn descriptor<'s>( key: v8::Local<'s, v8::Name>, _args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { if !is_managed_key(scope, key) { - return; + return v8::Intercepted::No; }; let mode = current_mode(scope); @@ -502,12 +505,13 @@ pub fn descriptor<'s>( let Some(descriptor) = inner.get_own_property_descriptor(scope, key) else { scope.rethrow().expect("to have caught an exception"); - return; + return v8::Intercepted::Yes; }; if descriptor.is_undefined() { - return; + return v8::Intercepted::No; } rv.set(descriptor); + v8::Intercepted::Yes } diff --git a/ext/node/ops/vm_internal.rs b/ext/node/ops/vm_internal.rs index 9c641954e..bbdcba632 100644 --- a/ext/node/ops/vm_internal.rs +++ b/ext/node/ops/vm_internal.rs @@ -215,12 +215,12 @@ extern "C" fn c_noop(_: *const v8::FunctionCallbackInfo) {} // // See NOTE in ext/node/global.rs#L12 thread_local! { - pub static GETTER_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = property_getter.map_fn_to(); - pub static SETTER_MAP_FN: v8::GenericNamedPropertySetterCallback<'static> = property_setter.map_fn_to(); - pub static DELETER_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = property_deleter.map_fn_to(); - pub static ENUMERATOR_MAP_FN: v8::GenericNamedPropertyEnumeratorCallback<'static> = property_enumerator.map_fn_to(); - pub static DEFINER_MAP_FN: v8::GenericNamedPropertyDefinerCallback<'static> = property_definer.map_fn_to(); - pub static DESCRIPTOR_MAP_FN: v8::GenericNamedPropertyGetterCallback<'static> = property_descriptor.map_fn_to(); + pub static GETTER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_getter.map_fn_to(); + pub static SETTER_MAP_FN: v8::NamedPropertySetterCallback<'static> = property_setter.map_fn_to(); + pub static DELETER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_deleter.map_fn_to(); + pub static ENUMERATOR_MAP_FN: v8::NamedPropertyEnumeratorCallback<'static> = property_enumerator.map_fn_to(); + pub static DEFINER_MAP_FN: v8::NamedPropertyDefinerCallback<'static> = property_definer.map_fn_to(); + pub static DESCRIPTOR_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_descriptor.map_fn_to(); } thread_local! { @@ -286,7 +286,7 @@ fn property_getter<'s>( key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, mut ret: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let sandbox = ctx.sandbox(scope); @@ -308,7 +308,10 @@ fn property_getter<'s>( } ret.set(rv); + return v8::Intercepted::Yes; } + + v8::Intercepted::No } fn property_setter<'s>( @@ -317,7 +320,7 @@ fn property_setter<'s>( value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let (attributes, is_declared_on_global_proxy) = match ctx @@ -339,7 +342,7 @@ fn property_setter<'s>( read_only |= attributes.is_read_only(); if read_only { - return; + return v8::Intercepted::No; } // true for x = 5 @@ -363,15 +366,15 @@ fn property_setter<'s>( && is_contextual_store && !is_function { - return; + return v8::Intercepted::No; } if !is_declared && key.is_symbol() { - return; + return v8::Intercepted::No; }; if ctx.sandbox(scope).set(scope, key.into(), value).is_none() { - return; + return v8::Intercepted::No; } if is_declared_on_sandbox { @@ -394,10 +397,13 @@ fn property_setter<'s>( .unwrap_or(false) { rv.set(value); + return v8::Intercepted::Yes; } } } } + + v8::Intercepted::No } fn property_deleter<'s>( @@ -405,17 +411,18 @@ fn property_deleter<'s>( key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let context = ctx.context(scope); let sandbox = ctx.sandbox(scope); let context_scope = &mut v8::ContextScope::new(scope, context); if !sandbox.delete(context_scope, key.into()).unwrap_or(false) { - return; + return v8::Intercepted::No; } rv.set_bool(false); + v8::Intercepted::Yes } fn property_enumerator<'s>( @@ -443,7 +450,7 @@ fn property_definer<'s>( desc: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, _: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let context = ctx.context(scope); @@ -461,7 +468,7 @@ fn property_definer<'s>( // If the property is set on the global as read_only, don't change it on // the global or sandbox. if is_declared && read_only && dont_delete { - return; + return v8::Intercepted::No; } let sandbox = ctx.sandbox(scope); @@ -512,6 +519,8 @@ fn property_definer<'s>( define_prop_on_sandbox(scope, &mut desc_for_sandbox); } } + + v8::Intercepted::Yes } fn property_descriptor<'s>( @@ -519,7 +528,7 @@ fn property_descriptor<'s>( key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let context = ctx.context(scope); @@ -529,8 +538,11 @@ fn property_descriptor<'s>( if sandbox.has_own_property(scope, key).unwrap_or(false) { if let Some(desc) = sandbox.get_own_property_descriptor(scope, key) { rv.set(desc); + return v8::Intercepted::Yes; } } + + v8::Intercepted::No } fn uint32_to_name<'s>( @@ -547,9 +559,9 @@ fn indexed_property_getter<'s>( index: u32, args: v8::PropertyCallbackArguments<'s>, rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let key = uint32_to_name(scope, index); - property_getter(scope, key, args, rv); + property_getter(scope, key, args, rv) } fn indexed_property_setter<'s>( @@ -558,9 +570,9 @@ fn indexed_property_setter<'s>( value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let key = uint32_to_name(scope, index); - property_setter(scope, key, value, args, rv); + property_setter(scope, key, value, args, rv) } fn indexed_property_deleter<'s>( @@ -568,19 +580,20 @@ fn indexed_property_deleter<'s>( index: u32, args: v8::PropertyCallbackArguments<'s>, mut rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let ctx = ContextifyContext::get(scope, args.this()).unwrap(); let context = ctx.context(scope); let sandbox = ctx.sandbox(scope); let context_scope = &mut v8::ContextScope::new(scope, context); if !sandbox.delete_index(context_scope, index).unwrap_or(false) { - return; + return v8::Intercepted::No; } // Delete failed on the sandbox, intercept and do not delete on // the global object. rv.set_bool(false); + v8::Intercepted::No } fn indexed_property_definer<'s>( @@ -589,9 +602,9 @@ fn indexed_property_definer<'s>( descriptor: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let key = uint32_to_name(scope, index); - property_definer(scope, key, descriptor, args, rv); + property_definer(scope, key, descriptor, args, rv) } fn indexed_property_descriptor<'s>( @@ -599,7 +612,7 @@ fn indexed_property_descriptor<'s>( index: u32, args: v8::PropertyCallbackArguments<'s>, rv: v8::ReturnValue, -) { +) -> v8::Intercepted { let key = uint32_to_name(scope, index); - property_descriptor(scope, key, args, rv); + property_descriptor(scope, key, args, rv) } |