Changeset 133932 in webkit


Ignore:
Timestamp:
Nov 8, 2012 12:33:42 PM (11 years ago)
Author:
arv@chromium.org
Message:

Wrong error type is thrown for type errors in callbacks
https://bugs.webkit.org/show_bug.cgi?id=101502

Reviewed by Adam Barth.

We should be throwing a TypeError and not a DOMException with code TYPE_MISMATCH_ERR.

http://www.w3.org/TR/WebIDL/#es-callback-function

Source/WebCore:

Updated existing tests.

  • bindings/scripts/CodeGeneratorJS.pm:
  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/scripts/test/JS/JSTestObj.cpp:
  • bindings/scripts/test/V8/V8TestObj.cpp:

LayoutTests:

  • fast/mediastream/argument-types-expected.txt:
  • fast/mediastream/peerconnection-argument-types-expected.txt:
  • fast/mediastream/script-tests/argument-types.js:
  • fast/mediastream/script-tests/peerconnection-argument-types.js:
  • fast/workers/storage/open-database-inputs-sync-expected.txt:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r133930 r133932  
     12012-11-08  Erik Arvidsson  <arv@chromium.org>
     2
     3        Wrong error type is thrown for type errors in callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=101502
     5
     6        Reviewed by Adam Barth.
     7
     8        We should be throwing a TypeError and not a DOMException with code TYPE_MISMATCH_ERR.
     9
     10        http://www.w3.org/TR/WebIDL/#es-callback-function
     11
     12        * fast/mediastream/argument-types-expected.txt:
     13        * fast/mediastream/peerconnection-argument-types-expected.txt:
     14        * fast/mediastream/script-tests/argument-types.js:
     15        * fast/mediastream/script-tests/peerconnection-argument-types.js:
     16        * fast/workers/storage/open-database-inputs-sync-expected.txt:
     17
    1182012-11-08  Yael Aharon  <yael.aharon@intel.com>
    219
  • trunk/LayoutTests/fast/mediastream/argument-types-expected.txt

    r115810 r133932  
    2323PASS navigator.webkitGetUserMedia(-Infinity, emptyFunction) threw exception TypeError: Not an object..
    2424PASS navigator.webkitGetUserMedia(emptyFunction, emptyFunction) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
    25 PASS navigator.webkitGetUserMedia({video: true}, "foobar") threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    26 PASS navigator.webkitGetUserMedia({video: true}, undefined) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    27 PASS navigator.webkitGetUserMedia({video: true}, null) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    28 PASS navigator.webkitGetUserMedia({video: true}, {}) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    29 PASS navigator.webkitGetUserMedia({video: true}, true) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    30 PASS navigator.webkitGetUserMedia({video: true}, 42) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    31 PASS navigator.webkitGetUserMedia({video: true}, Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    32 PASS navigator.webkitGetUserMedia({video: true}, -Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     25PASS navigator.webkitGetUserMedia({video: true}, "foobar") threw exception TypeError: Type error.
     26PASS navigator.webkitGetUserMedia({video: true}, undefined) threw exception TypeError: Type error.
     27PASS navigator.webkitGetUserMedia({video: true}, null) threw exception TypeError: Type error.
     28PASS navigator.webkitGetUserMedia({video: true}, {}) threw exception TypeError: Type error.
     29PASS navigator.webkitGetUserMedia({video: true}, true) threw exception TypeError: Type error.
     30PASS navigator.webkitGetUserMedia({video: true}, 42) threw exception TypeError: Type error.
     31PASS navigator.webkitGetUserMedia({video: true}, Infinity) threw exception TypeError: Type error.
     32PASS navigator.webkitGetUserMedia({video: true}, -Infinity) threw exception TypeError: Type error.
    3333PASS navigator.webkitGetUserMedia({ }, emptyFunction, emptyFunction) threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
    3434PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, emptyFunction) did not throw exception.
     
    3636PASS navigator.webkitGetUserMedia({audio:true, video:true}, emptyFunction, undefined) did not throw exception.
    3737PASS navigator.webkitGetUserMedia({audio:true}, emptyFunction, undefined) did not throw exception.
    38 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, "video") threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     38PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, "video") threw exception TypeError: Type error.
    3939PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, null) did not throw exception.
    40 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, {}) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    41 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, true) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    42 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, 42) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    43 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    44 PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, -Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     40PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, {}) threw exception TypeError: Type error.
     41PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, true) threw exception TypeError: Type error.
     42PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, 42) threw exception TypeError: Type error.
     43PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, Infinity) threw exception TypeError: Type error.
     44PASS navigator.webkitGetUserMedia({video: true}, emptyFunction, -Infinity) threw exception TypeError: Type error.
    4545PASS successfullyParsed is true
    4646
  • trunk/LayoutTests/fast/mediastream/peerconnection-argument-types-expected.txt

    r123724 r133932  
    4545PASS new webkitPeerConnection00("STUN NONE",emptyFunction) did not throw exception.
    4646PASS new webkitPeerConnection00("STUNS NONE",emptyFunction) did not throw exception.
    47 PASS new webkitPeerConnection00("TURN NONE",undefined) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    48 PASS new webkitPeerConnection00("TURNS NONE",{}) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    49 PASS new webkitPeerConnection00("STUN NONE",42) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    50 PASS new webkitPeerConnection00("STUNS NONE",Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
    51 PASS new webkitPeerConnection00("STUNS NONE",-Infinity) threw exception Error: TYPE_MISMATCH_ERR: DOM Exception 17.
     47PASS new webkitPeerConnection00("TURN NONE",undefined) threw exception TypeError: Type error.
     48PASS new webkitPeerConnection00("TURNS NONE",{}) threw exception TypeError: Type error.
     49PASS new webkitPeerConnection00("STUN NONE",42) threw exception TypeError: Type error.
     50PASS new webkitPeerConnection00("STUNS NONE",Infinity) threw exception TypeError: Type error.
     51PASS new webkitPeerConnection00("STUNS NONE",-Infinity) threw exception TypeError: Type error.
    5252PASS successfullyParsed is true
    5353
  • trunk/LayoutTests/fast/mediastream/script-tests/argument-types.js

    r116511 r133932  
    44    if (expressionShouldThrow) {
    55        if (expectedException)
    6             shouldThrow(expression, '(function() { return "' + expectedException + '"; })();');
     6            shouldThrow(expression, '"' + expectedException + '"');
    77        else
    8             shouldThrow(expression, '(function() { return "TypeError: Not enough arguments"; })();');
     8            shouldThrow(expression, '"TypeError: Not enough arguments"');
    99    } else {
    1010        shouldNotThrow(expression);
     
    1313
    1414var notSupportedError = new Error('NOT_SUPPORTED_ERR: DOM Exception 9');
    15 var typeMismatchError = new Error('TYPE_MISMATCH_ERR: DOM Exception 17');
     15var typeError = new TypeError('Type error');
    1616var typeNotAnObjectError = new TypeError('Not an object.');
    1717
     
    4242test('navigator.webkitGetUserMedia(-Infinity, emptyFunction)', true, typeNotAnObjectError);
    4343test('navigator.webkitGetUserMedia(emptyFunction, emptyFunction)', true, notSupportedError);
    44 test('navigator.webkitGetUserMedia({video: true}, "foobar")', true, typeMismatchError);
    45 test('navigator.webkitGetUserMedia({video: true}, undefined)', true, typeMismatchError);
    46 test('navigator.webkitGetUserMedia({video: true}, null)', true, typeMismatchError);
    47 test('navigator.webkitGetUserMedia({video: true}, {})', true, typeMismatchError);
    48 test('navigator.webkitGetUserMedia({video: true}, true)', true, typeMismatchError);
    49 test('navigator.webkitGetUserMedia({video: true}, 42)', true, typeMismatchError);
    50 test('navigator.webkitGetUserMedia({video: true}, Infinity)', true, typeMismatchError);
    51 test('navigator.webkitGetUserMedia({video: true}, -Infinity)', true, typeMismatchError);
     44test('navigator.webkitGetUserMedia({video: true}, "foobar")', true, typeError);
     45test('navigator.webkitGetUserMedia({video: true}, undefined)', true, typeError);
     46test('navigator.webkitGetUserMedia({video: true}, null)', true, typeError);
     47test('navigator.webkitGetUserMedia({video: true}, {})', true, typeError);
     48test('navigator.webkitGetUserMedia({video: true}, true)', true, typeError);
     49test('navigator.webkitGetUserMedia({video: true}, 42)', true, typeError);
     50test('navigator.webkitGetUserMedia({video: true}, Infinity)', true, typeError);
     51test('navigator.webkitGetUserMedia({video: true}, -Infinity)', true, typeError);
    5252
    5353// 3 Arguments.
     
    5757test('navigator.webkitGetUserMedia({audio:true, video:true}, emptyFunction, undefined)', false);
    5858test('navigator.webkitGetUserMedia({audio:true}, emptyFunction, undefined)', false);
    59 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, "video")', true, typeMismatchError);
     59test('navigator.webkitGetUserMedia({video: true}, emptyFunction, "video")', true, typeError);
    6060test('navigator.webkitGetUserMedia({video: true}, emptyFunction, null)', false );
    61 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, {})', true, typeMismatchError);
    62 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, true)', true, typeMismatchError);
    63 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, 42)', true, typeMismatchError);
    64 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, Infinity)', true, typeMismatchError);
    65 test('navigator.webkitGetUserMedia({video: true}, emptyFunction, -Infinity)', true, typeMismatchError);
     61test('navigator.webkitGetUserMedia({video: true}, emptyFunction, {})', true, typeError);
     62test('navigator.webkitGetUserMedia({video: true}, emptyFunction, true)', true, typeError);
     63test('navigator.webkitGetUserMedia({video: true}, emptyFunction, 42)', true, typeError);
     64test('navigator.webkitGetUserMedia({video: true}, emptyFunction, Infinity)', true, typeError);
     65test('navigator.webkitGetUserMedia({video: true}, emptyFunction, -Infinity)', true, typeError);
    6666
    6767window.jsTestIsAsync = false;
  • trunk/LayoutTests/fast/mediastream/script-tests/peerconnection-argument-types.js

    r123724 r133932  
    44    if (expressionShouldThrow) {
    55        if (expectedException)
    6             shouldThrow(expression, '(function() { return "' + expectedException + '"; })();');
     6            shouldThrow(expression, '"' + expectedException + '"');
    77        else
    8             shouldThrow(expression, '(function() { return "Error: TYPE_MISMATCH_ERR: DOM Exception 17"; })();');
     8            shouldThrow(expression, '"TypeError: Type error"');
    99    } else {
    1010        shouldNotThrow(expression);
  • trunk/LayoutTests/fast/workers/storage/open-database-inputs-sync-expected.txt

    r65005 r133932  
    55PASS: undefined
    66PASS: undefined
    7 PASS: TYPE_MISMATCH_ERR: DOM Exception 17
     7PASS: Type error
    88PASS: openDatabaseSync() succeeded.
    99PASS: openDatabaseSync() succeeded.
  • trunk/Source/WebCore/ChangeLog

    r133926 r133932  
     12012-11-08  Erik Arvidsson  <arv@chromium.org>
     2
     3        Wrong error type is thrown for type errors in callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=101502
     5
     6        Reviewed by Adam Barth.
     7
     8        We should be throwing a TypeError and not a DOMException with code TYPE_MISMATCH_ERR.
     9
     10        http://www.w3.org/TR/WebIDL/#es-callback-function
     11
     12        Updated existing tests.
     13
     14        * bindings/scripts/CodeGeneratorJS.pm:
     15        * bindings/scripts/CodeGeneratorV8.pm:
     16        * bindings/scripts/test/JS/JSTestObj.cpp:
     17        * bindings/scripts/test/V8/V8TestObj.cpp:
     18
    1192012-11-08  Andreas Kling  <kling@webkit.org>
    220
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r132973 r133932  
    27042704                push(@$outputArray, "    RefPtr<$argType> $name;\n");
    27052705                push(@$outputArray, "    if (exec->argumentCount() > $argsIndex && !exec->argument($argsIndex).isUndefinedOrNull()) {\n");
    2706                 push(@$outputArray, "        if (!exec->argument($argsIndex).isFunction()) {\n");
    2707                 push(@$outputArray, "            setDOMException(exec, TYPE_MISMATCH_ERR);\n");
    2708                 push(@$outputArray, "            return JSValue::encode(jsUndefined());\n");
    2709                 push(@$outputArray, "        }\n");
     2706                push(@$outputArray, "        if (!exec->argument($argsIndex).isFunction())\n");
     2707                push(@$outputArray, "            return throwVMTypeError(exec);\n");
    27102708                push(@$outputArray, "        $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n");
    27112709                push(@$outputArray, "    }\n");
    27122710            } else {
    2713                 push(@$outputArray, "    if (exec->argumentCount() <= $argsIndex || !exec->argument($argsIndex).isFunction()) {\n");
    2714                 push(@$outputArray, "        setDOMException(exec, TYPE_MISMATCH_ERR);\n");
    2715                 push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
    2716                 push(@$outputArray, "    }\n");
     2711                push(@$outputArray, "    if (exec->argumentCount() <= $argsIndex || !exec->argument($argsIndex).isFunction())\n");
     2712                push(@$outputArray, "        return throwVMTypeError(exec);\n");
    27172713                push(@$outputArray, "    RefPtr<$argType> $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n");
    27182714            }
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r133829 r133932  
    17461746                $parameterCheckString .= "    if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n";
    17471747                $parameterCheckString .= "        if (!args[$paramIndex]->IsFunction())\n";
    1748                 $parameterCheckString .= "            return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());\n";
     1748                $parameterCheckString .= "            return throwTypeError(0, args.GetIsolate());\n";
    17491749                $parameterCheckString .= "        $parameterName = ${className}::create(args[$paramIndex], getScriptExecutionContext());\n";
    17501750                $parameterCheckString .= "    }\n";
    17511751            } else {
    17521752                $parameterCheckString .= "    if (args.Length() <= $paramIndex || !args[$paramIndex]->IsFunction())\n";
    1753                 $parameterCheckString .= "        return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());\n";
     1753                $parameterCheckString .= "        return throwTypeError(0, args.GetIsolate());\n";
    17541754                $parameterCheckString .= "    RefPtr<" . $parameter->type . "> $parameterName = ${className}::create(args[$paramIndex], getScriptExecutionContext());\n";
    17551755            }
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r132698 r133932  
    231231    if (exec->argumentCount() < 1)
    232232        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    233     if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction()) {
    234         setDOMException(exec, TYPE_MISMATCH_ERR);
    235         return JSValue::encode(jsUndefined());
    236     }
     233    if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction())
     234        return throwVMTypeError(exec);
    237235    RefPtr<TestCallback> testCallback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject());
    238236    RefPtr<TestObj> object = TestObj::create(testCallback);
     
    19941992    if (exec->argumentCount() < 1)
    19951993        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    1996     if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction()) {
    1997         setDOMException(exec, TYPE_MISMATCH_ERR);
    1998         return JSValue::encode(jsUndefined());
    1999     }
     1994    if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction())
     1995        return throwVMTypeError(exec);
    20001996    RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject());
    20011997    impl->methodWithCallbackArg(callback);
     
    20162012    if (exec->hadException())
    20172013        return JSValue::encode(jsUndefined());
    2018     if (exec->argumentCount() <= 1 || !exec->argument(1).isFunction()) {
    2019         setDOMException(exec, TYPE_MISMATCH_ERR);
    2020         return JSValue::encode(jsUndefined());
    2021     }
     2014    if (exec->argumentCount() <= 1 || !exec->argument(1).isFunction())
     2015        return throwVMTypeError(exec);
    20222016    RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(1)), castedThis->globalObject());
    20232017    impl->methodWithNonCallbackArgAndCallbackArg(nonCallback, callback);
     
    20352029    RefPtr<TestCallback> callback;
    20362030    if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull()) {
    2037         if (!exec->argument(0).isFunction()) {
    2038             setDOMException(exec, TYPE_MISMATCH_ERR);
    2039             return JSValue::encode(jsUndefined());
    2040         }
     2031        if (!exec->argument(0).isFunction())
     2032            return throwVMTypeError(exec);
    20412033        callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject());
    20422034    }
     
    21822174    if (exec->argumentCount() < 1)
    21832175        return throwVMError(exec, createNotEnoughArgumentsError(exec));
    2184     if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction()) {
    2185         setDOMException(exec, TYPE_MISMATCH_ERR);
    2186         return JSValue::encode(jsUndefined());
    2187     }
     2176    if (exec->argumentCount() <= 0 || !exec->argument(0).isFunction())
     2177        return throwVMTypeError(exec);
    21882178    RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject());
    21892179    impl->overloadedMethod(callback);
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r133719 r133932  
    14281428    TestObj* imp = V8TestObj::toNative(args.Holder());
    14291429    if (args.Length() <= 0 || !args[0]->IsFunction())
    1430         return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
     1430        return throwTypeError(0, args.GetIsolate());
    14311431    RefPtr<TestCallback> callback = V8TestCallback::create(args[0], getScriptExecutionContext());
    14321432    imp->methodWithCallbackArg(callback);
     
    14421442    EXCEPTION_BLOCK(int, nonCallback, toInt32(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)));
    14431443    if (args.Length() <= 1 || !args[1]->IsFunction())
    1444         return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
     1444        return throwTypeError(0, args.GetIsolate());
    14451445    RefPtr<TestCallback> callback = V8TestCallback::create(args[1], getScriptExecutionContext());
    14461446    imp->methodWithNonCallbackArgAndCallbackArg(nonCallback, callback);
     
    14551455    if (args.Length() > 0 && !args[0]->IsNull() && !args[0]->IsUndefined()) {
    14561456        if (!args[0]->IsFunction())
    1457             return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
     1457            return throwTypeError(0, args.GetIsolate());
    14581458        callback = V8TestCallback::create(args[0], getScriptExecutionContext());
    14591459    }
     
    15541554    TestObj* imp = V8TestObj::toNative(args.Holder());
    15551555    if (args.Length() <= 0 || !args[0]->IsFunction())
    1556         return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
     1556        return throwTypeError(0, args.GetIsolate());
    15571557    RefPtr<TestCallback> callback = V8TestCallback::create(args[0], getScriptExecutionContext());
    15581558    imp->overloadedMethod(callback);
     
    21732173        return throwNotEnoughArgumentsError(args.GetIsolate());
    21742174    if (args.Length() <= 0 || !args[0]->IsFunction())
    2175         return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());
     2175        return throwTypeError(0, args.GetIsolate());
    21762176    RefPtr<TestCallback> testCallback = V8TestCallback::create(args[0], getScriptExecutionContext());
    21772177
Note: See TracChangeset for help on using the changeset viewer.