Skip to content

Commit 5b5ad5a

Browse files
committed
json-parse-with-source: JSON.rawJSON success cases
1 parent f892253 commit 5b5ad5a

File tree

2 files changed

+60
-71
lines changed

2 files changed

+60
-71
lines changed

test/built-ins/JSON/rawJSON/basic.js

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,71 @@ esid: sec-json.rawjson
66
description: Basic functionality of JSON.rawJSON().
77
info: |
88
JSON.rawJSON ( text )
9-
10-
1. Let jsonString be ? ToString(text).
119
...
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.
10+
9. Let _obj_ be OrdinaryObjectCreate(*null*, _internalSlotsList_).
11+
10. Perform ! CreateDataPropertyOrThrow(_obj_, *"rawJSON"*, _jsonString_).
12+
11. Perform ! SetIntegrityLevel(_obj_, ~frozen~).
13+
12. Return _obj_.
1714
15+
includes: [propertyHelper.js]
1816
features: [json-parse-with-source]
1917
---*/
2018

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');
19+
function verifyRawJSON(primitive) {
20+
var entries = [
21+
['primitive', JSON.rawJSON(primitive)],
22+
['string', JSON.rawJSON(String(primitive))],
23+
['toString', JSON.rawJSON({ toString: function() { return primitive; } })]
24+
];
25+
for (var i = 0; i < entries.length; i++) {
26+
var label = 'rawJSON of ' + entries[i][0] + ' ' + (typeof primitive) + ' ' + primitive;
27+
var raw = entries[i][1];
28+
assert.sameValue(Object.getPrototypeOf(raw), null, label + ' has a null prototype');
29+
assert.sameValue(Object.isFrozen(raw), true, label + ' is frozen');
30+
assert.sameValue(
31+
Reflect.defineProperty(raw, 'expando', { value: true }),
32+
false,
33+
label + ' rejects new properties'
34+
);
35+
assert.sameValue(
36+
Object.getOwnPropertyDescriptor(raw, 'expando'),
37+
undefined,
38+
label + ' does not define new properties'
39+
);
40+
assert.compareArray(Reflect.ownKeys(raw), ['rawJSON'], label + ' own properties');
41+
verifyProperty(raw, 'rawJSON', {
42+
value: String(primitive),
43+
enumerable: true,
44+
configurable: false,
45+
writable: false
46+
});
47+
assert.sameValue(JSON.stringify(raw), String(primitive), label + ' JSON.stringify');
48+
}
49+
var composite = {
50+
primitive: entries[0][1],
51+
strings: [entries[1][1], entries[2][1]]
52+
};
53+
assert.sameValue(
54+
JSON.stringify(composite),
55+
'{"primitive":%s,"strings":[%s,%s]}'.replace(/%s/g, primitive),
56+
'JSON.stringify a structure containing rawJSON for ' + primitive
57+
);
58+
}
59+
60+
verifyRawJSON(null);
61+
verifyRawJSON(false);
62+
verifyRawJSON(true);
2763

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"');
64+
verifyRawJSON('""');
65+
verifyRawJSON('"foo"');
66+
verifyRawJSON('"\\u00bD"');
3267

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-
);
68+
verifyRawJSON(1);
69+
verifyRawJSON(-1);
70+
verifyRawJSON(-1.2);
4271

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-
);
72+
verifyRawJSON('-0');
73+
verifyRawJSON('1e0');
74+
verifyRawJSON('1E1');
75+
verifyRawJSON('1.23e+1');
76+
verifyRawJSON('1.23E-1');

test/built-ins/JSON/rawJSON/returns-expected-object.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)