basic.js (1877B)
1 // Copyright (C) 2023 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-json.rawjson 6 description: Basic functionality of JSON.rawJSON(). 7 info: | 8 JSON.rawJSON ( text ) 9 10 1. Let jsonString be ? ToString(text). 11 ... 12 4. Let internalSlotsList be « [[IsRawJSON]] ». 13 5. Let obj be OrdinaryObjectCreate(null, internalSlotsList). 14 6. Perform ! CreateDataPropertyOrThrow(obj, "rawJSON", jsonString). 15 7. Perform ! SetIntegrityLevel(obj, frozen). 16 8. Return obj. 17 18 features: [json-parse-with-source] 19 ---*/ 20 21 assert.sameValue(JSON.stringify(JSON.rawJSON(1)), '1'); 22 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1)), '1.1'); 23 assert.sameValue(JSON.stringify(JSON.rawJSON(-1)), '-1'); 24 assert.sameValue(JSON.stringify(JSON.rawJSON(-1.1)), '-1.1'); 25 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1e1)), '11'); 26 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1e-1)), '0.11'); 27 28 assert.sameValue(JSON.stringify(JSON.rawJSON(null)), 'null'); 29 assert.sameValue(JSON.stringify(JSON.rawJSON(true)), 'true'); 30 assert.sameValue(JSON.stringify(JSON.rawJSON(false)), 'false'); 31 assert.sameValue(JSON.stringify(JSON.rawJSON('"foo"')), '"foo"'); 32 33 assert.sameValue(JSON.stringify({ 42: JSON.rawJSON(37) }), '{"42":37}'); 34 assert.sameValue( 35 JSON.stringify({ x: JSON.rawJSON(1), y: JSON.rawJSON(2) }), 36 '{"x":1,"y":2}' 37 ); 38 assert.sameValue( 39 JSON.stringify({ x: { x: JSON.rawJSON(1), y: JSON.rawJSON(2) } }), 40 '{"x":{"x":1,"y":2}}' 41 ); 42 43 assert.sameValue(JSON.stringify([JSON.rawJSON(1), JSON.rawJSON(1.1)]), '[1,1.1]'); 44 assert.sameValue( 45 JSON.stringify([ 46 JSON.rawJSON('"1"'), 47 JSON.rawJSON(true), 48 JSON.rawJSON(null), 49 JSON.rawJSON(false), 50 ]), 51 '["1",true,null,false]' 52 ); 53 assert.sameValue( 54 JSON.stringify([{ x: JSON.rawJSON(1), y: JSON.rawJSON(1) }]), 55 '[{"x":1,"y":1}]' 56 ); 57 58 reportCompare(0, 0);