diff options
author | Delan Azabani <dazabani@igalia.com> | 2023-03-03 22:08:49 +0800 |
---|---|---|
committer | Delan Azabani <dazabani@igalia.com> | 2023-03-23 18:07:05 +0800 |
commit | 33387eb75a87ff0ba0e3d0f104d23e248d0c471b (patch) | |
tree | a9fddb0d2c291178f889f1818f7f11f2594a3795 /components/script | |
parent | 9a3d6969c96bdae299f051e4411d9972858b66d0 (diff) | |
download | servo-33387eb75a87ff0ba0e3d0f104d23e248d0c471b.tar.gz servo-33387eb75a87ff0ba0e3d0f104d23e248d0c471b.zip |
make getOwnPropertyDescriptor trap accept integer indices
Several /webidl/ecmascript-binding/window-named-properties-object.html
subtests, including the “[[GetOwnProperty]]” and “[[HasProperty]]”
subtests, expect iframe.contentWindow.Window.prototype[0] to return an
element with id “0”.
This commit makes the getOwnPropertyDescriptor trap accept property
keys that are integer indices, by converting them to a DOMString just
like we would for a property key that is a JSString.
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/window_named_properties.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/components/script/window_named_properties.rs b/components/script/window_named_properties.rs index 289e4f7372d..33955b954bc 100644 --- a/components/script/window_named_properties.rs +++ b/components/script/window_named_properties.rs @@ -84,10 +84,6 @@ unsafe extern "C" fn get_own_property_descriptor( is_none: *mut bool, ) -> bool { let cx = SafeJSContext::from_ptr(cx); - if !id.is_string() { - // Nothing to do if we're resolving a non-string property. - return true; - } let mut found = false; if !has_property_on_prototype( @@ -102,7 +98,19 @@ unsafe extern "C" fn get_own_property_descriptor( return true; } - let s = jsstr_to_string(*cx, id.to_string()); + let s = if id.is_string() { + jsstr_to_string(*cx, id.to_string()) + } else if id.is_int() { + // If the property key is an integer index, convert it to a String too. + // TODO(delan) will this interfere with indexed access on the Window object + // (window[index]), which should only return document-tree child navigables? + // https://html.spec.whatwg.org/#accessing-other-browsing-contexts + id.to_int().to_string() + } else { + // TODO(delan) what do we do if the property key is a symbol? + warn!("[[GetOwnProperty]] called with id neither string nor int: {:?}", id.get()); + return true; + }; if s.is_empty() { return true; } |