diff --git a/servo/src/components/script/dom/bindings/codegen/CodegenRust.py b/servo/src/components/script/dom/bindings/codegen/CodegenRust.py index 5da64c1c3d8c..27e7e344dfab 100644 --- a/servo/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/servo/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -3547,10 +3547,10 @@ return box_;""" % self.descriptor.concreteType) class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): def __init__(self, descriptor): args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), - Argument('jsid', 'id'), Argument('JSBool', 'set'), + Argument('jsid', 'id'), Argument('bool', 'set'), Argument('*mut JSPropertyDescriptor', 'desc')] CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor", - "JSBool", args) + "bool", args) self.descriptor = descriptor def getBody(self): indexedGetter = self.descriptor.operations['IndexedGetter'] @@ -3562,7 +3562,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): if indexedGetter: readonly = toStringBool(self.descriptor.operations['IndexedSetter'] is None) - fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn 1;" % readonly + fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor} get = ("if index.is_some() {\n" + " let index = index.unwrap();\n" + @@ -3581,7 +3581,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): # FIXME need to check that this is a 'supported property index' assert False setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" + - " return 1;\n" + + " return true;\n" + " }\n") if self.descriptor.operations['NamedSetter']: setOrIndexedGet += " if RUST_JSID_IS_STRING(id) {\n" @@ -3589,7 +3589,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): # FIXME need to check that this is a 'supported property name' assert False setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" + - " return 1;\n" + + " return true;\n" + " }\n") setOrIndexedGet += "}" if indexedGetter: @@ -3598,20 +3598,20 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): "}") setOrIndexedGet += "\n\n" elif indexedGetter: - setOrIndexedGet += ("if set == 0 {\n" + + setOrIndexedGet += ("if !set {\n" + CGIndenter(CGGeneric(get)).define() + "}\n\n") namedGetter = self.descriptor.operations['NamedGetter'] if namedGetter: readonly = toStringBool(self.descriptor.operations['NamedSetter'] is None) - fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn 1;" % readonly + fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor} # Once we start supporting OverrideBuiltins we need to make # ResolveOwnProperty or EnumerateOwnProperties filter out named # properties that shadow prototype properties. namedGet = ("\n" + - "if set == 0 && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" + + "if !set && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" + " let name = jsid_to_str(cx, id);\n" + " let this = UnwrapProxy(proxy);\n" + " let this = JS::from_raw(this);\n" + @@ -3624,19 +3624,19 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): return setOrIndexedGet + """let expando: *mut JSObject = GetExpandoObject(proxy); //if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) { if expando.is_not_null() { - let flags = if set != 0 { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED; + let flags = if set { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED; if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc) == 0 { - return 0; + return false; } if (*desc).obj.is_not_null() { // Pretend the property lives on the wrapper. (*desc).obj = proxy; - return 1; + return true; } } """ + namedGet + """ (*desc).obj = ptr::mut_null(); -return 1;""" +return true;""" def definition_body(self): return CGGeneric(self.getBody()) @@ -3646,7 +3646,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('jsid', 'id'), Argument('*const JSPropertyDescriptor', 'desc')] - CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args) + CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "bool", args) self.descriptor = descriptor def getBody(self): set = "" @@ -3662,11 +3662,11 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " let this = JS::from_raw(this);\n" + " let this = this.root();\n" + CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() + - " return 1;\n" + + " return true;\n" + "}\n") elif self.descriptor.operations['IndexedGetter']: set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" + - " return 0;\n" + + " return false;\n" + " //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" + "}\n") % self.descriptor.name @@ -3689,10 +3689,10 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " let this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + " if (found) {\n" - " return 0;\n" + + " return false;\n" + " //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" + " }\n" + - " return 1;\n" + " return true;\n" "}\n") % (self.descriptor.name) return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args) @@ -3702,8 +3702,8 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): def __init__(self, descriptor): args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), - Argument('jsid', 'id'), Argument('*mut JSBool', 'bp')] - CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "JSBool", args) + Argument('jsid', 'id'), Argument('*mut bool', 'bp')] + CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "bool", args) self.descriptor = descriptor def getBody(self): indexedGetter = self.descriptor.operations['IndexedGetter'] @@ -3715,8 +3715,8 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " let this = JS::from_raw(this);\n" + " let this = this.root();\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + - " *bp = found as JSBool;\n" + - " return 1;\n" + + " *bp = found;\n" + + " return true;\n" + "}\n\n") else: indexed = "" @@ -3729,8 +3729,8 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " let this = JS::from_raw(this);\n" + " let this = this.root();\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" + - " *bp = found as JSBool;\n" - " return 1;\n" + " *bp = found;\n" + " return true;\n" "}\n" + "\n") else: @@ -3739,15 +3739,15 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): return indexed + """let expando: *mut JSObject = GetExpandoObject(proxy); if expando.is_not_null() { let mut b: JSBool = 1; - let ok: JSBool = JS_HasPropertyById(cx, expando, id, &mut b); - *bp = !!b; - if ok == 0 || *bp != 0 { + let ok = JS_HasPropertyById(cx, expando, id, &mut b) != 0; + *bp = b != 0; + if !ok || *bp { return ok; } } -""" + named + """*bp = 0; -return 1;""" +""" + named + """*bp = false; +return true;""" def definition_body(self): return CGGeneric(self.getBody()) @@ -3757,22 +3757,25 @@ class CGDOMJSProxyHandler_get(CGAbstractExternMethod): args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'), Argument('*mut JSObject', 'receiver'), Argument('jsid', 'id'), Argument('*mut JSVal', 'vp')] - CGAbstractExternMethod.__init__(self, descriptor, "get", "JSBool", args) + CGAbstractExternMethod.__init__(self, descriptor, "get", "bool", args) self.descriptor = descriptor def getBody(self): getFromExpando = """let expando = GetExpandoObject(proxy); if expando.is_not_null() { let mut hasProp = 0; if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 { - return 0; + return false; } if hasProp != 0 { - return JS_GetPropertyById(cx, expando, id, vp); + return JS_GetPropertyById(cx, expando, id, vp) != 0; } }""" - templateValues = {'jsvalRef': '*vp'} + templateValues = { + 'jsvalRef': '*vp', + 'successCode': 'return true;', + } indexedGetter = self.descriptor.operations['IndexedGetter'] if indexedGetter: @@ -3811,15 +3814,15 @@ if expando.is_not_null() { %s let mut found = false; if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp) { - return 0; + return false; } if found { - return 1; + return true; } %s *vp = UndefinedValue(); -return 1;""" % (getIndexedOrExpando, getNamed) +return true;""" % (getIndexedOrExpando, getNamed) def definition_body(self): return CGGeneric(self.getBody()) diff --git a/servo/src/components/script/dom/bindings/proxyhandler.rs b/servo/src/components/script/dom/bindings/proxyhandler.rs index 97fa373b24f4..a3b61aa4be54 100644 --- a/servo/src/components/script/dom/bindings/proxyhandler.rs +++ b/servo/src/components/script/dom/bindings/proxyhandler.rs @@ -7,7 +7,7 @@ use dom::bindings::utils::is_dom_proxy; use js::jsapi::{JSContext, jsid, JSPropertyDescriptor, JSObject, JSString, jschar}; use js::jsapi::{JS_GetPropertyDescriptorById, JS_NewUCString, JS_malloc, JS_free}; -use js::jsapi::{JSBool, JS_DefinePropertyById, JS_NewObjectWithGivenProto}; +use js::jsapi::{JS_DefinePropertyById, JS_NewObjectWithGivenProto}; use js::jsapi::{JS_ReportErrorFlagsAndNumber, JS_StrictPropertyStub}; use js::jsapi::{JSREPORT_WARNING, JSREPORT_STRICT, JSREPORT_STRICT_MODE_ERROR}; use js::jsapi::JS_DeletePropertyById2; @@ -26,30 +26,32 @@ use std::mem::size_of; static JSPROXYSLOT_EXPANDO: u32 = 0; -pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - set: libc::c_int, desc: *mut JSPropertyDescriptor) -> libc::c_int { +pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, + id: jsid, set: bool, + desc: *mut JSPropertyDescriptor) + -> bool { unsafe { let handler = GetProxyHandler(proxy); - if InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, set, desc) == 0 { - return 0; + if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, set, desc) { + return false; } if (*desc).obj.is_not_null() { - return 1; + return true; } //let proto = JS_GetPrototype(proxy); let proto = GetObjectProto(proxy); if proto.is_null() { (*desc).obj = ptr::mut_null(); - return 1; + return true; } - JS_GetPropertyDescriptorById(cx, proto, id, JSRESOLVE_QUALIFIED, mem::transmute(desc)) + JS_GetPropertyDescriptorById(cx, proto, id, JSRESOLVE_QUALIFIED, desc) != 0 } } pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *mut JSPropertyDescriptor) -> JSBool { + desc: *mut JSPropertyDescriptor) -> bool { static JSMSG_GETTER_ONLY: libc::c_uint = 160; unsafe { @@ -61,39 +63,39 @@ pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, JSREPORT_WARNING | JSREPORT_STRICT | JSREPORT_STRICT_MODE_ERROR, Some(RUST_js_GetErrorMessage), ptr::mut_null(), - JSMSG_GETTER_ONLY); + JSMSG_GETTER_ONLY) != 0; } let expando = EnsureExpandoObject(cx, proxy); if expando.is_null() { - return 0; + return false; } return JS_DefinePropertyById(cx, expando, id, (*desc).value, (*desc).getter, - (*desc).setter, (*desc).attrs); + (*desc).setter, (*desc).attrs) != 0; } } pub extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - desc: *mut JSPropertyDescriptor) -> JSBool { + desc: *mut JSPropertyDescriptor) -> bool { defineProperty_(cx, proxy, id, desc) } pub extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, - bp: *mut bool) -> JSBool { + bp: *mut bool) -> bool { unsafe { let expando = EnsureExpandoObject(cx, proxy); if expando.is_null() { - return 0; + return false; } let mut value = UndefinedValue(); if JS_DeletePropertyById2(cx, expando, id, &mut value) == 0 { - return 0; + return false; } *bp = value.to_boolean(); - return 1; + return true; } }