diff --git a/test/built-ins/JSON/parse/15.12.2-0-1.js b/test/built-ins/JSON/parse/15.12.2-0-1.js deleted file mode 100644 index 2bb7779492..0000000000 --- a/test/built-ins/JSON/parse/15.12.2-0-1.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - This test should be run without any built-ins being added/augmented. - The name JSON must be bound to an object. - Section 15 says that every built-in Function object described in this - section � whether as a constructor, an ordinary function, or both � has - a length property whose value is an integer. Unless otherwise specified, - this value is equal to the largest number of named arguments shown in - the section headings for the function description, including optional - parameters. - This default applies to JSON.parse, and it must exist as a function - taking 2 parameters. -es5id: 15.12.2-0-1 -description: JSON.parse must exist as a function ----*/ - -var f = JSON.parse; - -assert.sameValue(typeof(f), "function", 'typeof(f)'); diff --git a/test/built-ins/JSON/parse/15.12.2-0-2.js b/test/built-ins/JSON/parse/15.12.2-0-2.js deleted file mode 100644 index fe9569381d..0000000000 --- a/test/built-ins/JSON/parse/15.12.2-0-2.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - This test should be run without any built-ins being added/augmented. - The name JSON must be bound to an object. - Section 15 says that every built-in Function object described in this - section � whether as a constructor, an ordinary function, or both � has - a length property whose value is an integer. Unless otherwise specified, - this value is equal to the largest number of named arguments shown in - the section headings for the function description, including optional - parameters. - This default applies to JSON.parse, and it must exist as a function - taking 2 parameters. -es5id: 15.12.2-0-2 -description: JSON.parse must exist as a function taking 2 parameters ----*/ - -var f = JSON.parse; - -assert.sameValue(typeof(f), "function", 'typeof(f)'); -assert.sameValue(f.length, 2, 'f.length'); diff --git a/test/built-ins/JSON/parse/15.12.2-0-3.js b/test/built-ins/JSON/parse/15.12.2-0-3.js deleted file mode 100644 index de7d3f825e..0000000000 --- a/test/built-ins/JSON/parse/15.12.2-0-3.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2012 Ecma International. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - This test should be run without any built-ins being added/augmented. - The initial value of [[Configurable]] on JSON is true. This means we - should be able to delete (8.6.2.5) the stringify and parse properties. -es5id: 15.12.2-0-3 -description: JSON.parse must be deletable (configurable) ----*/ - -var o = JSON; -var desc = Object.getOwnPropertyDescriptor(o, "parse"); - -assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/built-ins/JSON/parse/builtin.js b/test/built-ins/JSON/parse/builtin.js new file mode 100644 index 0000000000..70adc232c6 --- /dev/null +++ b/test/built-ins/JSON/parse/builtin.js @@ -0,0 +1,19 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Requirements for built-in functions, defined in introduction of chapter 17, + are satisfied. +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +var parse = JSON.parse; +assert(Object.isExtensible(parse)); +assert.sameValue(typeof parse, 'function'); +assert.sameValue(Object.prototype.toString.call(parse), '[object Function]'); +assert.sameValue(Object.getPrototypeOf(parse), Function.prototype); + +assert.sameValue(parse.hasOwnProperty('prototype'), false); +assert.sameValue(isConstructor(parse), false); diff --git a/test/built-ins/JSON/parse/length.js b/test/built-ins/JSON/parse/length.js new file mode 100644 index 0000000000..92efc36fb4 --- /dev/null +++ b/test/built-ins/JSON/parse/length.js @@ -0,0 +1,25 @@ +// Copyright (C) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + JSON.parse.length is 2. +info: | + JSON.parse ( text [ , reviver ] ) + + The "length" property of the parse function is 2. + + ECMAScript Standard Built-in Objects + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(JSON.parse, 'length', { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/JSON/parse/name.js b/test/built-ins/JSON/parse/name.js index 9ce452ef3c..46fb88ec93 100644 --- a/test/built-ins/JSON/parse/name.js +++ b/test/built-ins/JSON/parse/name.js @@ -2,6 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- +esid: sec-json.parse es6id: 24.3.1 description: > JSON.parse.name is "parse". @@ -19,8 +20,9 @@ info: | includes: [propertyHelper.js] ---*/ -assert.sameValue(JSON.parse.name, "parse"); - -verifyNotEnumerable(JSON.parse, "name"); -verifyNotWritable(JSON.parse, "name"); -verifyConfigurable(JSON.parse, "name"); +verifyProperty(JSON.parse, 'name', { + value: 'parse', + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/JSON/parse/prop-desc.js b/test/built-ins/JSON/parse/prop-desc.js new file mode 100644 index 0000000000..ce67eb8dab --- /dev/null +++ b/test/built-ins/JSON/parse/prop-desc.js @@ -0,0 +1,20 @@ +// Copyright (C) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Property descriptor of JSON.parse. +info: | + ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(JSON, 'parse', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/JSON/parse/text-negative-zero.js b/test/built-ins/JSON/parse/text-negative-zero.js new file mode 100644 index 0000000000..f9289a916b --- /dev/null +++ b/test/built-ins/JSON/parse/text-negative-zero.js @@ -0,0 +1,21 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Top-level negative zero surrounded by whitespace is parsed correctly. +info: | + JSON.parse ( text [ , reviver ] ) + + 1. Let JText be ? ToString(text). + 2. Parse JText interpreted as UTF-16 encoded Unicode points (6.1.4) as a JSON + text as specified in ECMA-404. Throw a SyntaxError exception if JText is not + a valid JSON text as defined in that specification. +---*/ + +assert.sameValue(JSON.parse('-0'), -0); +assert.sameValue(JSON.parse(' \n-0'), -0); +assert.sameValue(JSON.parse('-0 \t'), -0); +assert.sameValue(JSON.parse('\n\t -0\n '), -0); + +assert.sameValue(JSON.parse(-0), 0); diff --git a/test/built-ins/JSON/parse/text-non-string-primitive.js b/test/built-ins/JSON/parse/text-non-string-primitive.js new file mode 100644 index 0000000000..d0ce960e34 --- /dev/null +++ b/test/built-ins/JSON/parse/text-non-string-primitive.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Primitive values are coerced to strings and parsed. +info: | + JSON.parse ( text [ , reviver ] ) + + 1. Let JText be ? ToString(text). + 2. Parse JText interpreted as UTF-16 encoded Unicode points (6.1.4) as a JSON + text as specified in ECMA-404. Throw a SyntaxError exception if JText is not + a valid JSON text as defined in that specification. +features: [Symbol] +---*/ + +assert.throws(SyntaxError, function() { + JSON.parse(); +}); + +assert.throws(SyntaxError, function() { + JSON.parse(undefined); +}); + +assert.sameValue(JSON.parse(null), null); +assert.sameValue(JSON.parse(false), false); +assert.sameValue(JSON.parse(true), true); +assert.sameValue(JSON.parse(0), 0); +assert.sameValue(JSON.parse(3.14), 3.14); + +var sym = Symbol('desc'); +assert.throws(TypeError, function() { + JSON.parse(sym); +}); diff --git a/test/built-ins/JSON/parse/text-object-abrupt.js b/test/built-ins/JSON/parse/text-object-abrupt.js new file mode 100644 index 0000000000..8ede14f514 --- /dev/null +++ b/test/built-ins/JSON/parse/text-object-abrupt.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Abrupt completion from Get and Call in ToPrimitive. +info: | + JSON.parse ( text [ , reviver ] ) + + 1. Let JText be ? ToString(text). +---*/ + +assert.throws(Test262Error, function() { + JSON.parse({ + toString: null, + get valueOf() { + throw new Test262Error(); + }, + }); +}); + +assert.throws(Test262Error, function() { + JSON.parse({ + toString: function() { + throw new Test262Error(); + }, + }); +}); diff --git a/test/built-ins/JSON/parse/text-object.js b/test/built-ins/JSON/parse/text-object.js new file mode 100644 index 0000000000..d1dd305220 --- /dev/null +++ b/test/built-ins/JSON/parse/text-object.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-json.parse +description: > + Objects are coerced to strings using ToString. +info: | + JSON.parse ( text [ , reviver ] ) + + 1. Let JText be ? ToString(text). + 2. Parse JText interpreted as UTF-16 encoded Unicode points (6.1.4) as a JSON + text as specified in ECMA-404. Throw a SyntaxError exception if JText is not + a valid JSON text as defined in that specification. +---*/ + +var hint = JSON.parse({ + toString: function() { + return '"string"'; + }, + valueOf: function() { + return '"default_or_number"'; + }, +}); + +assert.sameValue(hint, 'string');