From 943dde7841f882063ed423bb82b9977704db0fdb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 24 May 2019 17:31:42 +0000 Subject: [PATCH] Bug 1554195. Remove MSG_THIS_DOES_NOT_IMPLEMENT_INTERFACE. r=mccr8 I was clearly trying to do that in bug 882653 part 3 and failed to. Our current behavior of passing two args to this error message (which only takes one arg) is silly, and the only thing that makes it at all sane is that we only use it in class hooks, which can never have the wrong sort of object, so it's unreached code. The comment cleanup is just to make the role of CGAbstractBindingMethod. and the validity of the changes to it, clearer. Differential Revision: https://phabricator.services.mozilla.com/D32478 --HG-- extra : moz-landing-system : lando --- dom/base/nsContentUtils.cpp | 8 ++++---- dom/bindings/Codegen.py | 22 +++++++++++++++------- dom/bindings/Errors.msg | 1 - 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a0f42e0dd50b..f5be90398d88 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -9402,14 +9402,14 @@ static void DoCustomElementCreate(Element** aElement, JSContext* aCx, UNWRAP_OBJECT(Element, &constructResult, element); if (aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) { if (!element || !element->IsHTMLElement()) { - aRv.ThrowTypeError( - NS_LITERAL_STRING("HTMLElement")); + aRv.ThrowTypeError( + NS_LITERAL_STRING("\"this\""), NS_LITERAL_STRING("HTMLElement")); return; } } else { if (!element || !element->IsXULElement()) { - aRv.ThrowTypeError( - NS_LITERAL_STRING("XULElement")); + aRv.ThrowTypeError( + NS_LITERAL_STRING("\"this\""), NS_LITERAL_STRING("XULElement")); return; } } diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 749e51754e6c..042174955f48 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -8743,11 +8743,12 @@ class CGSetterCall(CGPerSignatureCall): class CGAbstractBindingMethod(CGAbstractStaticMethod): """ - Common class to generate the JSNatives for all our methods, getters, and - setters. This will generate the function declaration and unwrap the - |this| object. Subclasses are expected to override the generate_code - function to do the rest of the work. This function should return a - CGThing which is already properly indented. + Common class to generate some of our class hooks. This will generate the + function declaration, get a reference to the JS object for our binding + object (which might be an argument of the class hook or something we get + from a JS::CallArgs), and unwrap into the right C++ type. Subclasses are + expected to override the generate_code function to do the rest of the work. + This function should return a CGThing which is already properly indented. getThisObj should be code for getting a JSObject* for the binding object. "" can be passed in if the binding object is already stored in @@ -8755,14 +8756,21 @@ class CGAbstractBindingMethod(CGAbstractStaticMethod): callArgs should be code for getting a JS::CallArgs into a variable called 'args'. This can be "" if there is already such a variable - around. + around or if the body does not need a JS::CallArgs. + """ def __init__(self, descriptor, name, args, getThisObj, callArgs="JS::CallArgs args = JS::CallArgsFromVp(argc, vp);\n"): CGAbstractStaticMethod.__init__(self, descriptor, name, "bool", args, canRunScript=True) - self.unwrapFailureCode = 'return ThrowErrorMessage(cx, MSG_THIS_DOES_NOT_IMPLEMENT_INTERFACE, "Value", "%s");\n' % descriptor.interface.identifier.name + # This can't ever happen, because we only use this for class hooks. + self.unwrapFailureCode = fill( + """ + MOZ_CRASH("Unexpected object in '${name}' hook"); + return false; + """, + name=name) if getThisObj == "": self.getThisObj = None diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index 48953cfc6189..155602a09c98 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -30,7 +30,6 @@ MSG_DEF(MSG_NOT_CONSTRUCTOR, 1, JSEXN_TYPEERR, "{0} is not a constructor.") MSG_DEF(MSG_DOES_NOT_IMPLEMENT_INTERFACE, 2, JSEXN_TYPEERR, "{0} does not implement interface {1}.") MSG_DEF(MSG_METHOD_THIS_DOES_NOT_IMPLEMENT_INTERFACE, 2, JSEXN_TYPEERR, "'{0}' called on an object that does not implement interface {1}.") MSG_DEF(MSG_METHOD_THIS_UNWRAPPING_DENIED, 1, JSEXN_TYPEERR, "Permission to call '{0}' denied.") -MSG_DEF(MSG_THIS_DOES_NOT_IMPLEMENT_INTERFACE, 1, JSEXN_TYPEERR, "\"this\" object does not implement interface {0}.") MSG_DEF(MSG_NOT_IN_UNION, 2, JSEXN_TYPEERR, "{0} could not be converted to any of: {1}.") MSG_DEF(MSG_ILLEGAL_CONSTRUCTOR, 0, JSEXN_TYPEERR, "Illegal constructor.") MSG_DEF(MSG_ILLEGAL_TYPE_PR_CONSTRUCTOR, 1, JSEXN_TYPEERR, "TypeError:{0}")