mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Make has_property_on_prototype fallible
This commit is contained in:
parent
fbc8938bee
commit
f70fa98954
2 changed files with 33 additions and 15 deletions
|
@ -4724,10 +4724,17 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
# Once we start supporting OverrideBuiltins we need to make
|
# Once we start supporting OverrideBuiltins we need to make
|
||||||
# ResolveOwnProperty or EnumerateOwnProperties filter out named
|
# ResolveOwnProperty or EnumerateOwnProperties filter out named
|
||||||
# properties that shadow prototype properties.
|
# properties that shadow prototype properties.
|
||||||
namedGet = ("\n" +
|
namedGet = """
|
||||||
"if RUST_JSID_IS_STRING(id) && !has_property_on_prototype(cx, proxy, id) {\n" +
|
if RUST_JSID_IS_STRING(id) {
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
|
let mut has_on_proto = false;
|
||||||
"}\n")
|
if !has_property_on_prototype(cx, proxy, id, &mut has_on_proto) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if !has_on_proto {
|
||||||
|
%s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""" % CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues), 8).define()
|
||||||
else:
|
else:
|
||||||
namedGet = ""
|
namedGet = ""
|
||||||
|
|
||||||
|
@ -4952,12 +4959,20 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
|
|
||||||
namedGetter = self.descriptor.operations['NamedGetter']
|
namedGetter = self.descriptor.operations['NamedGetter']
|
||||||
if namedGetter:
|
if namedGetter:
|
||||||
named = ("if RUST_JSID_IS_STRING(id) && !has_property_on_prototype(cx, proxy, id) {\n" +
|
named = """\
|
||||||
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
|
if RUST_JSID_IS_STRING(id) {
|
||||||
" *bp = found;\n"
|
let mut has_on_proto = false;
|
||||||
" return true;\n"
|
if !has_property_on_prototype(cx, proxy, id, &mut has_on_proto) {
|
||||||
"}\n" +
|
return false;
|
||||||
"\n")
|
}
|
||||||
|
if !has_on_proto {
|
||||||
|
%s
|
||||||
|
*bp = found;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
""" % CGIndenter(CGProxyNamedGetter(self.descriptor), 8).define()
|
||||||
else:
|
else:
|
||||||
named = ""
|
named = ""
|
||||||
|
|
||||||
|
|
|
@ -284,12 +284,15 @@ pub fn set_dictionary_property(cx: *mut JSContext,
|
||||||
/// Returns whether `proxy` has a property `id` on its prototype.
|
/// Returns whether `proxy` has a property `id` on its prototype.
|
||||||
pub unsafe fn has_property_on_prototype(cx: *mut JSContext,
|
pub unsafe fn has_property_on_prototype(cx: *mut JSContext,
|
||||||
proxy: HandleObject,
|
proxy: HandleObject,
|
||||||
id: HandleId)
|
id: HandleId,
|
||||||
|
found: &mut bool)
|
||||||
-> bool {
|
-> bool {
|
||||||
let mut found = false;
|
rooted!(in(cx) let mut proto = ptr::null_mut());
|
||||||
!get_property_on_prototype(
|
if !JS_GetPrototype(cx, proxy, proto.handle_mut()) {
|
||||||
cx, proxy, id, &mut found,
|
return false;
|
||||||
MutableHandleValue::from_marked_location(ptr::null_mut())) || found
|
}
|
||||||
|
assert!(!proto.is_null());
|
||||||
|
JS_HasPropertyById(cx, proto.handle(), id, found)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drop the resources held by reserved slots of a global object
|
/// Drop the resources held by reserved slots of a global object
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue