Commit 2ec947a6 authored by Peter Van der Beken's avatar Peter Van der Beken
Browse files

Bug 1708660 - Remove support for map/setLike in JS-implemented WebIDL. r=edgar

parent 67b390b0
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -218,7 +218,6 @@
#if defined(ENABLE_TESTS) && defined(MOZ_DEBUG)
@RESPATH@/components/TestInterfaceJS.js
@RESPATH@/components/TestInterfaceJS.manifest
@RESPATH@/components/TestInterfaceJSMaplike.js
#endif

#if defined(MOZ_DEBUG) || defined(MOZ_DEV_EDITION) || defined(NIGHTLY_BUILD)
+1 −87
Original line number Diff line number Diff line
@@ -19805,24 +19805,6 @@ class CGJSImplClass(CGBindingImplClass):
            )
        )
        if (
            descriptor.interface.isJSImplemented()
            and descriptor.interface.maplikeOrSetlikeOrIterable
            and descriptor.interface.maplikeOrSetlikeOrIterable.isMaplike()
        ):
            self.methodDecls.append(
                ClassMethod(
                    "__OnGet",
                    "void",
                    [
                        Argument("JS::Handle<JS::Value>", "aKey"),
                        Argument("JS::Handle<JS::Value>", "aValue"),
                        Argument("ErrorResult&", "aRv"),
                    ],
                    body="mImpl->__OnGet(aKey, aValue, aRv);\n",
                )
            )
        CGClass.__init__(
            self,
            descriptor.name,
@@ -20327,15 +20309,6 @@ class CGCallbackInterface(CGCallback):
            methods.append(CGJSImplInitOperation(sigs[0], descriptor))
            needInitId = True
        needOnGetId = False
        if (
            iface.isJSImplemented()
            and iface.maplikeOrSetlikeOrIterable
            and iface.maplikeOrSetlikeOrIterable.isMaplike()
        ):
            methods.append(CGJSImplOnGetOperation(descriptor))
            needOnGetId = True
        idlist = [
            descriptor.binaryNameFor(m.identifier.name)
            for m in iface.members
@@ -20343,8 +20316,6 @@ class CGCallbackInterface(CGCallback):
        ]
        if needInitId:
            idlist.append("__init")
        if needOnGetId:
            idlist.append("__onget")
        if iface.isJSImplemented() and iface.getExtendedAttribute(
            "WantsEventListenerHooks"
@@ -21058,35 +21029,6 @@ class CGJSImplInitOperation(CallbackOperationBase):
        return "__init"
class CGJSImplOnGetOperation(CallbackOperationBase):
    """
    Codegen the __OnGet() method used to notify the JS impl that a get() is
    happening on a JS-implemented maplike.  This method takes two arguments
    (key and value) and returns nothing.
    """
    def __init__(self, descriptor):
        CallbackOperationBase.__init__(
            self,
            (
                BuiltinTypes[IDLBuiltinType.Types.void],
                [
                    FakeArgument(BuiltinTypes[IDLBuiltinType.Types.any], None, "key"),
                    FakeArgument(BuiltinTypes[IDLBuiltinType.Types.any], None, "value"),
                ],
            ),
            "__onget",
            "__OnGet",
            descriptor,
            singleOperation=False,
            rethrowContentException=True,
            spiderMonkeyInterfacesAreStructs=True,
        )
    def getPrettyName(self):
        return "__onget"
class CGJSImplEventHookOperation(CallbackOperationBase):
    """
    Codegen the hooks on a JS impl for adding/removing event listeners.
@@ -21467,28 +21409,7 @@ class CGMaplikeOrSetlikeMethodGenerator(CGThing):
            ]
        arguments = ["&result"]
        callOnGet = []
        if (
            self.descriptor.interface.isJSImplemented()
            and not self.helperImpl  # For C++ MaplikeHelper Get method, we don't notify underlying js implementation
        ):
            callOnGet = [
                CGGeneric(
                    dedent(
                        """
                {
                  JS::ExposeValueToActiveJS(result);
                  ErrorResult onGetResult;
                  self->__OnGet(arg0Val, result, onGetResult);
                  if (onGetResult.MaybeSetPendingException(cx)) {
                    return false;
                  }
                }
                """
                    )
                )
            ]
        return self.mergeTuples(r, (code, arguments, callOnGet))
        return self.mergeTuples(r, (code, arguments, []))
    def has(self):
        """
@@ -21933,13 +21854,6 @@ class GlobalGenRoots:
            if d.interface.isJSImplemented() and d.interface.ctor():
                # We'll have an __init() method.
                members.append(FakeMember("__init"))
            if (
                d.interface.isJSImplemented()
                and d.interface.maplikeOrSetlikeOrIterable
                and d.interface.maplikeOrSetlikeOrIterable.isMaplike()
            ):
                # We'll have an __onget() method.
                members.append(FakeMember("__onget"))
            if d.interface.isJSImplemented() and d.interface.getExtendedAttribute(
                "WantsEventListenerHooks"
            ):
+10 −45
Original line number Diff line number Diff line
@@ -1021,6 +1021,13 @@ class IDLInterfaceOrNamespace(IDLInterfaceOrInterfaceMixinOrNamespace):
        # things like exposure setting.
        for member in self.members:
            if member.isMaplikeOrSetlikeOrIterable():
                if self.isJSImplemented():
                    raise WebIDLError(
                        "%s declaration used on "
                        "interface that is implemented in JS"
                        % (member.maplikeOrSetlikeOrIterableType),
                        [member.location],
                    )
                # Check that we only have one interface declaration (currently
                # there can only be one maplike/setlike declaration per
                # interface)
@@ -1038,9 +1045,7 @@ class IDLInterfaceOrNamespace(IDLInterfaceOrInterfaceMixinOrNamespace):
                self.maplikeOrSetlikeOrIterable = member
                # If we've got a maplike or setlike declaration, we'll be building all of
                # our required methods in Codegen. Generate members now.
                self.maplikeOrSetlikeOrIterable.expand(
                    self.members, self.isJSImplemented()
                )
                self.maplikeOrSetlikeOrIterable.expand(self.members)

        assert not self.parent or isinstance(self.parent, IDLIdentifierPlaceholder)
        parent = self.parent.finish(scope) if self.parent else None
@@ -4605,7 +4610,7 @@ class IDLIterable(IDLMaplikeOrSetlikeOrIterableBase):
            self.valueType,
        )

    def expand(self, members, isJSImplemented):
    def expand(self, members):
        """
        In order to take advantage of all of the method machinery in Codegen,
        we generate our functions as if they were part of the interface
@@ -4691,7 +4696,7 @@ class IDLMaplikeOrSetlike(IDLMaplikeOrSetlikeOrIterableBase):
            self.keyType,
        )

    def expand(self, members, isJSImplemented):
    def expand(self, members):
        """
        In order to take advantage of all of the method machinery in Codegen,
        we generate our functions as if they were part of the interface
@@ -4782,28 +4787,6 @@ class IDLMaplikeOrSetlike(IDLMaplikeOrSetlikeOrIterableBase):
                [getKeyArg()],
            )

        # Always generate underscored functions (e.g. __add, __clear) for js
        # implemented interfaces as convenience functions.
        if isJSImplemented:
            # void clear()
            self.addMethod(
                "clear",
                members,
                True,
                BuiltinTypes[IDLBuiltinType.Types.void],
                [],
                chromeOnly=True,
            )
            # boolean delete(keyType key)
            self.addMethod(
                "delete",
                members,
                True,
                BuiltinTypes[IDLBuiltinType.Types.boolean],
                [getKeyArg()],
                chromeOnly=True,
            )

        if self.isSetlike():
            if not self.readonly:
                # Add returns the set object it just added to.
@@ -4816,15 +4799,6 @@ class IDLMaplikeOrSetlike(IDLMaplikeOrSetlikeOrIterableBase):
                    BuiltinTypes[IDLBuiltinType.Types.object],
                    [getKeyArg()],
                )
            if isJSImplemented:
                self.addMethod(
                    "add",
                    members,
                    True,
                    BuiltinTypes[IDLBuiltinType.Types.object],
                    [getKeyArg()],
                    chromeOnly=True,
                )
            return

        # If we get this far, we're a maplike declaration.
@@ -4861,15 +4835,6 @@ class IDLMaplikeOrSetlike(IDLMaplikeOrSetlikeOrIterableBase):
                BuiltinTypes[IDLBuiltinType.Types.object],
                [getKeyArg(), getValueArg()],
            )
        if isJSImplemented:
            self.addMethod(
                "set",
                members,
                True,
                BuiltinTypes[IDLBuiltinType.Types.object],
                [getKeyArg(), getValueArg()],
                chromeOnly=True,
            )


class IDLConst(IDLInterfaceMember):
+2 −29
Original line number Diff line number Diff line
@@ -317,7 +317,7 @@ def WebIDLTest(parser, harness):
        numProductions=2,
    )

    shouldPass(
    shouldFail(
        "JS Implemented maplike interface",
        """
               [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
@@ -326,10 +326,9 @@ def WebIDLTest(parser, harness):
               setlike<long>;
               };
               """,
        setRWChromeMembers,
    )

    shouldPass(
    shouldFail(
        "JS Implemented maplike interface",
        """
               [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
@@ -338,7 +337,6 @@ def WebIDLTest(parser, harness):
               maplike<long, long>;
               };
               """,
        mapRWChromeMembers,
    )

    #
@@ -746,31 +744,6 @@ def WebIDLTest(parser, harness):
        setROMembers + [("clear", WebIDL.IDLAttribute)],
    )

    shouldPass(
        "JS Implemented read-only interface with readonly allowable overrides",
        """
               [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
               interface Foo1 {
               constructor();
               readonly setlike<long>;
               readonly attribute boolean clear;
               };
               """,
        setROChromeMembers + [("clear", WebIDL.IDLAttribute)],
    )

    shouldFail(
        "JS Implemented read-write interface with non-readwrite allowable overrides",
        """
               [JSImplementation="@mozilla.org/dom/test-interface-js-maplike;1"]
               interface Foo1 {
               constructor();
               setlike<long>;
               readonly attribute boolean clear;
               };
               """,
    )

    r = shouldPass(
        "Check proper override of clear/delete/set",
        """
+0 −2
Original line number Diff line number Diff line
component {2ac4e026-cf25-47d5-b067-78d553c3cad8} TestInterfaceJS.js
contract @mozilla.org/dom/test-interface-js;1 {2ac4e026-cf25-47d5-b067-78d553c3cad8}
component {4bc6f6f3-e005-4f0a-b42d-4d1663a9013a} TestInterfaceJSMaplike.js
contract @mozilla.org/dom/test-interface-js-maplike;1 {4bc6f6f3-e005-4f0a-b42d-4d1663a9013a}
Loading