diff options
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 34 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 44 |
2 files changed, 36 insertions, 42 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 29741117383..6b8fcc09e34 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -9,23 +9,20 @@ use dom::bindings::global::global_object_for_js_object; use dom::bindings::js::JSRef; use dom::bindings::utils::Reflectable; -use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable}; -use js::jsapi::JS_GetProperty; +use js::jsapi::{JSContext, JSObject, JS_WrapObject, JS_ObjectIsCallable, JS_GetGlobalObject}; +use js::jsapi::{JS_GetProperty, JS_IsExceptionPending, JS_ReportPendingException}; use js::jsval::{JSVal, UndefinedValue}; +use js::rust::with_compartment; use std::ptr; /// The exception handling used for a call. -#[deriving(Copy)] +#[deriving(Copy, PartialEq)] pub enum ExceptionHandling { /// Report any exception and don't throw it to the caller code. - ReportExceptions, - /// Throw an exception to the caller code if the thrown exception is a - /// binding object for a DOMError from the caller's scope, otherwise report - /// it. - RethrowContentExceptions, + Report, /// Throw any exception to the caller code. - RethrowExceptions + Rethrow } /// A common base class for representing IDL callback function types. @@ -139,7 +136,7 @@ pub struct CallSetup { /// The `JSContext` used for the call. cx: *mut JSContext, /// The exception handling used for the call. - _handling: ExceptionHandling + _handling: ExceptionHandling, } impl CallSetup { @@ -149,9 +146,10 @@ impl CallSetup { let global = global_object_for_js_object(callback.callback()); let global = global.root(); let cx = global.r().get_cx(); + CallSetup { cx: cx, - _handling: handling + _handling: handling, } } @@ -160,3 +158,17 @@ impl CallSetup { self.cx } } + +impl Drop for CallSetup { + fn drop(&mut self) { + let need_to_deal_with_exception = unsafe { JS_IsExceptionPending(self.cx) } != 0; + if need_to_deal_with_exception { + unsafe { + let old_global = JS_GetGlobalObject(self.cx); + with_compartment(self.cx, old_global, || { + JS_ReportPendingException(self.cx) + }); + } + } + } +} diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index c1c4aca60ca..1cc9c2dc9e8 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -4837,12 +4837,11 @@ class FakeMember(): return None class CallbackMember(CGNativeMember): - def __init__(self, sig, name, descriptorProvider, needThisHandling, rethrowContentException=False): + def __init__(self, sig, name, descriptorProvider, needThisHandling): """ needThisHandling is True if we need to be able to accept a specified thisObj, False otherwise. """ - assert not rethrowContentException or not needThisHandling self.retvalType = sig[0] self.originalSig = sig @@ -4861,7 +4860,6 @@ class CallbackMember(CGNativeMember): # If needThisHandling, we generate ourselves as private and the caller # will handle generating public versions that handle the "this" stuff. visibility = "priv" if needThisHandling else "pub" - self.rethrowContentException = rethrowContentException # We don't care, for callback codegen, whether our original member was # a method or attribute or whatnot. Just always pass FakeMember() # here. @@ -4984,11 +4982,8 @@ class CallbackMember(CGNativeMember): if not self.needThisHandling: # Since we don't need this handling, we're the actual method that # will be called, so we need an aRethrowExceptions argument. - if self.rethrowContentException: - args.append(Argument("JSCompartment*", "aCompartment", "nullptr")) - else: - args.append(Argument("ExceptionHandling", "aExceptionHandling", - "ReportExceptions")) + args.append(Argument("ExceptionHandling", "aExceptionHandling", + "ReportExceptions")) return args # We want to allow the caller to pass in a "this" object, as # well as a JSContext. @@ -4999,22 +4994,12 @@ class CallbackMember(CGNativeMember): if self.needThisHandling: # It's been done for us already return "" - callSetup = "CallSetup s(CallbackPreserveColor(), aRv" - if self.rethrowContentException: - # getArgs doesn't add the aExceptionHandling argument but does add - # aCompartment for us. - callSetup += ", RethrowContentExceptions, aCompartment" - else: - callSetup += ", aExceptionHandling" - callSetup += ");" - return string.Template( - "${callSetup}\n" + return ( + "CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling);\n" "JSContext* cx = s.GetContext();\n" "if (!cx) {\n" " return Err(FailureUnknown);\n" - "}\n").substitute({ - "callSetup": callSetup, - }) + "}\n") def getArgcDecl(self): return CGGeneric("let mut argc = %s as u32;" % self.argCountStr); @@ -5035,9 +5020,9 @@ class CallbackMember(CGNativeMember): idlObject.location)) class CallbackMethod(CallbackMember): - def __init__(self, sig, name, descriptorProvider, needThisHandling, rethrowContentException=False): + def __init__(self, sig, name, descriptorProvider, needThisHandling): CallbackMember.__init__(self, sig, name, descriptorProvider, - needThisHandling, rethrowContentException) + needThisHandling) def getRvalDecl(self): return "let mut rval = UndefinedValue();\n" @@ -5076,10 +5061,10 @@ class CallbackOperationBase(CallbackMethod): """ Common class for implementing various callback operations. """ - def __init__(self, signature, jsName, nativeName, descriptor, singleOperation, rethrowContentException=False): + def __init__(self, signature, jsName, nativeName, descriptor, singleOperation): self.singleOperation = singleOperation self.methodName = jsName - CallbackMethod.__init__(self, signature, nativeName, descriptor, singleOperation, rethrowContentException) + CallbackMethod.__init__(self, signature, nativeName, descriptor, singleOperation) def getThisObj(self): if not self.singleOperation: @@ -5117,8 +5102,7 @@ class CallbackOperation(CallbackOperationBase): jsName = method.identifier.name CallbackOperationBase.__init__(self, signature, jsName, MakeNativeName(jsName), - descriptor, descriptor.interface.isSingleOperationInterface(), - rethrowContentException=descriptor.interface.isJSImplemented()) + descriptor, descriptor.interface.isSingleOperationInterface()) class CallbackGetter(CallbackMember): def __init__(self, attr, descriptor): @@ -5128,8 +5112,7 @@ class CallbackGetter(CallbackMember): (attr.type, []), callbackGetterName(attr), descriptor, - needThisHandling=False, - rethrowContentException=descriptor.interface.isJSImplemented()) + needThisHandling=False) def getRvalDecl(self): return "JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());\n" @@ -5152,8 +5135,7 @@ class CallbackSetter(CallbackMember): [FakeArgument(attr.type, attr)]), callbackSetterName(attr), descriptor, - needThisHandling=False, - rethrowContentException=descriptor.interface.isJSImplemented()) + needThisHandling=False) def getRvalDecl(self): # We don't need an rval |