Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tc39/test262
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 54d32596b0fc7aff1c0013a354e2984d28d1e668
Choose a base ref
..
head repository: tc39/test262
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 42634c8788b83fcbd8a3cefffaca2fdf58ae0e23
Choose a head ref
4 changes: 2 additions & 2 deletions test/built-ins/Error/isError/bigints.js
Original file line number Diff line number Diff line change
@@ -10,5 +10,5 @@ features: [Error.isError, BigInt]

assert.sameValue(Error.isError(0n), false);
assert.sameValue(Error.isError(42n), false);
assert.sameValue(Error.isError(new BigInt(0)), false);
assert.sameValue(Error.isError(new BigInt(42)), false);
assert.sameValue(Error.isError(BigInt(0)), false);
assert.sameValue(Error.isError(BigInt(42)), false);
2 changes: 1 addition & 1 deletion test/built-ins/Error/isError/error-subclass.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ assert.sameValue(Error.isError(new MyURIError()), true);
if (typeof AggregateError !== 'undefined') {
class MyAggregateError extends AggregateError {}

assert.sameValue(Error.isError(new MyAggregateError()), true);
assert.sameValue(Error.isError(new MyAggregateError([])), true);
}

if (typeof SuppressedError !== 'undefined') {
2 changes: 1 addition & 1 deletion test/built-ins/Error/isError/errors-other-realm.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ assert.sameValue(Error.isError(new other.TypeError()), true);
assert.sameValue(Error.isError(new other.URIError()), true);

if (typeof AggregateError !== 'undefined') {
assert.sameValue(Error.isError(new other.AggregateError()), true);
assert.sameValue(Error.isError(new other.AggregateError([])), true);
}
if (typeof SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(new other.SuppressedError()), true);
2 changes: 1 addition & 1 deletion test/built-ins/Error/isError/errors.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ assert.sameValue(Error.isError(new TypeError()), true);
assert.sameValue(Error.isError(new URIError()), true);

if (typeof AggregateError !== 'undefined') {
assert.sameValue(Error.isError(new AggregateError()), true);
assert.sameValue(Error.isError(new AggregateError([])), true);
}
if (typeof SuppressedError !== 'undefined') {
assert.sameValue(Error.isError(new SuppressedError()), true);
2 changes: 1 addition & 1 deletion test/built-ins/Error/isError/symbols.js
Original file line number Diff line number Diff line change
@@ -8,4 +8,4 @@ description: >
features: [Error.isError, Symbol]
---*/

assert.sameValue(Error.isError(new Symbol()), false);
assert.sameValue(Error.isError(Symbol()), false);
25 changes: 25 additions & 0 deletions test/built-ins/JSON/isRawJSON/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-json.israwjson
description: Basic functionality of JSON.isRawJSON()
info: |
JSON.isRawJSON ( O )
1. If Type(O) is Object and O has an [[IsRawJSON]] internal slot, return true.
2. Return false.
features: [json-parse-with-source]
---*/

const values = [1, 1.1, null, false, true, '123'];
for (const value of values) {
assert(!JSON.isRawJSON(value));
assert(JSON.isRawJSON(JSON.rawJSON(value)));
}
assert(!JSON.isRawJSON(undefined));
assert(!JSON.isRawJSON(Symbol('123')));
assert(!JSON.isRawJSON([]));
assert(!JSON.isRawJSON({}));
assert(!JSON.isRawJSON({ rawJSON: '123' }));
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-json.parse
description: >
JSON.parse reviver is called with the correct arguments when the object is
modified
includes: [compareArray.js]
features: [json-parse-with-source]
---*/

// Test Array append
{
let log = [];
const o = JSON.parse('[1,[]]', function reviver(k, v, { source }) {
log.push(`key: |${k}| value: ${JSON.stringify(v)} source: |${source}|`);
if (v === 1) {
this[1].push('barf');
}
return this[k];
});
assert.compareArray(log, [
'key: |0| value: 1 source: |1|',
'key: |0| value: "barf" source: |undefined|',
'key: |1| value: ["barf"] source: |undefined|',
'key: || value: [1,["barf"]] source: |undefined|',
]);
}

// Test Object add property
{
let log = [];
const o = JSON.parse('{"p":1,"q":{}}', function (k, v, { source }) {
log.push(`key: |${k}| value: ${JSON.stringify(v)} source: |${source}|`);
if (v === 1) {
this.q.added = 'barf';
}
return this[k];
});
assert.compareArray(log, [
'key: |p| value: 1 source: |1|',
'key: |added| value: "barf" source: |undefined|',
'key: |q| value: {"added":"barf"} source: |undefined|',
'key: || value: {"p":1,"q":{"added":"barf"}} source: |undefined|',
]);
}
58 changes: 58 additions & 0 deletions test/built-ins/JSON/parse/reviver-context-source-array-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (C) 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-json.parse
description: >
Context argument and its source property behave as expected when parsing an
ArrayLiteral JSON string
includes: [compareArray.js, propertyHelper.js]
features: [json-parse-with-source]
---*/

function assertOnlyOwnProperties(object, props, message) {
assert.compareArray(Object.getOwnPropertyNames(object), props, `${message}: object should have no other properties than expected`);
assert.compareArray(Object.getOwnPropertySymbols(object), [], `${message}: object should have no own symbol properties`);
}

function reviverWithExpectedSources(expectedSources) {
let i = 0;
return function reviver(key, value, context) {
assert.sameValue(typeof context, "object", "context should be an object");
assert.sameValue(Object.getPrototypeOf(context), Object.prototype, "context should be a plain object");
if (expectedSources[i] !== undefined) {
assertOnlyOwnProperties(context, ["source"],
"the JSON value is a primitve value, its context should only have a source property");
verifyProperty(context, "source", {
value: expectedSources[i++],
configurable: true,
enumerable: true,
writable: true,
}, { restore: true });
} else {
assertOnlyOwnProperties(context, [],
"the JSON value is an Array or Object, its context should have no property");
i++;
}
return value;
};
}

assert.compareArray(JSON.parse('[1.0]', reviverWithExpectedSources(['1.0'])), [1]);
assert.compareArray(
JSON.parse('[1.1]', reviverWithExpectedSources(['1.1'])),
[1.1]
);
assert.compareArray(JSON.parse('[]', reviverWithExpectedSources([])), []);

const longArray = JSON.parse(
'[1, "2", true, null, {"x": 1, "y": 1}]',
reviverWithExpectedSources(['1', '"2"', 'true', 'null', '1', '1'])
);
assert.sameValue(longArray[0], 1, "array, element 0");
assert.sameValue(longArray[1], "2", "array, element 1");
assert.sameValue(longArray[2], true, "array, element 2");
assert.sameValue(longArray[3], null, "array, element 3");
assertOnlyOwnProperties(longArray[4], ["x", "y"], "array, element 5");
assert.sameValue(longArray[4].x, 1, "array, element 5, prop x");
assert.sameValue(longArray[4].y, 1, "array, element 5, prop y");
73 changes: 73 additions & 0 deletions test/built-ins/JSON/parse/reviver-context-source-object-literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (C) 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-json.parse
description: >
Context argument and its source property behave as expected when parsing an
ObjectLiteral JSON string
includes: [compareArray.js, propertyHelper.js]
features: [json-parse-with-source]
---*/

function assertOnlyOwnProperties(object, props, message) {
assert.compareArray(Object.getOwnPropertyNames(object), props, `${message}: object should have no other properties than expected`);
assert.compareArray(Object.getOwnPropertySymbols(object), [], `${message}: object should have no own symbol properties`);
}

function reviverWithExpectedSources(expectedSources) {
let i = 0;
return function reviver(key, value, context) {
assert.sameValue(typeof context, "object", "context should be an object");
assert.sameValue(Object.getPrototypeOf(context), Object.prototype, "context should be a plain object");
if (expectedSources[i] !== undefined) {
assertOnlyOwnProperties(context, ["source"],
"the JSON value is a primitve value, its context should only have a source property");
verifyProperty(context, "source", {
value: expectedSources[i++],
configurable: true,
enumerable: true,
writable: true,
}, { restore: true });
} else {
assertOnlyOwnProperties(context, [],
"the JSON value is an Array or Object, its context should have no property");
i++;
}
return value;
};
}

assertOnlyOwnProperties(
JSON.parse('{}', reviverWithExpectedSources([])),
[],
"empty object"
);

const singleProp = JSON.parse('{"42":37}', reviverWithExpectedSources(['37']));
assertOnlyOwnProperties(singleProp, ["42"], "single numeric property key");
assert.sameValue(singleProp[42], 37, "value of single numeric property key");

const multipleProps = JSON.parse('{"x": 1, "y": 2}', reviverWithExpectedSources(['1', '2']));
assertOnlyOwnProperties(multipleProps, ["x", "y"], "multiple properties");
assert.sameValue(multipleProps.x, 1, "multiple properties, value of x");
assert.sameValue(multipleProps.y, 2, "multiple properties, value of y");

// undefined means the json value is JSObject or JSArray and the passed
// context to the reviver function has no source property.
const arrayProps = JSON.parse(
'{"x": [1,2], "y": [2,3]}',
reviverWithExpectedSources(['1', '2', undefined, '2', '3', undefined])
);
assertOnlyOwnProperties(arrayProps, ["x", "y"], "array-valued properties");
assert.compareArray(arrayProps.x, [1, 2], "array-valued properties, value of x");
assert.compareArray(arrayProps.y, [2, 3], "array-valued properties, value of y");

const objectProps = JSON.parse(
'{"x": {"x": 1, "y": 2}}',
reviverWithExpectedSources(['1', '2', undefined, undefined])
);
assertOnlyOwnProperties(objectProps, ["x"], "object-valued properties");
assertOnlyOwnProperties(objectProps.x, ["x", "y"], "object-valued properties, value of x");
assert.sameValue(objectProps.x.x, 1, "object-valued properties, value of x.x");
assert.sameValue(objectProps.x.y, 2, "object-valued properties, value of x.y");
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (C) 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-json.parse
description: >
Context argument and its source property behave as expected when parsing a
NumericLiteral, NullLiteral, BoolLiteral, or StringLiteral JSON string
includes: [compareArray.js, propertyHelper.js]
features: [json-parse-with-source]
---*/

function assertOnlyOwnProperties(object, props, message) {
assert.compareArray(Object.getOwnPropertyNames(object), props, `${message}: object should have no other properties than expected`);
assert.compareArray(Object.getOwnPropertySymbols(object), [], `${message}: object should have no own symbol properties`);
}

function reviverWithExpectedSources(expectedSources) {
let i = 0;
return function reviver(key, value, context) {
assert.sameValue(typeof context, "object", "context should be an object");
assert.sameValue(Object.getPrototypeOf(context), Object.prototype, "context should be a plain object");
if (expectedSources[i] !== undefined) {
assertOnlyOwnProperties(context, ["source"],
"the JSON value is a primitve value, its context should only have a source property");
verifyProperty(context, "source", {
value: expectedSources[i++],
configurable: true,
enumerable: true,
writable: true,
}, { restore: true });
} else {
assertOnlyOwnProperties(context, [],
"the JSON value is an Array or Object, its context should have no property");
i++;
}
return value;
};
}

assert.sameValue(1, JSON.parse('1', reviverWithExpectedSources(['1'])));
assert.sameValue(1.1, JSON.parse('1.1', reviverWithExpectedSources(['1.1'])));
assert.sameValue(-1, JSON.parse('-1', reviverWithExpectedSources(['-1'])));
assert.sameValue(
-1.1,
JSON.parse('-1.1', reviverWithExpectedSources(['-1.1']))
);
assert.sameValue(
11,
JSON.parse('1.1e1', reviverWithExpectedSources(['1.1e1']))
);
assert.sameValue(
11,
JSON.parse('1.1e+1', reviverWithExpectedSources(['1.1e+1']))
);
assert.sameValue(
0.11,
JSON.parse('1.1e-1', reviverWithExpectedSources(['1.1e-1']))
);
assert.sameValue(
11,
JSON.parse('1.1E1', reviverWithExpectedSources(['1.1E1']))
);
assert.sameValue(
11,
JSON.parse('1.1E+1', reviverWithExpectedSources(['1.1E+1']))
);
assert.sameValue(
0.11,
JSON.parse('1.1E-1', reviverWithExpectedSources(['1.1E-1']))
);

// Test NullLiteral, BoolLiteral, StringLiteral
assert.sameValue(
JSON.parse('null', reviverWithExpectedSources(['null'])),
null
);
assert.sameValue(
JSON.parse('true', reviverWithExpectedSources(['true'])),
true
);
assert.sameValue(
JSON.parse('false', reviverWithExpectedSources(['false'])),
false
);
assert.sameValue(
JSON.parse('"foo"', reviverWithExpectedSources(['"foo"'])),
"foo"
);
Loading