Commit 62dcf2fa authored by yangguo's avatar yangguo Committed by Commit bot

[es6] correctly handle object wrappers in JSON.stringify.

R=bmeurer@chromium.org
BUG=v8:4581
LOG=N

Review URL: https://codereview.chromium.org/1495473002

Cr-Commit-Position: refs/heads/master@{#32494}
parent 4fb84b9d
......@@ -397,9 +397,10 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue(
DCHECK(value->IsBoolean());
builder_.AppendCString(value->IsTrue() ? "true" : "false");
} else {
// Fail gracefully for special value wrappers.
isolate_->ThrowIllegalOperation();
return EXCEPTION;
// ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject.
CHECK(!object->IsAccessCheckNeeded());
CHECK(!object->IsJSGlobalProxy());
return SerializeJSObject(object);
}
return SUCCESS;
}
......
......@@ -549,3 +549,16 @@ function TestContext() {
assertFalse(verifier(rSymbol, TypeError()));
}
TestContext();
function TestStringify(expected, input) {
assertEquals(expected, JSON.stringify(input));
assertEquals(expected, JSON.stringify(input, null, 0));
}
TestStringify(undefined, Symbol("a"));
TestStringify('[{}]', [Object(Symbol())]);
var symbol_wrapper = Object(Symbol("a"))
TestStringify('{}', symbol_wrapper);
symbol_wrapper.a = 1;
TestStringify('{"a":1}', symbol_wrapper);
......@@ -618,3 +618,17 @@ function TestSIMDObject() {
assertSame(SIMD.Bool8x16, undefined);
}
TestSIMDObject()
function TestStringify(expected, input) {
assertEquals(expected, JSON.stringify(input));
assertEquals(expected, JSON.stringify(input, null, 0));
}
TestStringify(undefined, SIMD.Float32x4(1, 2, 3, 4));
TestStringify('[null]', [SIMD.Float32x4(1, 2, 3, 4)]);
TestStringify('[{}]', [Object(SIMD.Float32x4(1, 2, 3, 4))]);
var simd_wrapper = Object(SIMD.Float32x4(1, 2, 3, 4));
TestStringify('{}', simd_wrapper);
simd_wrapper.a = 1;
TestStringify('{"a":1}', simd_wrapper);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment