[JSC] JSON.stringify can accept call-with-no-arguments
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 13:48:11 +0000 (13:48 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 13:48:11 +0000 (13:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190343

Reviewed by Mark Lam.

JSTests:

* stress/json-stringify-no-arguments.js: Added.
(shouldBe):

Source/JavaScriptCore:

JSON.stringify can accept `JSON.stringify()` call (call-with-no-arguments) according to the spec[1].
Instead of throwing an error, we should take the first argument as `undefined` if it is not given.

[1]: https://tc39.github.io/ecma262/#sec-json.stringify

* runtime/JSONObject.cpp:
(JSC::JSONProtoFuncStringify):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/stress/json-stringify-no-arguments.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSONObject.cpp

index 8196b00..1a9be08 100644 (file)
@@ -1,3 +1,13 @@
+2018-10-13  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] JSON.stringify can accept call-with-no-arguments
+        https://bugs.webkit.org/show_bug.cgi?id=190343
+
+        Reviewed by Mark Lam.
+
+        * stress/json-stringify-no-arguments.js: Added.
+        (shouldBe):
+
 2018-10-08  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
 
         [JSC] JSC should have "parseFunction" to optimize Function constructor
diff --git a/JSTests/stress/json-stringify-no-arguments.js b/JSTests/stress/json-stringify-no-arguments.js
new file mode 100644 (file)
index 0000000..905ac25
--- /dev/null
@@ -0,0 +1,7 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+shouldBe(JSON.stringify(), undefined);
+shouldBe(JSON.stringify(undefined), undefined);
index fa8e939..164f796 100644 (file)
@@ -1,3 +1,18 @@
+2018-10-13  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
+
+        [JSC] JSON.stringify can accept call-with-no-arguments
+        https://bugs.webkit.org/show_bug.cgi?id=190343
+
+        Reviewed by Mark Lam.
+
+        JSON.stringify can accept `JSON.stringify()` call (call-with-no-arguments) according to the spec[1].
+        Instead of throwing an error, we should take the first argument as `undefined` if it is not given.
+
+        [1]: https://tc39.github.io/ecma262/#sec-json.stringify
+
+        * runtime/JSONObject.cpp:
+        (JSC::JSONProtoFuncStringify):
+
 2018-10-12  Tadeu Zagallo  <tzagallo@apple.com>
 
         Gardening: Build fix after r237084.
index 2998702..3dc2b8f 100644 (file)
@@ -829,11 +829,9 @@ EncodedJSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec)
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    if (!exec->argumentCount())
-        return throwVMError(exec, scope, createError(exec, "No input to stringify"_s));
     Stringifier stringifier(exec, exec->argument(1), exec->argument(2));
     RETURN_IF_EXCEPTION(scope, { });
-    RELEASE_AND_RETURN(scope, JSValue::encode(stringifier.stringify(exec->uncheckedArgument(0))));
+    RELEASE_AND_RETURN(scope, JSValue::encode(stringifier.stringify(exec->argument(0))));
 }
 
 JSValue JSONParse(ExecState* exec, const String& json)