Commit 9e852426 authored by Peter Van der Beken's avatar Peter Van der Beken
Browse files

Bug 1792444 - Switch some WebIDL APIs from 'any' to a union with 'undefined'....

Bug 1792444 - Switch some WebIDL APIs from 'any' to a union with 'undefined'. r=edgar,media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D158195
parent c579de64
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1127,17 +1127,18 @@ void CustomElementRegistry::Upgrade(nsINode& aRoot) {
  }
}

void CustomElementRegistry::Get(JSContext* aCx, const nsAString& aName,
                                JS::MutableHandle<JS::Value> aRetVal) {
void CustomElementRegistry::Get(
    const nsAString& aName,
    OwningCustomElementConstructorOrUndefined& aRetVal) {
  RefPtr<nsAtom> nameAtom(NS_Atomize(aName));
  CustomElementDefinition* data = mCustomDefinitions.GetWeak(nameAtom);

  if (!data) {
    aRetVal.setUndefined();
    aRetVal.SetUndefined();
    return;
  }

  aRetVal.setObject(*data->mConstructor->Callback(aCx));
  aRetVal.SetAsCustomElementConstructor() = data->mConstructor;
}

already_AddRefed<Promise> CustomElementRegistry::WhenDefined(
+2 −2
Original line number Diff line number Diff line
@@ -547,8 +547,8 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache {
              CustomElementConstructor& aFunctionConstructor,
              const ElementDefinitionOptions& aOptions, ErrorResult& aRv);

  void Get(JSContext* cx, const nsAString& name,
           JS::MutableHandle<JS::Value> aRetVal);
  void Get(const nsAString& name,
           OwningCustomElementConstructorOrUndefined& aRetVal);

  already_AddRefed<Promise> WhenDefined(const nsAString& aName,
                                        ErrorResult& aRv);
+3 −4
Original line number Diff line number Diff line
@@ -3399,12 +3399,11 @@ void nsGlobalWindowInner::SetOpener(JSContext* aCx,
  RedefineProperty(aCx, "opener", aOpener, aError);
}

void nsGlobalWindowInner::GetEvent(JSContext* aCx,
                                   JS::MutableHandle<JS::Value> aRetval) {
void nsGlobalWindowInner::GetEvent(OwningEventOrUndefined& aRetval) {
  if (mEvent) {
    Unused << nsContentUtils::WrapNative(aCx, mEvent, aRetval);
    aRetval.SetAsEvent() = mEvent;
  } else {
    aRetval.setUndefined();
    aRetval.SetUndefined();
  }
}

+1 −1
Original line number Diff line number Diff line
@@ -638,7 +638,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
                 mozilla::ErrorResult& aError);
  void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
                 mozilla::ErrorResult& aError);
  void GetEvent(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
  void GetEvent(mozilla::dom::OwningEventOrUndefined& aRetval);
  mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> GetParent(
      mozilla::ErrorResult& aError);
  nsPIDOMWindowOuter* GetInProcessScriptableParent() override;
+35 −25
Original line number Diff line number Diff line
@@ -18614,46 +18614,56 @@ class CGBindingRoot(CGThing):
                return getDependenciesFromType(type.unroll())
            if type.isUnion():
                return set([type.unroll()])
            if type.isCallback():
                return set([type.unroll()])
            return set()
        def getDependencies(unionTypeOrDictionary):
            if isinstance(unionTypeOrDictionary, IDLDictionary):
        def getDependencies(unionTypeOrDictionaryOrCallback):
            if isinstance(unionTypeOrDictionaryOrCallback, IDLDictionary):
                deps = set()
                if unionTypeOrDictionary.parent:
                    deps.add(unionTypeOrDictionary.parent)
                for member in unionTypeOrDictionary.members:
                if unionTypeOrDictionaryOrCallback.parent:
                    deps.add(unionTypeOrDictionaryOrCallback.parent)
                for member in unionTypeOrDictionaryOrCallback.members:
                    deps |= getDependenciesFromType(member.type)
                return deps
            assert unionTypeOrDictionary.isType() and unionTypeOrDictionary.isUnion()
            if (
                unionTypeOrDictionaryOrCallback.isType()
                and unionTypeOrDictionaryOrCallback.isUnion()
            ):
                deps = set()
            for member in unionTypeOrDictionary.flatMemberTypes:
                for member in unionTypeOrDictionaryOrCallback.flatMemberTypes:
                    deps |= getDependenciesFromType(member)
                return deps
        def getName(unionTypeOrDictionary):
            if isinstance(unionTypeOrDictionary, IDLDictionary):
                return unionTypeOrDictionary.identifier.name
            assert unionTypeOrDictionaryOrCallback.isCallback()
            return set()
        def getName(unionTypeOrDictionaryOrCallback):
            if isinstance(unionTypeOrDictionaryOrCallback, IDLDictionary):
                return unionTypeOrDictionaryOrCallback.identifier.name
            if (
                unionTypeOrDictionaryOrCallback.isType()
                and unionTypeOrDictionaryOrCallback.isUnion()
            ):
                return unionTypeOrDictionaryOrCallback.name
            assert unionTypeOrDictionary.isType() and unionTypeOrDictionary.isUnion()
            return unionTypeOrDictionary.name
            assert unionTypeOrDictionaryOrCallback.isCallback()
            return unionTypeOrDictionaryOrCallback.identifier.name
        for t in dependencySortObjects(
            dictionaries + unionStructs, getDependencies, getName
            dictionaries + unionStructs + callbacks, getDependencies, getName
        ):
            if t.isDictionary():
                cgthings.append(CGDictionary(t, config))
            else:
                assert t.isUnion()
            elif t.isUnion():
                cgthings.append(CGUnionStruct(t, config))
                cgthings.append(CGUnionStruct(t, config, True))
        # Do codegen for all the callbacks.
        cgthings.extend(CGCallbackFunction(c, config) for c in callbacks)
        cgthings.extend(
            [CGNamespace("binding_detail", CGFastCallback(c)) for c in callbacks]
        )
            else:
                assert t.isCallback()
                cgthings.append(CGCallbackFunction(t, config))
                cgthings.append(CGNamespace("binding_detail", CGFastCallback(t)))
        # Do codegen for all the descriptors
        cgthings.extend([CGDescriptor(x) for x in descriptors])
Loading