Changeset 246162 in webkit


Ignore:
Timestamp:
Jun 6, 2019 12:07:55 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

JSON.parse throws incorrect exception when called w/o arguments
https://bugs.webkit.org/show_bug.cgi?id=198574

Patch by Alexey Shvayka <Alexey Shvayka> on 2019-06-06
Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

Always coerce first argument to string and attempt to parse it.
(steps 1-2 of https://tc39.github.io/ecma262/#sec-json.parse)

  • runtime/JSONObject.cpp:

(JSC::JSONProtoFuncParse): Remove argumentCount check.

LayoutTests:

SyntaxError should be thrown if JSON.parse is called w/o arguments.
(steps 1-2 of https://tc39.github.io/ecma262/#sec-json.parse)

  • js/dom/JSON-parse-expected.txt:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246156 r246162  
     12019-06-06  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        JSON.parse throws incorrect exception when called w/o arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=198574
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        SyntaxError should be thrown if JSON.parse is called w/o arguments.
     9        (steps 1-2 of https://tc39.github.io/ecma262/#sec-json.parse)
     10
     11        * js/dom/JSON-parse-expected.txt:
     12
    1132019-06-06  Antti Koivisto  <antti@apple.com>
    214
  • trunk/LayoutTests/js/dom/JSON-parse-expected.txt

    r245028 r246162  
    22        return jsonObject.parse();
    33    }
    4 PASS tests[i](nativeJSON) threw exception Error: JSON.parse requires at least one parameter.
     4PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Unexpected identifier "undefined".
    55function (jsonObject){
    66        return jsonObject.parse('');
  • trunk/Source/JavaScriptCore/ChangeLog

    r246160 r246162  
     12019-06-06  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        JSON.parse throws incorrect exception when called w/o arguments
     4        https://bugs.webkit.org/show_bug.cgi?id=198574
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Always coerce first argument to string and attempt to parse it.
     9        (steps 1-2 of https://tc39.github.io/ecma262/#sec-json.parse)
     10
     11        * runtime/JSONObject.cpp:
     12        (JSC::JSONProtoFuncParse): Remove argumentCount check.
     13
    1142019-06-06  Keith Miller  <keith_miller@apple.com>
    215
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r246034 r246162  
    802802    VM& vm = exec->vm();
    803803    auto scope = DECLARE_THROW_SCOPE(vm);
    804 
    805     if (!exec->argumentCount())
    806         return throwVMError(exec, scope, createError(exec, "JSON.parse requires at least one parameter"_s));
    807     auto viewWithString = exec->uncheckedArgument(0).toString(exec)->viewWithUnderlyingString(exec);
     804    auto viewWithString = exec->argument(0).toString(exec)->viewWithUnderlyingString(exec);
    808805    RETURN_IF_EXCEPTION(scope, { });
    809806    StringView view = viewWithString.view;
Note: See TracChangeset for help on using the changeset viewer.