diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/test262/language/expressions/prefix-increment | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/expressions/prefix-increment')
34 files changed, 1065 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/prefix-increment/11.4.4-2-3-s.js b/js/src/tests/test262/language/expressions/prefix-increment/11.4.4-2-3-s.js new file mode 100644 index 0000000000..8c1f4075f8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/11.4.4-2-3-s.js @@ -0,0 +1,16 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 11.4.4-2-3-s +description: SyntaxError is not thrown for ++arguments[...] +---*/ + +function testcase() { + arguments[1] = 7; + ++arguments[1]; + assert.sameValue(arguments[1], 8, 'arguments[1]'); + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T1.js new file mode 100644 index 0000000000..433a59f55e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T1.js @@ -0,0 +1,41 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x uses GetValue and PutValue +es5id: 11.4.4_A2.1_T1 +description: Type(x) is Reference and GetBase(x) is not null +---*/ + +//CHECK#1 +var x = 1; +if (++x !== 1 + 1) { + $ERROR('#1: var x = 1; ++x === 1 + 1. Actual: ' + (++x)); +} else { + if (x !== 1 + 1) { + $ERROR('#1: var x = 1; ++x; x === 1 + 1. Actual: ' + (x)); + } +} + +//CHECK#2 +this.x = 1; +if (++this.x !== 1 + 1) { + $ERROR('#2: this.x = 1; ++this.x === 1 + 1. Actual: ' + (++this.x)); +} else { + if (this.x !== 1 + 1) { + $ERROR('#2: this.x = 1; ++this.x; this.x === 1 + 1. Actual: ' + (this.x)); + } +} + +//CHECK#3 +var object = new Object(); +object.prop = 1; +if (++object.prop !== 1 + 1) { + $ERROR('#3: var object = new Object(); object.prop = 1; ++object.prop === 1 + 1. Actual: ' + (++object.prop)); +} else { + if (this.x !== 1 + 1) { + $ERROR('#3: var object = new Object(); object.prop = 1; ++object.prop; object.prop === 1 + 1. Actual: ' + (object.prop)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T2.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T2.js new file mode 100644 index 0000000000..3ffda30931 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x uses GetValue and PutValue +es5id: 11.4.4_A2.1_T2 +description: If GetBase(x) is null, throw ReferenceError +---*/ + +//CHECK#1 +try { + ++x; + $ERROR('#1.1: ++x throw ReferenceError. Actual: ' + (++x)); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + $ERROR('#1.2: ++x throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.2_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.2_T1.js new file mode 100644 index 0000000000..40e5aacae8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A2.2_T1.js @@ -0,0 +1,104 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x uses [[Default Value]] +es5id: 11.4.4_A2.2_T1 +description: If Type(value) is Object, evaluate ToPrimitive(value, Number) +---*/ + +//CHECK#1 +var object = {valueOf: function() {return 1}}; +if (++object !== 1 + 1) { + $ERROR('#1: var object = {valueOf: function() {return 1}}; ++object === 1 + 1. Actual: ' + (++object)); +} else { + if (object !== 1 + 1) { + $ERROR('#1: var object = {valueOf: function() {return 1}}; ++object; object === 1 + 1. Actual: ' + (object)); + } +} + +//CHECK#2 +var object = {valueOf: function() {return 1}, toString: function() {return 0}}; +if (++object !== 1 + 1) { + $ERROR('#2: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; ++object === 1 + 1. Actual: ' + (++object)); +} else { + if (object !== 1 + 1) { + $ERROR('#2: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; ++object; object === 1 + 1. Actual: ' + (object)); + } +} + +//CHECK#3 +var object = {valueOf: function() {return 1}, toString: function() {return {}}}; +if (++object !== 1 + 1) { + $ERROR('#3: var object = {valueOf: function() {return 1}, toString: function() {return {}}}; ++object === 1 + 1. Actual: ' + (++object)); +} else { + if (object !== 1 + 1) { + $ERROR('#3: var object = {valueOf: function() {return 1}, toString: function() {return {}}}; ++object; object === 1 + 1. Actual: ' + (object)); + } +} + +//CHECK#4 +try { + var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; + if (++object !== 1 + 1) { + $ERROR('#4.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; ++object === 1 + 1. Actual: ' + (++object)); + } else { + if (object !== 1 + 1) { + $ERROR('#4.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; ++object; object === 1 + 1. Actual: ' + (object)); + } + } +} +catch (e) { + if (e === "error") { + $ERROR('#4.2: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; ++object not throw "error"'); + } else { + $ERROR('#4.3: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; ++object not throw Error. Actual: ' + (e)); + } +} + +//CHECK#5 +var object = {toString: function() {return 1}}; +if (++object !== 1 + 1) { + $ERROR('#5.1: var object = {toString: function() {return 1}}; ++object === 1 + 1. Actual: ' + (++object)); +} else { + if (object !== 1 + 1) { + $ERROR('#5.2: var object = {toString: function() {return 1}}; ++object; object === 1 + 1. Actual: ' + (object)); + } +} + + +//CHECK#6 +var object = {valueOf: function() {return {}}, toString: function() {return 1}} +if (++object !== 1 + 1) { + $ERROR('#6.1: var object = {valueOf: function() {return {}}, toString: function() {return 1}}; ++object === 1 + 1. Actual: ' + (++object)); +} else { + if (object !== 1 + 1) { + $ERROR('#6.2: var object = {valueOf: function() {return {}}, toString: function() {return 1}}; ++object; object === 1 + 1. Actual: ' + (object)); + } +} + +//CHECK#7 +try { + var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; + ++object; + $ERROR('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; ++object throw "error". Actual: ' + (++object)); +} +catch (e) { + if (e !== "error") { + $ERROR('#7.2: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; ++object throw "error". Actual: ' + (e)); + } +} + +//CHECK#8 +try { + var object = {valueOf: function() {return {}}, toString: function() {return {}}}; + ++object; + $ERROR('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; ++object throw TypeError. Actual: ' + (++object)); +} +catch (e) { + if ((e instanceof TypeError) !== true) { + $ERROR('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; ++object throw TypeError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T1.js new file mode 100644 index 0000000000..d99f98b2d7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T1.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns x = ToNumber(x) + 1 +es5id: 11.4.4_A3_T1 +description: Type(x) is boolean primitive or Boolean object +---*/ + +//CHECK#1 +var x = false; +++x; +if (x !== 0 + 1) { + $ERROR('#1: var x = false; ++x; x === 0 + 1. Actual: ' + (x)); +} + +//CHECK#2 +var x = new Boolean(true); +++x; +if (x !== 1 + 1) { + $ERROR('#2: var x = new Boolean(true); ++x; x === 1 + 1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T2.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T2.js new file mode 100644 index 0000000000..939a8d93e2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T2.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns x = ToNumber(x) + 1 +es5id: 11.4.4_A3_T2 +description: Type(x) is number primitive or Number object +---*/ + +//CHECK#1 +var x = 0.1; +++x; +if (x !== 0.1 + 1) { + $ERROR('#1: var x = 0.1; ++x; x === 0.1 + 1. Actual: ' + (x)); +} + +//CHECK#2 +var x = new Number(-1.1); +++x; +if (x !== -1.1 + 1) { + $ERROR('#2: var x = new Number(-1.1); ++x; x === -1.1 + 1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T3.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T3.js new file mode 100644 index 0000000000..1509e61cbf --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T3.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns x = ToNumber(x) + 1 +es5id: 11.4.4_A3_T3 +description: Type(x) is string primitive or String object +---*/ + +//CHECK#1 +var x = "1"; +++x; +if (x !== 1 + 1) { + $ERROR('#1: var x = "1"; ++x; x === 1 + 1. Actual: ' + (x)); +} + +//CHECK#2 +var x = "x"; +++x; +if (isNaN(x) !== true) { + $ERROR('#2: var x = "x"; ++x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#3 +var x = new Number("-1"); +++x; +if (x !== -1 + 1) { + $ERROR('#3: var x = new String("-1"); ++x; x === -1 + 1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T4.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T4.js new file mode 100644 index 0000000000..60db2cc38c --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T4.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns x = ToNumber(x) + 1 +es5id: 11.4.4_A3_T4 +description: Type(x) is undefined or null +---*/ + +//CHECK#1 +var x; +++x; +if (isNaN(x) !== true) { + $ERROR('#1: var x; ++x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#2 +var x = null; +++x; +if (x !== 1) { + $ERROR('#2: var x = null; ++x; x === 1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T5.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T5.js new file mode 100644 index 0000000000..c243d0f96b --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A3_T5.js @@ -0,0 +1,24 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns x = ToNumber(x) + 1 +es5id: 11.4.4_A3_T5 +description: Type(x) is Object object or Function object +---*/ + +//CHECK#1 +var x = {}; +++x; +if (isNaN(x) !== true) { + $ERROR('#1: var x = {}; ++x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#2 +var x = function(){return 1}; +++x; +if (isNaN(x) !== true) { + $ERROR('#2: var x = function(){return 1}; ++x; x === Not-a-Number. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T1.js new file mode 100644 index 0000000000..600910fffb --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T1.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns ToNumber(x) + 1 +es5id: 11.4.4_A4_T1 +description: Type(x) is boolean primitive or Boolean object +---*/ + +//CHECK#1 +var x = false; +if (++x !== 0 + 1) { + $ERROR('#1: var x = false; ++x === 0 + 1. Actual: ' + (++x)); +} + +//CHECK#2 +var x = new Boolean(true); +if (++x !== 1 + 1) { + $ERROR('#2: var x = new Boolean(true); ++x === 1 + 1. Actual: ' + (++x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T2.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T2.js new file mode 100644 index 0000000000..f27059d9a4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T2.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns ToNumber(x) + 1 +es5id: 11.4.4_A4_T2 +description: Type(x) is number primitive or Number object +---*/ + +//CHECK#1 +var x = 0.1; +if (++x !== 0.1 + 1) { + $ERROR('#1: var x = 0.1; ++x === 0.1 + 1. Actual: ' + (++x)); +} + +//CHECK#2 +var x = new Number(-1.1); +if (++x !== -1.1 + 1) { + $ERROR('#2: var x = new Number(-1.1); ++x === -1.1 + 1. Actual: ' + (++x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T3.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T3.js new file mode 100644 index 0000000000..dc10d6945e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T3.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns ToNumber(x) + 1 +es5id: 11.4.4_A4_T3 +description: Type(x) is string primitive or String object +---*/ + +//CHECK#1 +var x = "1"; +if (++x !== 1 + 1) { + $ERROR('#1: var x = "1"; ++x === 1 + 1. Actual: ' + (++x)); +} + +//CHECK#2 +var x = "x"; +if (isNaN(++x) !== true) { + $ERROR('#2: var x = "x"; ++x === Not-a-Number. Actual: ' + (++x)); +} + +//CHECK#3 +var x = new String("-1"); +if (++x !== -1 + 1) { + $ERROR('#3: var x = new String("-1"); ++x === -1 + 1. Actual: ' + (++x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T4.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T4.js new file mode 100644 index 0000000000..bf3bbce1b9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T4.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns ToNumber(x) + 1 +es5id: 11.4.4_A4_T4 +description: Type(x) is undefined or null +---*/ + +//CHECK#1 +var x; +if (isNaN(++x) !== true) { + $ERROR('#1: var x; ++x === Not-a-Number. Actual: ' + (++x)); +} + +//CHECK#2 +var x = null; +if (++x !== 1) { + $ERROR('#2: var x = null; ++x === 1. Actual: ' + (++x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T5.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T5.js new file mode 100644 index 0000000000..ab364393f1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A4_T5.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x returns ToNumber(x) + 1 +es5id: 11.4.4_A4_T5 +description: Type(x) is Object object or Function object +---*/ + +//CHECK#1 +var x = {}; +if (isNaN(++x) !== true) { + $ERROR('#1: var x = {}; ++x === Not-a-Number. Actual: ' + (++x)); +} + +//CHECK#2 +var x = function(){return 1}; +if (isNaN(++x) !== true) { + $ERROR('#2: var x = function(){return 1}; ++x === Not-a-Number. Actual: ' + (++x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T1.js new file mode 100644 index 0000000000..3297b27a7f --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T1.js @@ -0,0 +1,38 @@ +// Copyright (C) 2014 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x calls PutValue(lhs, newValue) +es5id: S11.4.4_A5_T1 +description: > + Evaluating LeftHandSideExpression lhs returns Reference type; Reference + base value is an environment record and environment record kind is + object environment record. PutValue(lhs, newValue) uses the initially + created Reference even if the environment binding is no longer present. + Binding in surrounding function environment record is not changed. +flags: [noStrict] +---*/ + +function testFunction() { + var x = 0; + var scope = { + get x() { + delete this.x; + return 2; + } + }; + + with (scope) { + ++x; + } + + if (scope.x !== 3) { + $ERROR('#1: scope.x === 3. Actual: ' + (scope.x)); + } + if (x !== 0) { + $ERROR('#2: x === 0. Actual: ' + (x)); + } +} +testFunction(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T2.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T2.js new file mode 100644 index 0000000000..aeda7d8662 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T2.js @@ -0,0 +1,35 @@ +// Copyright (C) 2014 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x calls PutValue(lhs, newValue) +es5id: S11.4.4_A5_T2 +description: > + Evaluating LeftHandSideExpression lhs returns Reference type; Reference + base value is an environment record and environment record kind is + object environment record. PutValue(lhs, newValue) uses the initially + created Reference even if the environment binding is no longer present. + Binding in surrounding global environment record is not changed. +flags: [noStrict] +---*/ + +var x = 0; +var scope = { + get x() { + delete this.x; + return 2; + } +}; + +with (scope) { + ++x; +} + +if (scope.x !== 3) { + $ERROR('#1: scope.x === 3. Actual: ' + (scope.x)); +} +if (x !== 0) { + $ERROR('#2: x === 0. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T3.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T3.js new file mode 100644 index 0000000000..914873496e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A5_T3.js @@ -0,0 +1,39 @@ +// Copyright (C) 2014 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x calls PutValue(lhs, newValue) +es5id: S11.4.4_A5_T3 +description: > + Evaluating LeftHandSideExpression lhs returns Reference type; Reference + base value is an environment record and environment record kind is + object environment record. PutValue(lhs, newValue) uses the initially + created Reference even if the environment binding is no longer present. + Binding in surrounding object environment record is not changed. +flags: [noStrict] +---*/ + +var outerScope = { + x: 0 +}; +var innerScope = { + get x() { + delete this.x; + return 2; + } +}; + +with (outerScope) { + with (innerScope) { + ++x; + } +} + +if (innerScope.x !== 3) { + $ERROR('#1: innerScope.x === 3. Actual: ' + (innerScope.x)); +} +if (outerScope.x !== 0) { + $ERROR('#2: outerScope.x === 0. Actual: ' + (outerScope.x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T1.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T1.js new file mode 100644 index 0000000000..d7cb2b1a02 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T1.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x evaluates its reference expression once. +description: > + The operand expression is evaluated exactly once. Operand expression is + MemberExpression: base[prop]. base is the null value. +---*/ + +function DummyError() { } + +assert.throws(DummyError, function() { + var base = null; + var prop = function() { + throw new DummyError(); + }; + + ++base[prop()]; +}); + +assert.throws(TypeError, function() { + var base = null; + var prop = { + toString: function() { + $ERROR("property key evaluated"); + } + }; + + ++base[prop]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T2.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T2.js new file mode 100644 index 0000000000..2a492245e0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T2.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x evaluates its reference expression once. +description: > + The operand expression is evaluated exactly once. Operand expression is + MemberExpression: base[prop]. base is the undefined value. +---*/ + +function DummyError() { } + +assert.throws(DummyError, function() { + var base = undefined; + var prop = function() { + throw new DummyError(); + }; + + ++base[prop()]; +}); + +assert.throws(TypeError, function() { + var base = undefined; + var prop = { + toString: function() { + $ERROR("property key evaluated"); + } + }; + + ++base[prop]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T3.js b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T3.js new file mode 100644 index 0000000000..b3e9a874c7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/S11.4.4_A6_T3.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator ++x evaluates its reference expression once. +description: > + The operand expression is evaluated exactly once. Operand expression is + MemberExpression: base[prop]. ToPropertyKey(prop) is not called multiple + times. +---*/ + +var propKeyEvaluated = false; +var base = {}; +var prop = { + toString: function() { + assert(!propKeyEvaluated); + propKeyEvaluated = true; + return 1; + } +}; + +++base[prop]; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/arguments-nostrict.js b/js/src/tests/test262/language/expressions/prefix-increment/arguments-nostrict.js new file mode 100644 index 0000000000..d9af8d7ad5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/arguments-nostrict.js @@ -0,0 +1,27 @@ +// Copyright (c) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-update-expressions +description: > + In non-strict code, "++arguments" does not produce an early error. +info: | + sec-identifiers-static-semantics-assignmenttargettype + + 1. If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return strict. + 2. Return simple. + + sec-update-expressions-static-semantics-early-errors + + UpdateExpression ++ UnaryExpression + + It is an early Reference Error if AssignmentTargetType of UnaryExpression is invalid. + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. +flags: [noStrict] +---*/ + +if (false) { + ++arguments; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/arguments-strict.js b/js/src/tests/test262/language/expressions/prefix-increment/arguments-strict.js new file mode 100644 index 0000000000..c96cdfa298 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/arguments-strict.js @@ -0,0 +1,28 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-update-expressions +description: > + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. (arguments) +info: | + sec-identifiers-static-semantics-assignmenttargettype + + If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return strict. + + sec-update-expressions-static-semantics-early-errors + + UpdateExpression: ++ UnaryExpression + + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +++arguments; diff --git a/js/src/tests/test262/language/expressions/prefix-increment/bigint.js b/js/src/tests/test262/language/expressions/prefix-increment/bigint.js new file mode 100644 index 0000000000..a6cd9dcbde --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/bigint.js @@ -0,0 +1,64 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Prefix increment for references to BigInt values +esid: sec-prefix-increment-operator-runtime-semantics-evaluation +info: | + 1. Let expr be the result of evaluating UnaryExpression. + 2. Let oldValue be ? ToNumeric(? GetValue(expr)). + 3. Let newValue be ? Type(oldvalue)::add(oldValue, Type(oldValue)::unit). + 4. Perform ? PutValue(expr, newValue). + 5. Return newValue. +features: [BigInt] +---*/ + +var x = 0n; +assert.sameValue(++x, 1n, "var x = 0n; ++x === 1n"); +assert.sameValue(x, 1n, "var x = 0n; ++x; x === 1n"); + +var x = -1n; +assert.sameValue(++x, 0n, "var x = -1n; ++x === 0n"); +assert.sameValue(x, 0n, "var x = -1n; ++x; x === 0n"); + +var x = 123456n; +assert.sameValue(++x, 123457n, "var x = 123456n; ++x === 123457n"); +assert.sameValue(x, 123457n, "var x = 123456n; ++x; x === 123457n"); + +var x = -123457n; +assert.sameValue(++x, -123456n, "var x = -123457n; ++x === -123456n"); +assert.sameValue(x, -123456n, "var x = -123457n; ++x; x === -123456n"); + +var x = 0x1fffffffffffff00n; +assert.sameValue(++x, 0x1fffffffffffff01n, "var x = 0x1fffffffffffff00n; ++x === 0x1fffffffffffff01n"); +assert.sameValue(x, 0x1fffffffffffff01n, "var x = 0x1fffffffffffff00n; ++x; x === 0x1fffffffffffff01n"); + +var x = -0x1fffffffffffff01n; +assert.sameValue(++x, -0x1fffffffffffff00n, "var x = -0x1fffffffffffff01n; ++x === -0x1fffffffffffff00n"); +assert.sameValue(x, -0x1fffffffffffff00n, "var x = -0x1fffffffffffff01n; ++x; x === -0x1fffffffffffff00n"); + +var x = {y:0n}; +assert.sameValue(++x.y, 1n, "var x = {y:0n}; ++x.y === 1n"); +assert.sameValue(x.y, 1n, "var x = {y:0n}; ++x.y; x.y === 1n"); + +var x = {y:{z:0n}}; +assert.sameValue(++x.y.z, 1n, "var x = {y:{z:0n}}; ++x.y.z === 1n"); +assert.sameValue(x.y.z, 1n, "var x = {y:{z:0n}}; ++x.y.z; x.y.z === 1n"); + +var x = [0n]; +assert.sameValue(++x[0], 1n, "var x = [0n]; ++x[0] === 1n"); +assert.sameValue(x[0], 1n, "var x = [0n]; ++x[0]; x[0] === 1n"); + +var x = [null, [null, null, 0n]]; +assert.sameValue(++x[1][2], 1n, "var x = [null, [null, null, 0n]]; ++x[1][2] === 1n"); +assert.sameValue(x[1][2], 1n, "var x = [null, [null, null, 0n]]; ++x[1][2]; x[1][2] === 1n"); + +var x = {y:[0n]}; +assert.sameValue(++x.y[0], 1n, "var x = {y:[0n]}; ++x.y[0] === 1n"); +assert.sameValue(x.y[0], 1n, "var x = {y:[0n]}; ++x.y[0]; x.y[0] === 1n"); + +var x = [{z:0n}]; +assert.sameValue(++x[0].z, 1n, "var x = [{z:0n}]; ++x[0].z === 1n"); +assert.sameValue(x[0].z, 1n, "var x = [{z:0n}]; ++x[0].z; x[0].z === 1n"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/browser.js b/js/src/tests/test262/language/expressions/prefix-increment/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/browser.js diff --git a/js/src/tests/test262/language/expressions/prefix-increment/eval-nostrict.js b/js/src/tests/test262/language/expressions/prefix-increment/eval-nostrict.js new file mode 100644 index 0000000000..8bebe8850e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/eval-nostrict.js @@ -0,0 +1,25 @@ +// Copyright (c) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-update-expressions +description: > + In non-strict code, "++eval" does not produce an early error. +info: | + sec-identifiers-static-semantics-assignmenttargettype + + 1. If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return strict. + 2. Return simple. + + sec-update-expressions-static-semantics-early-errors + + UpdateExpression ++ UnaryExpression + + It is an early Reference Error if AssignmentTargetType of UnaryExpression is invalid. + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. +flags: [noStrict] +---*/ + +++eval; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/eval-strict.js b/js/src/tests/test262/language/expressions/prefix-increment/eval-strict.js new file mode 100644 index 0000000000..21498be432 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/eval-strict.js @@ -0,0 +1,29 @@ +// |reftest| error:SyntaxError +'use strict'; +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-update-expressions +description: > + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. (eval) +info: | + sec-identifiers-static-semantics-assignmenttargettype + + If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return strict. + + sec-update-expressions-static-semantics-early-errors + + UpdateExpression: ++ UnaryExpression + + It is an early Syntax Error if AssignmentTargetType of UnaryExpression is strict. + +flags: [onlyStrict] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +++eval; diff --git a/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue--1.js b/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue--1.js new file mode 100644 index 0000000000..96e6ebb9a1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue--1.js @@ -0,0 +1,41 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-setmutablebinding-n-v-s +description: > + Operator ++x calls PutValue(lhs, newValue) (formerly S11.4.4_A5_T5) +info: | + The concrete Environment Record method SetMutableBinding for object Environment + Records attempts to set the value of the Environment Record's associated binding + object's property whose name is the value of the argument N to the value of argument V. + A property named N normally already exists but if it does not or is not currently writable, + error handling is determined by the value of the Boolean argument S. + + Let stillExists be ? HasProperty(bindings, N). + If stillExists is false and S is true, throw a ReferenceError exception. +flags: [noStrict] +---*/ +var count = 0; +Object.defineProperty(this, "x", { + configurable: true, + get: function() { + delete this.x; + return 2; + } +}); + +(function() { + "use strict"; + assert.throws(ReferenceError, () => { + count++; + ++x; + count++; + }); + count++; +})(); + +assert.sameValue(count, 2); +assert(!('x' in this)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue-.js b/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue-.js new file mode 100644 index 0000000000..8825b4563e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/operator-prefix-increment-x-calls-putvalue-lhs-newvalue-.js @@ -0,0 +1,42 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-setmutablebinding-n-v-s +description: > + Operator ++x calls PutValue(lhs, newValue) (formerly S11.4.4_A5_T4) +info: | + The concrete Environment Record method SetMutableBinding for object Environment + Records attempts to set the value of the Environment Record's associated binding + object's property whose name is the value of the argument N to the value of argument V. + A property named N normally already exists but if it does not or is not currently writable, + error handling is determined by the value of the Boolean argument S. + + Let stillExists be ? HasProperty(bindings, N). + If stillExists is false and S is true, throw a ReferenceError exception. +flags: [noStrict] +---*/ +var count = 0; +var scope = { + get x() { + delete this.x; + return 2; + } +}; + +with (scope) { + (function() { + "use strict"; + assert.throws(ReferenceError, () => { + count++; + ++x; + count++; + }); + count++; + })(); +} + +assert.sameValue(count, 2); +assert(!('x' in scope)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/shell.js b/js/src/tests/test262/language/expressions/prefix-increment/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/shell.js diff --git a/js/src/tests/test262/language/expressions/prefix-increment/target-cover-id.js b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-id.js new file mode 100644 index 0000000000..df73600774 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-id.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-unary-operators-static-semantics-early-errors +es6id: 12.5.1 +es5id: 11.1.6_A3_T5 +description: Applied to a "covered" IdentifierReference +info: | + UnaryExpression : + ++ UnaryExpression + -- UnaryExpression + + - It is an early Reference Error if IsValidSimpleAssignmentTarget of + UnaryExpression is false. + + Static Semantics: IsValidSimpleAssignmentTarget + + IdentifierReference : Identifier + + 1. If this IdentifierReference is contained in strict mode code and + StringValue of Identifier is "eval" or "arguments", return false. + 2. Return true. +---*/ + +var y = 1; + +++(y); + +assert.sameValue(y, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-increment/target-cover-newtarget.js b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-newtarget.js new file mode 100644 index 0000000000..cd99f262d0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-newtarget.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-update-expressions-static-semantics-early-errors +description: Applied to a "covered" new.target +info: | + UnaryExpression : + ++ UnaryExpression + -- UnaryExpression + + - It is an early Syntax Error if IsValidSimpleAssignmentTarget of + UnaryExpression is invalid or strict. + + 12.3.1.6 Static Semantics: AssignmentTargetType + + NewTarget: + + new.target + + 1. Return invalid. +negative: + phase: parse + type: SyntaxError +features: [new.target] +---*/ + +$DONOTEVALUATE(); + +function f() { + ++(new.target); +} diff --git a/js/src/tests/test262/language/expressions/prefix-increment/target-cover-yieldexpr.js b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-yieldexpr.js new file mode 100644 index 0000000000..b22a09e52c --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/target-cover-yieldexpr.js @@ -0,0 +1,35 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-update-expressions-static-semantics-early-errors +description: Applied to a "covered" YieldExpression +info: | + UnaryExpression : + ++ UnaryExpression + -- UnaryExpression + + - It is an early Syntax Error if IsValidSimpleAssignmentTarget of + UnaryExpression is invalid or strict. + + 12.15.3 Static Semantics: AssignmentTargetType + + AssignmentExpression: + YieldExpression + ArrowFunction + AsyncArrowFunction + LeftHandSideExpression = AssignmentExpression + LeftHandSideExpression AssignmentOperator AssignmentExpression + + 1. Return invalid. +features: [generators] +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +function* g() { + ++(yield); +} diff --git a/js/src/tests/test262/language/expressions/prefix-increment/target-newtarget.js b/js/src/tests/test262/language/expressions/prefix-increment/target-newtarget.js new file mode 100644 index 0000000000..eb8e4edd45 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/target-newtarget.js @@ -0,0 +1,32 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-update-expressions-static-semantics-early-errors +description: Applied to new.target +info: | + UnaryExpression : + ++ UnaryExpression + -- UnaryExpression + + - It is an early Syntax Error if IsValidSimpleAssignmentTarget of + UnaryExpression is invalid or strict. + + 12.3.1.6 Static Semantics: AssignmentTargetType + + NewTarget: + + new.target + + 1. Return invalid. +negative: + phase: parse + type: SyntaxError +features: [new.target] +---*/ + +$DONOTEVALUATE(); + +function f() { + ++new.target; +} diff --git a/js/src/tests/test262/language/expressions/prefix-increment/whitespace.js b/js/src/tests/test262/language/expressions/prefix-increment/whitespace.js new file mode 100644 index 0000000000..04d98bd7d8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-increment/whitespace.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + White Space and Line Terminator between "++" and UnaryExpression are + allowed +es5id: 11.4.4_A1 +esid: sec-prefix-increment-operator +---*/ + +var x = 0; + +assert.sameValue(++ x, 1, 'U+0009 (expression)'); +assert.sameValue(x, 1, 'U+0009 (side effect)'); + +assert.sameValue(++x, 2, 'U+000B (expression)'); +assert.sameValue(x, 2, 'U+000B (side effect)'); + +assert.sameValue(++x, 3, 'U+000C (expression)'); +assert.sameValue(x, 3, 'U+000C (side effect)'); + +assert.sameValue(++ x, 4, 'U+0020 (expression)'); +assert.sameValue(x, 4, 'U+0020 (side effect)'); + +assert.sameValue(++ x, 5, 'U+00A0 (expression)'); +assert.sameValue(x, 5, 'U+00A0 (side effect)'); + +assert.sameValue(++ +x, 6, 'U+000A (expression)'); +assert.sameValue(x, 6, 'U+000A (side effect)'); + +assert.sameValue(++
x, 7, 'U+000D (expression)'); +assert.sameValue(x, 7, 'U+000D (side effect)'); + +assert.sameValue(++
x, 8, 'U+2028 (expression)'); +assert.sameValue(x, 8, 'U+2028 (side effect)'); + +assert.sameValue(++
x, 9, 'U+2029 (expression)'); +assert.sameValue(x, 9, 'U+2029 (side effect)'); + +assert.sameValue( + ++ +
x, + 10, + 'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (expression)' +); +assert.sameValue( + x, 10, 'U+0009U+000BU+000CU+0020U+00A0U+000AU+000DU+2028U+2029 (side effect)' +); + +reportCompare(0, 0); |