diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-23 20:13:45 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-02-23 20:13:45 +0530 |
commit | 3550993075a0dedb5857a421cf39c3e8942b30f8 (patch) | |
tree | 61b590a507fea1980888c1300b92dc956bbc8106 /components/script/dom | |
parent | 90c7b78b12c772e4019c9724e0037b813eb8a555 (diff) | |
parent | 0af373cef6bca2ec998c1dbdfde74fc837a13135 (diff) | |
download | servo-3550993075a0dedb5857a421cf39c3e8942b30f8.tar.gz servo-3550993075a0dedb5857a421cf39c3e8942b30f8.zip |
Auto merge of #9728 - nox:lazy-preliminaries, r=Ms2ger
Preliminary commits for lazy interface objects in #9652
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9728)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 84 | ||||
-rw-r--r-- | components/script/dom/browsingcontext.rs | 33 |
2 files changed, 53 insertions, 64 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index cefb3b23e15..ec1a0a7ec15 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1766,25 +1766,29 @@ class CGDOMJSClass(CGThing): self.descriptor = descriptor def define(self): - traceHook = 'Some(%s)' % TRACE_HOOK_NAME + args = { + "domClass": DOMClass(self.descriptor), + "finalizeHook": FINALIZE_HOOK_NAME, + "flags": "0", + "name": str_to_const_array(self.descriptor.interface.identifier.name), + "outerObjectHook": self.descriptor.outerObjectHook, + "slots": "1", + "traceHook": TRACE_HOOK_NAME, + } if self.descriptor.isGlobal(): assert not self.descriptor.weakReferenceable - traceHook = "Some(js::jsapi::JS_GlobalObjectTraceHook)" - flags = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL" - slots = "JSCLASS_GLOBAL_SLOT_COUNT + 1" - else: - flags = "0" - if self.descriptor.weakReferenceable: - slots = "2" - else: - slots = "1" + args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL" + args["slots"] = "JSCLASS_GLOBAL_SLOT_COUNT + 1" + args["traceHook"] = "js::jsapi::JS_GlobalObjectTraceHook" + elif self.descriptor.weakReferenceable: + args["slots"] = "2" return """\ static Class: DOMJSClass = DOMJSClass { base: js::jsapi::Class { - name: %s as *const u8 as *const libc::c_char, - flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS | %s | - (((%s) & JSCLASS_RESERVED_SLOTS_MASK) << - JSCLASS_RESERVED_SLOTS_SHIFT), //JSCLASS_HAS_RESERVED_SLOTS(%s), + name: %(name)s as *const u8 as *const libc::c_char, + flags: JSCLASS_IS_DOMJSCLASS | JSCLASS_IMPLEMENTS_BARRIERS | %(flags)s | + (((%(slots)s) & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT) + /* JSCLASS_HAS_RESERVED_SLOTS(%(slots)s) */, addProperty: None, delProperty: None, getProperty: None, @@ -1792,11 +1796,11 @@ static Class: DOMJSClass = DOMJSClass { enumerate: None, resolve: None, convert: None, - finalize: Some(%s), + finalize: Some(%(finalizeHook)s), call: None, hasInstance: None, construct: None, - trace: %s, + trace: Some(%(traceHook)s), spec: js::jsapi::ClassSpec { createConstructor: None, @@ -1810,7 +1814,7 @@ static Class: DOMJSClass = DOMJSClass { }, ext: js::jsapi::ClassExtension { - outerObject: %s, + outerObject: %(outerObjectHook)s, innerObject: None, isWrappedNative: false, weakmapKeyDelegateOp: None, @@ -1829,17 +1833,12 @@ static Class: DOMJSClass = DOMJSClass { unwatch: None, getElements: None, enumerate: None, - thisObject: %s, + thisObject: %(outerObjectHook)s, funToString: None, }, }, - dom_class: %s -};""" % (str_to_const_array(self.descriptor.interface.identifier.name), - flags, slots, slots, - FINALIZE_HOOK_NAME, traceHook, - self.descriptor.outerObjectHook, - self.descriptor.outerObjectHook, - CGGeneric(DOMClass(self.descriptor)).define()) + dom_class: %(domClass)s +};""" % args def str_to_const_array(s): @@ -2254,7 +2253,7 @@ assert!(((*JS_GetClass(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0); let mut proto = RootedObject::new(cx, ptr::null_mut()); let _ac = JSAutoCompartment::new(cx, scope.get()); -GetProtoObject(cx, scope, scope, proto.handle_mut()); +GetProtoObject(cx, scope, proto.handle_mut()); assert!(!proto.ptr.is_null()); %(createObject)s @@ -2271,7 +2270,7 @@ let _ar = JSAutoRequest::new(cx); let _ac = JSAutoCompartment::new(cx, obj.ptr); let mut proto = RootedObject::new(cx, ptr::null_mut()); -GetProtoObject(cx, obj.handle(), obj.handle(), proto.handle_mut()); +GetProtoObject(cx, obj.handle(), proto.handle_mut()); JS_SetPrototype(cx, obj.handle(), proto.handle()); %(copyUnforgeable)s @@ -2376,11 +2375,9 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): properties should be a PropertyArrays instance. """ def __init__(self, descriptor, properties): - args = [Argument('*mut JSContext', 'cx')] + args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'global')] if not descriptor.interface.isCallback(): - args += [Argument('HandleObject', 'global'), - Argument('*mut ProtoOrIfaceArray', 'cache')] - args.append(Argument('HandleObject', 'receiver')) + args.append(Argument('*mut ProtoOrIfaceArray', 'cache')) CGAbstractMethod.__init__(self, descriptor, 'CreateInterfaceObjects', 'void', args, unsafe=True) self.properties = properties @@ -2390,7 +2387,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): if self.descriptor.interface.isCallback(): assert not self.descriptor.interface.ctor() and self.descriptor.interface.hasConstants() return CGGeneric("""\ -create_callback_interface_object(cx, receiver, sConstants, %s);""" % str_to_const_array(name)) +create_callback_interface_object(cx, global, sConstants, %s);""" % str_to_const_array(name)) if len(self.descriptor.prototypeChain) == 1: if self.descriptor.interface.getExtendedAttribute("ExceptionClass"): @@ -2398,7 +2395,7 @@ create_callback_interface_object(cx, receiver, sConstants, %s);""" % str_to_cons else: getPrototypeProto = "prototype_proto.ptr = JS_GetObjectPrototype(cx, global)" else: - getPrototypeProto = ("%s::GetProtoObject(cx, global, receiver, prototype_proto.handle_mut())" % + getPrototypeProto = ("%s::GetProtoObject(cx, global, prototype_proto.handle_mut())" % toBindingNamespace(self.descriptor.prototypeChain[-2])) code = [CGGeneric("""\ @@ -2446,7 +2443,7 @@ if <*mut JSObject>::needs_post_barrier(prototype.ptr) { parentName = toBindingNamespace(self.descriptor.getParentName()) code.append(CGGeneric(""" let mut interface_proto = RootedObject::new(cx, ptr::null_mut()); -%s::GetConstructorObject(cx, global, receiver, interface_proto.handle_mut());""" % parentName)) +%s::GetConstructorObject(cx, global, interface_proto.handle_mut());""" % parentName)) else: code.append(CGGeneric(""" let interface_proto = RootedObject::new(cx, JS_GetFunctionPrototype(cx, global));""")) @@ -2455,7 +2452,7 @@ assert!(!interface_proto.ptr.is_null()); let mut interface = RootedObject::new(cx, ptr::null_mut()); create_noncallback_interface_object(cx, - receiver, + global, interface_proto.handle(), &InterfaceObjectClass, %(static_methods)s, @@ -2484,7 +2481,7 @@ if <*mut JSObject>::needs_post_barrier(prototype.ptr) { specs.append(CGGeneric("(%s as NonNullJSNative, %s, %d)" % (hook, name, length))) values = CGIndenter(CGList(specs, "\n"), 4) code.append(CGWrapper(values, pre="%s = [\n" % decl, post="\n];")) - code.append(CGGeneric("create_named_constructors(cx, receiver, &named_constructors, prototype.handle());")) + code.append(CGGeneric("create_named_constructors(cx, global, &named_constructors, prototype.handle());")) if self.descriptor.hasUnforgeableMembers: # We want to use the same JSClass and prototype as the object we'll @@ -2524,8 +2521,8 @@ class CGGetPerInterfaceObject(CGAbstractMethod): constructor object). """ def __init__(self, descriptor, name, idPrefix="", pub=False): - args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'global'), - Argument('HandleObject', 'receiver'), + args = [Argument('*mut JSContext', 'cx'), + Argument('HandleObject', 'global'), Argument('MutableHandleObject', 'rval')] CGAbstractMethod.__init__(self, descriptor, name, 'void', args, pub=pub, unsafe=True) @@ -2533,13 +2530,6 @@ class CGGetPerInterfaceObject(CGAbstractMethod): def definition_body(self): return CGGeneric(""" - -/* global and receiver are usually the same, but they can be different - too. For example a sandbox often has an xray wrapper for a window as the - prototype of the sandbox's global. In that case receiver is the xray - wrapper and global is the sandbox's global. - */ - assert!(((*JS_GetClass(global.get())).flags & JSCLASS_DOM_GLOBAL) != 0); /* Check to see whether the interface objects are already installed */ @@ -2549,7 +2539,7 @@ if !rval.get().is_null() { return; } -CreateInterfaceObjects(cx, global, proto_or_iface_array, receiver); +CreateInterfaceObjects(cx, global, proto_or_iface_array); rval.set((*proto_or_iface_array)[%(id)s as usize]); assert!(!rval.get().is_null()); """ % {"id": self.id}) @@ -2671,7 +2661,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): else: code = """\ let mut proto = RootedObject::new(cx, ptr::null_mut()); -GetProtoObject(cx, global, global, proto.handle_mut()); +GetProtoObject(cx, global, proto.handle_mut()); assert!(!proto.ptr.is_null()); """ return CGGeneric("assert!(!global.get().is_null());\n" + code) diff --git a/components/script/dom/browsingcontext.rs b/components/script/dom/browsingcontext.rs index 603b2c27f80..7149a365800 100644 --- a/components/script/dom/browsingcontext.rs +++ b/components/script/dom/browsingcontext.rs @@ -13,15 +13,14 @@ use dom::document::Document; use dom::element::Element; use dom::window::Window; use js::JSCLASS_IS_GLOBAL; -use js::glue::{CreateWrapperProxyHandler, ProxyTraps, NewWindowProxy}; -use js::glue::{GetProxyPrivate, SetProxyExtra}; -use js::jsapi::{Handle, JS_ForwardSetPropertyTo, ObjectOpResult, RootedObject, RootedValue}; -use js::jsapi::{HandleId, HandleObject, MutableHandle, MutableHandleValue}; -use js::jsapi::{JSAutoCompartment, JSAutoRequest, JS_GetClass}; -use js::jsapi::{JSContext, JSErrNum, JSObject, JSPropertyDescriptor}; -use js::jsapi::{JS_AlreadyHasOwnPropertyById, JS_ForwardGetPropertyTo}; -use js::jsapi::{JS_DefinePropertyById6, JS_GetOwnPropertyDescriptorById}; -use js::jsval::{ObjectValue, UndefinedValue, PrivateValue}; +use js::glue::{CreateWrapperProxyHandler, GetProxyPrivate, NewWindowProxy}; +use js::glue::{ProxyTraps, SetProxyExtra}; +use js::jsapi::{Handle, HandleId, HandleObject, JSAutoCompartment, JSAutoRequest, JSContext}; +use js::jsapi::{JSErrNum, JSObject, JSPropertyDescriptor, JS_DefinePropertyById6}; +use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo, JS_GetClass}; +use js::jsapi::{JS_GetOwnPropertyDescriptorById, JS_HasPropertyById, MutableHandle}; +use js::jsapi::{MutableHandleValue, ObjectOpResult, RootedObject, RootedValue}; +use js::jsval::{ObjectValue, PrivateValue, UndefinedValue}; #[dom_struct] pub struct BrowsingContext { @@ -177,11 +176,11 @@ unsafe extern "C" fn defineProperty(cx: *mut JSContext, } #[allow(unsafe_code)] -unsafe extern "C" fn hasOwn(cx: *mut JSContext, - proxy: HandleObject, - id: HandleId, - bp: *mut bool) - -> bool { +unsafe extern "C" fn has(cx: *mut JSContext, + proxy: HandleObject, + id: HandleId, + bp: *mut bool) + -> bool { let window = GetSubframeWindow(cx, proxy, id); if window.is_some() { *bp = true; @@ -190,7 +189,7 @@ unsafe extern "C" fn hasOwn(cx: *mut JSContext, let target = RootedObject::new(cx, GetProxyPrivate(*proxy.ptr).to_object()); let mut found = false; - if !JS_AlreadyHasOwnPropertyById(cx, target.handle(), id, &mut found) { + if !JS_HasPropertyById(cx, target.handle(), id, &mut found) { return false; } @@ -248,13 +247,13 @@ static PROXY_HANDLER: ProxyTraps = ProxyTraps { enumerate: None, preventExtensions: None, isExtensible: None, - has: None, + has: Some(has), get: Some(get), set: Some(set), call: None, construct: None, getPropertyDescriptor: Some(get_property_descriptor), - hasOwn: Some(hasOwn), + hasOwn: None, getOwnEnumerablePropertyKeys: None, nativeCall: None, hasInstance: None, |