From 4f9e119334cbd68a33874402d31c0bf8b629b038 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 21 Apr 2014 13:43:13 +0200 Subject: Remove JSPageInfo::js_compartment. A js::rust::Compartment is little more than a glorified pointer to the reflector of a window, so there's no good reason to use it. Instead, this commit passes a JS directly when it's necessary. This also means that we now have to use JS_DefineFunctions rather than Compartment::define_functions; I believe the former is clearer to the reader than the extra indirection involved in the latter calling through three reopsitories. This commit also simplifies ScriptTask::load to reuse the 'cx' local that is in scope already, rather than refetching it through js_info. --- .../script/dom/bindings/codegen/CodegenRust.py | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py') diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 1e30647a3d6..22523568719 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2118,7 +2118,10 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): a given interface. """ def __init__(self, descriptor): - args = [Argument('&mut JSPageInfo', 'js_info')] + args = [ + Argument('&JS', 'window'), + Argument('&mut JSPageInfo', 'js_info'), + ] CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface', 'void', args, pub=True) def define(self): @@ -2173,10 +2176,10 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): ('Some(%s)' % TRACE_HOOK_NAME), self.descriptor.name) - return (body + """ let cx = (*js_info.js_context).deref().ptr; - let receiver = js_info.js_compartment.global_obj; - let global: *JSObject = JS_GetGlobalForObject(cx, receiver); - assert!(%s(cx, global, receiver).is_not_null());""" % (getter)) + return (body + """ let cx = (**js_info.js_context).ptr; + let global = window.reflector().get_jsobject(); + assert!(global.is_not_null()); + assert!(%s(cx, global, global).is_not_null());""" % (getter)) def needCx(returnType, arguments, extendedAttributes, considerTypes): return (considerTypes and @@ -4305,13 +4308,16 @@ class CGDictionary(CGThing): class CGRegisterProtos(CGAbstractMethod): def __init__(self, config): - CGAbstractMethod.__init__(self, None, 'Register', 'void', - [Argument('&mut JSPageInfo', 'js_info')], + arguments = [ + Argument('&JS', 'window'), + Argument('&mut JSPageInfo', 'js_info'), + ] + CGAbstractMethod.__init__(self, None, 'Register', 'void', arguments, unsafe=False, pub=True) self.config = config def _registerProtos(self): - lines = [" codegen::%sBinding::DefineDOMInterface(js_info);" % desc.name + lines = [" codegen::%sBinding::DefineDOMInterface(window, js_info);" % desc.name for desc in self.config.getDescriptors(hasInterfaceObject=True, register=True)] return '\n'.join(lines) + '\n' @@ -5349,6 +5355,8 @@ class GlobalGenRoots(): # TODO - Generate the methods we want return CGImports(CGRegisterProtos(config), [ 'dom::bindings::codegen', + 'dom::bindings::js::JS', + 'dom::window::Window', 'script_task::JSPageInfo', ]) -- cgit v1.2.3