From 8814e4bb4faf6ca4ba744aecc089e39875f08b92 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Fri, 3 Mar 2023 19:35:11 +0800 Subject: [PATCH] fix failures in [[DefineOwnProperty]] subtest Calling throw_type_error in the [[DefineOwnProperty]] trap (and returning false) makes the internal method throw a TypeError, which means both Object#defineProperty and Reflect#defineProperty will throw a TypeError, but we actually want the latter to return false. This commit makes the trap set ObjectOpResult to a TypeError (and return true), making the internal method return false per the spec [1] and in turn allowing Reflect#defineProperty to return false. [1] https://webidl.spec.whatwg.org/#named-properties-object-defineownproperty --- components/script/window_named_properties.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/components/script/window_named_properties.rs b/components/script/window_named_properties.rs index 320a80851a0..aeb8e3b20eb 100644 --- a/components/script/window_named_properties.rs +++ b/components/script/window_named_properties.rs @@ -11,7 +11,6 @@ use crate::dom::window::Window; use crate::js::conversions::ToJSValConvertible; use crate::script_runtime::JSContext as SafeJSContext; use js::conversions::jsstr_to_string; -use js::error::throw_type_error; use js::glue::RUST_JSID_TO_STRING; use js::glue::{CreateProxyHandler, NewProxyObject, ProxyTraps, RUST_JSID_IS_STRING}; use js::jsapi::JS_SetImmutablePrototype; @@ -131,17 +130,14 @@ unsafe extern "C" fn own_property_keys( #[allow(unsafe_code)] unsafe extern "C" fn define_property( - cx: *mut JSContext, + _cx: *mut JSContext, _proxy: HandleObject, _id: HandleId, _desc: Handle, - _result: *mut ObjectOpResult, + result: *mut ObjectOpResult, ) -> bool { - throw_type_error( - cx, - "Not allowed to define a property on the named properties object.", - ); - false + (*result).code_ = JSErrNum::JSMSG_CANT_DEFINE_WINDOW_NAMED_PROPERTY as usize; + true } #[allow(unsafe_code)]