Bug 1522433 - Check for a toJSON method on the BigInt prototype when stringifying BigInts. r=jandem
authorRobin Templeton <robin@igalia.com>
Sun, 27 Jan 2019 09:08:31 +0000
changeset 515586 4fbf196208cc9c28be1b9f884c1022f58ac62ba2
parent 515585 dd40395ed807a09a53b06be1176c6000870f6e68
child 515590 06e3993985b77e62c9b6ee1f9dba87da407eb6d1
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1522433
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522433 - Check for a toJSON method on the BigInt prototype when stringifying BigInts. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D17541
js/src/builtin/JSON.cpp
js/src/tests/jstests.list
--- a/js/src/builtin/JSON.cpp
+++ b/js/src/builtin/JSON.cpp
@@ -284,20 +284,25 @@ static bool PreprocessValue(JSContext* c
   // We don't want to do any preprocessing here if scx->maybeSafely,
   // since the stuff we do here can have side-effects.
   if (scx->maybeSafely) {
     return true;
   }
 
   RootedString keyStr(cx);
 
-  /* Step 2. */
-  if (vp.isObject()) {
+  // Step 2. Modified by BigInt spec 6.1 to check for a toJSON method on the
+  // BigInt prototype when the value is a BigInt.
+  if (vp.isObject() || IF_BIGINT(vp.isBigInt(), false)) {
     RootedValue toJSON(cx);
-    RootedObject obj(cx, &vp.toObject());
+    RootedObject obj(cx, JS::ToObject(cx, vp));
+    if (!obj) {
+      return false;
+    }
+
     if (!GetProperty(cx, obj, obj, cx->names().toJSON, &toJSON)) {
       return false;
     }
 
     if (IsCallable(toJSON)) {
       keyStr = KeyStringifier<KeyType>::toString(cx, key);
       if (!keyStr) {
         return false;
--- a/js/src/tests/jstests.list
+++ b/js/src/tests/jstests.list
@@ -962,20 +962,16 @@ skip script test262/built-ins/DataView/p
 skip script test262/built-ins/DataView/prototype/getBigUint64/toindex-byteoffset-wrapped-values.js
 
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1501105
 skip script test262/language/expressions/prefix-increment/bigint.js
 skip script test262/language/expressions/postfix-increment/bigint.js
 skip script test262/language/expressions/postfix-decrement/bigint.js
 skip script test262/language/expressions/prefix-decrement/bigint.js
 
-# https://bugzilla.mozilla.org/show_bug.cgi?id=1522433
-skip script test262/built-ins/JSON/stringify/bigint-order.js
-skip script test262/built-ins/JSON/stringify/bigint-tojson.js
-
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1317405
 skip script test262/language/computed-property-names/class/static/method-number.js
 skip script test262/language/computed-property-names/class/static/method-string.js
 skip script test262/language/computed-property-names/class/static/method-symbol.js
 
 # https://bugzilla.mozilla.org/show_bug.cgi?id=1286997
 # Bug 1286997 probably doesn't cover all spec violations.
 skip script test262/language/expressions/assignment/S11.13.1_A5_T5.js