Changeset 263638 in webkit


Ignore:
Timestamp:
Jun 28, 2020 3:49:40 PM (4 years ago)
Author:
Alexey Shvayka
Message:

Improve error message for primitive callback interfaces
https://bugs.webkit.org/show_bug.cgi?id=213684

Reviewed by Darin Adler.

Source/WebCore:

This patch rewords TypeError message for non-object callback interfaces
because apart from function, an object with certain method is also allowed.
New error message matches Chrome and Firefox.

Tests: fast/dom/createNodeIterator-parameters.html

fast/dom/createTreeWalker-parameters.html

  • bindings/js/JSDOMExceptionHandling.cpp:

(WebCore::throwArgumentMustBeObjectError):

  • bindings/js/JSDOMExceptionHandling.h:
  • bindings/scripts/CodeGeneratorJS.pm:

(GetArgumentExceptionFunction):

  • bindings/scripts/test/*: Updated.

LayoutTests:

  • fast/dom/createNodeIterator-parameters-expected.txt:
  • fast/dom/createNodeIterator-parameters.html:
  • fast/dom/createTreeWalker-parameters-expected.txt:
  • fast/dom/createTreeWalker-parameters.html:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r263633 r263638  
     12020-06-28  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Improve error message for primitive callback interfaces
     4        https://bugs.webkit.org/show_bug.cgi?id=213684
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/dom/createNodeIterator-parameters-expected.txt:
     9        * fast/dom/createNodeIterator-parameters.html:
     10        * fast/dom/createTreeWalker-parameters-expected.txt:
     11        * fast/dom/createTreeWalker-parameters.html:
     12
    1132020-06-28  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/fast/dom/createNodeIterator-parameters-expected.txt

    r200583 r263638  
    99Null root node
    1010PASS document.createNodeIterator(null) threw exception TypeError: Argument 1 ('root') to Document.createNodeIterator must be an instance of Node.
     11
     12Primitive (symbol) NodeFilter callback
     13PASS document.createNodeIterator(document, null, Symbol()) threw exception TypeError: Argument 3 ('filter') to Document.createNodeIterator must be an object.
    1114
    1215Default parameters
  • trunk/LayoutTests/fast/dom/createNodeIterator-parameters.html

    r200583 r263638  
    1212debug("Null root node");
    1313shouldThrow("document.createNodeIterator(null)", "'TypeError: Argument 1 (\\'root\\') to Document.createNodeIterator must be an instance of Node'");
     14
     15debug("");
     16debug("Primitive (symbol) NodeFilter callback");
     17shouldThrow("document.createNodeIterator(document, null, Symbol())", "'TypeError: Argument 3 (\\'filter\\') to Document.createNodeIterator must be an object'");
    1418
    1519debug("");
  • trunk/LayoutTests/fast/dom/createTreeWalker-parameters-expected.txt

    r200583 r263638  
    99Null root node
    1010PASS document.createTreeWalker(null) threw exception TypeError: Argument 1 ('root') to Document.createTreeWalker must be an instance of Node.
     11
     12Primitive (string) NodeFilter callback
     13PASS document.createTreeWalker(document, null, 'str') threw exception TypeError: Argument 3 ('filter') to Document.createTreeWalker must be an object.
    1114
    1215Default parameters
  • trunk/LayoutTests/fast/dom/createTreeWalker-parameters.html

    r200583 r263638  
    1212debug("Null root node");
    1313shouldThrow("document.createTreeWalker(null)", "'TypeError: Argument 1 (\\'root\\') to Document.createTreeWalker must be an instance of Node'");
     14
     15debug("");
     16debug("Primitive (string) NodeFilter callback");
     17shouldThrow("document.createTreeWalker(document, null, 'str')", "'TypeError: Argument 3 (\\'filter\\') to Document.createTreeWalker must be an object'");
    1418
    1519debug("");
  • trunk/Source/WebCore/ChangeLog

    r263637 r263638  
     12020-06-28  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Improve error message for primitive callback interfaces
     4        https://bugs.webkit.org/show_bug.cgi?id=213684
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch rewords TypeError message for non-object callback interfaces
     9        because apart from function, an object with certain method is also allowed.
     10        New error message matches Chrome and Firefox.
     11
     12        Tests: fast/dom/createNodeIterator-parameters.html
     13               fast/dom/createTreeWalker-parameters.html
     14
     15        * bindings/js/JSDOMExceptionHandling.cpp:
     16        (WebCore::throwArgumentMustBeObjectError):
     17        * bindings/js/JSDOMExceptionHandling.h:
     18        * bindings/scripts/CodeGeneratorJS.pm:
     19        (GetArgumentExceptionFunction):
     20        * bindings/scripts/test/*: Updated.
     21
    1222020-06-28  Rob Buis  <rbuis@igalia.com>
    223
  • trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp

    r251425 r263638  
    213213}
    214214
     215JSC::EncodedJSValue throwArgumentMustBeObjectError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, unsigned argumentIndex, const char* argumentName, const char* interfaceName, const char* functionName)
     216{
     217    StringBuilder builder;
     218    appendArgumentMustBe(builder, argumentIndex, argumentName, interfaceName, functionName);
     219    builder.appendLiteral("an object");
     220    return throwVMTypeError(&lexicalGlobalObject, scope, builder.toString());
     221}
     222
    215223JSC::EncodedJSValue throwArgumentTypeError(JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedType)
    216224{
  • trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.h

    r251445 r263638  
    5151WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeEnumError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedValues);
    5252WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeFunctionError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName);
     53WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeObjectError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName);
    5354WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedType);
    5455WEBCORE_EXPORT JSC::EncodedJSValue throwRequiredMemberTypeError(JSC::JSGlobalObject&, JSC::ThrowScope&, const char* memberName, const char* dictionaryName, const char* expectedType);
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r263628 r263638  
    15041504    my $typeName = GetTypeNameForDisplayInException($argument->type);
    15051505
    1506     if ($codeGenerator->IsCallbackInterface($argument->type) || $codeGenerator->IsCallbackFunction($argument->type)) {
    1507         # FIXME: We should have specialized messages for callback interfaces vs. callback functions.
     1506    if ($codeGenerator->IsCallbackInterface($argument->type)) {
     1507        return "throwArgumentMustBeObjectError(lexicalGlobalObject, scope, ${argumentIndex}, \"${name}\", \"${visibleInterfaceName}\", ${quotedFunctionName});";
     1508    }
     1509
     1510    if ($codeGenerator->IsCallbackFunction($argument->type)) {
    15081511        return "throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, ${argumentIndex}, \"${name}\", \"${visibleInterfaceName}\", ${quotedFunctionName});";
    15091512    }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r262693 r263638  
    19731973    auto& document = downcast<Document>(*context);
    19741974    EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
    1975     auto testCallback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "testCallback", "TestObject", nullptr); });
     1975    auto testCallback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "testCallback", "TestObject", nullptr); });
    19761976    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    19771977    EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1);
     
    73717371        return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
    73727372    EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
    7373     auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "methodWithCallbackArg"); });
     7373    auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "methodWithCallbackArg"); });
    73747374    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    73757375    impl.methodWithCallbackArg(callback.releaseNonNull());
     
    73947394    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    73957395    EnsureStillAliveScope argument1 = callFrame->uncheckedArgument(1);
    7396     auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument1.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 1, "callback", "TestObject", "methodWithNonCallbackArgAndCallbackArg"); });
     7396    auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument1.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 1, "callback", "TestObject", "methodWithNonCallbackArgAndCallbackArg"); });
    73977397    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    73987398    impl.methodWithNonCallbackArgAndCallbackArg(WTFMove(nonCallback), callback.releaseNonNull());
     
    74127412    auto& impl = castedThis->wrapped();
    74137413    EnsureStillAliveScope argument0 = callFrame->argument(0);
    7414     auto callback = convert<IDLNullable<IDLCallbackInterface<JSTestCallbackInterface>>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "methodWithCallbackAndOptionalArg"); });
     7414    auto callback = convert<IDLNullable<IDLCallbackInterface<JSTestCallbackInterface>>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "methodWithCallbackAndOptionalArg"); });
    74157415    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    74167416    impl.methodWithCallbackAndOptionalArg(WTFMove(callback));
     
    74907490    UNUSED_PARAM(throwScope);
    74917491    EnsureStillAliveScope argument0 = callFrame->argument(0);
    7492     auto callback = convert<IDLNullable<IDLCallbackInterface<JSTestCallbackInterface>>>(*lexicalGlobalObject, argument0.value(), *jsCast<JSDOMGlobalObject*>(lexicalGlobalObject), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "staticMethodWithCallbackAndOptionalArg"); });
     7492    auto callback = convert<IDLNullable<IDLCallbackInterface<JSTestCallbackInterface>>>(*lexicalGlobalObject, argument0.value(), *jsCast<JSDOMGlobalObject*>(lexicalGlobalObject), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "staticMethodWithCallbackAndOptionalArg"); });
    74937493    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    74947494    TestObj::staticMethodWithCallbackAndOptionalArg(WTFMove(callback));
     
    75097509        return throwVMError(lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(lexicalGlobalObject));
    75107510    EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
    7511     auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *jsCast<JSDOMGlobalObject*>(lexicalGlobalObject), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "staticMethodWithCallbackArg"); });
     7511    auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *jsCast<JSDOMGlobalObject*>(lexicalGlobalObject), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "staticMethodWithCallbackArg"); });
    75127512    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    75137513    TestObj::staticMethodWithCallbackArg(callback.releaseNonNull());
     
    76397639    auto& impl = castedThis->wrapped();
    76407640    EnsureStillAliveScope argument0 = callFrame->uncheckedArgument(0);
    7641     auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "overloadedMethod"); });
     7641    auto callback = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument0.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 0, "callback", "TestObject", "overloadedMethod"); });
    76427642    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    76437643    impl.overloadedMethod(callback.releaseNonNull());
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp

    r262628 r263638  
    170170    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    171171    EnsureStillAliveScope argument2 = callFrame->uncheckedArgument(2);
    172     auto testCallbackInterface = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument2.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeFunctionError(lexicalGlobalObject, scope, 2, "testCallbackInterface", "TestTypedefs", nullptr); });
     172    auto testCallbackInterface = convert<IDLCallbackInterface<JSTestCallbackInterface>>(*lexicalGlobalObject, argument2.value(), *castedThis->globalObject(), [](JSC::JSGlobalObject& lexicalGlobalObject, JSC::ThrowScope& scope) { throwArgumentMustBeObjectError(lexicalGlobalObject, scope, 2, "testCallbackInterface", "TestTypedefs", nullptr); });
    173173    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
    174174    auto object = TestTypedefs::create(WTFMove(hello), testCallbackFunction.releaseNonNull(), testCallbackInterface.releaseNonNull());
Note: See TracChangeset for help on using the changeset viewer.