aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-08-24 15:29:12 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-08-25 15:46:43 +0200
commitf70fa989547a256255ae74264ac6e906709b72f4 (patch)
treef49beefd8ad801a6950f3762783774565a70fccf /components/script/dom/bindings
parentfbc8938bee86cdc8c9427092b8b2c5dd8286a47b (diff)
downloadservo-f70fa989547a256255ae74264ac6e906709b72f4.tar.gz
servo-f70fa989547a256255ae74264ac6e906709b72f4.zip
Make has_property_on_prototype fallible
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py35
-rw-r--r--components/script/dom/bindings/utils.rs13
2 files changed, 33 insertions, 15 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 8e04fc76a10..4eb02f796e0 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -4724,10 +4724,17 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
# Once we start supporting OverrideBuiltins we need to make
# ResolveOwnProperty or EnumerateOwnProperties filter out named
# properties that shadow prototype properties.
- namedGet = ("\n" +
- "if RUST_JSID_IS_STRING(id) && !has_property_on_prototype(cx, proxy, id) {\n" +
- CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
- "}\n")
+ namedGet = """
+if RUST_JSID_IS_STRING(id) {
+ let mut has_on_proto = false;
+ 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:
namedGet = ""
@@ -4952,12 +4959,20 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter:
- named = ("if RUST_JSID_IS_STRING(id) && !has_property_on_prototype(cx, proxy, id) {\n" +
- CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
- " *bp = found;\n"
- " return true;\n"
- "}\n" +
- "\n")
+ named = """\
+if RUST_JSID_IS_STRING(id) {
+ let mut has_on_proto = false;
+ if !has_property_on_prototype(cx, proxy, id, &mut has_on_proto) {
+ return false;
+ }
+ if !has_on_proto {
+ %s
+ *bp = found;
+ return true;
+ }
+}
+
+""" % CGIndenter(CGProxyNamedGetter(self.descriptor), 8).define()
else:
named = ""
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 53b69fc0b40..666dba519a4 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -284,12 +284,15 @@ pub fn set_dictionary_property(cx: *mut JSContext,
/// Returns whether `proxy` has a property `id` on its prototype.
pub unsafe fn has_property_on_prototype(cx: *mut JSContext,
proxy: HandleObject,
- id: HandleId)
+ id: HandleId,
+ found: &mut bool)
-> bool {
- let mut found = false;
- !get_property_on_prototype(
- cx, proxy, id, &mut found,
- MutableHandleValue::from_marked_location(ptr::null_mut())) || found
+ rooted!(in(cx) let mut proto = ptr::null_mut());
+ if !JS_GetPrototype(cx, proxy, proto.handle_mut()) {
+ return false;
+ }
+ assert!(!proto.is_null());
+ JS_HasPropertyById(cx, proto.handle(), id, found)
}
/// Drop the resources held by reserved slots of a global object