Bug 1836127 - Nullable union used as callback arguments needs to be actually declared; r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D176127
This commit is contained in:
Edgar Chen 2023-06-02 09:47:46 +00:00
parent 3c666e778d
commit 5efbb426be
6 changed files with 25 additions and 11 deletions

View File

@ -1363,15 +1363,21 @@ class CGHeaders(CGWrapper):
bindingHeaders = set()
declareIncludes = set(declareIncludes)
def addHeadersForType(typeAndPossibleDictionary):
def addHeadersForType(typeAndPossibleOriginType):
"""
Add the relevant headers for this type. We use dictionary, if
Add the relevant headers for this type. We use its origin type, if
passed, to decide what to do with interface types.
"""
t, dictionary = typeAndPossibleDictionary
t, originType = typeAndPossibleOriginType
isFromDictionary = originType and originType.isDictionary()
isFromCallback = originType and originType.isCallback()
# Dictionaries have members that need to be actually
# declared, not just forward-declared.
if dictionary:
# Callbacks have nullable union arguments that need to be actually
# declared, not just forward-declared.
if isFromDictionary:
headerSet = declareIncludes
elif isFromCallback and t.nullable() and t.isUnion():
headerSet = declareIncludes
else:
headerSet = bindingHeaders
@ -1446,13 +1452,13 @@ class CGHeaders(CGWrapper):
elif unrolled.isPrimitive():
bindingHeaders.add("mozilla/dom/PrimitiveConversions.h")
elif unrolled.isRecord():
if dictionary or jsImplementedDescriptors:
if isFromDictionary or jsImplementedDescriptors:
declareIncludes.add("mozilla/dom/Record.h")
else:
bindingHeaders.add("mozilla/dom/Record.h")
# Also add headers for the type the record is
# parametrized over, if needed.
addHeadersForType((t.inner, dictionary))
addHeadersForType((t.inner, originType if isFromDictionary else None))
for t in getAllTypes(
descriptors + callbackDescriptors, dictionaries, callbacks

View File

@ -1083,7 +1083,7 @@ def getAllTypes(descriptors, dictionaries, callbacks):
yield (t, dictionary)
for callback in callbacks:
for t in getTypesFromCallback(callback):
yield (t, None)
yield (t, callback)
# For sync value iterators, we use default array implementation, for async

View File

@ -24,6 +24,7 @@ namespace mozilla {
namespace dom {
class DocGroup;
class TestExternalInterface;
class TestUnionArguments;
class Promise;
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,10 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
callback TestUnionArguments = undefined((DOMString or long) arg1,
(DOMString or long)? arg2,
optional (DOMString or long) arg3,
optional (DOMString or long)? arg4);

View File

@ -126,10 +126,6 @@ callback TestOptionalArguments = undefined(optional DOMString aString,
optional TestInterface? anInterface,
optional TestInterface anotherInterface,
optional long aLong);
callback TestUnionArguments = undefined((DOMString or long) arg1,
(DOMString or long)? arg2,
optional (DOMString or long) arg3,
optional (DOMString or long)? arg4);
// Callback constructor return value tests
callback constructor TestUndefinedConstruction = undefined(TestDictionaryTypedef arg);
callback constructor TestIntegerConstruction = unsigned long();

View File

@ -17,6 +17,7 @@ MOCHITEST_MANIFESTS += ["mochitest.ini"]
MOCHITEST_CHROME_MANIFESTS += ["chrome.ini"]
TEST_WEBIDL_FILES += [
"TestCallback.webidl",
"TestDictionary.webidl",
"TestJSImplInheritanceGen.webidl",
"TestTypedef.webidl",