diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/language/expressions/prefix-decrement | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/language/expressions/prefix-decrement')
35 files changed, 1083 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-2-2gs-strict.js b/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-2-2gs-strict.js new file mode 100644 index 0000000000..42a20db97e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-2-2gs-strict.js @@ -0,0 +1,19 @@ +// |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. + +/*--- +es5id: 11.4.5-2-2gs +description: > + Strict Mode - SyntaxError is throw if the UnaryExpression operated + upon by a Prefix Decrement operator(--arguments) +negative: + phase: parse + type: SyntaxError +flags: [onlyStrict] +---*/ + +$DONOTEVALUATE(); + +--arguments; diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-2-3-s.js b/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-2-3-s.js new file mode 100644 index 0000000000..56033f721a --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/11.4.5-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.5-2-3-s +description: SyntaxError is not thrown for --arguments[...] +---*/ + +function testcase() { + arguments[1] = 7; + --arguments[1]; + assert.sameValue(arguments[1], 6, 'arguments[1]'); + } +testcase(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A2.1_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A2.1_T1.js new file mode 100644 index 0000000000..5cd97ac2e5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A2.1_T1 +description: Type(x) is Reference and GetBase(x) is not null +---*/ + +//CHECK#1 +var x = 1; +if (--x !== 1 - 1) { + throw new Test262Error('#1: var x = 1; --x === 1 - 1. Actual: ' + (--x)); +} else { + if (x !== 1 - 1) { + throw new Test262Error('#1: var x = 1; --x; x === 1 - 1. Actual: ' + (x)); + } +} + +//CHECK#2 +this.x = 1; +if (--this.x !== 1 - 1) { + throw new Test262Error('#2: this.x = 1; --this.x === 1 - 1. Actual: ' + (--this.x)); +} else { + if (this.x !== 1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#3: var object = new Object(); object.prop = 1; --object.prop === 1 - 1. Actual: ' + (--object.prop)); +} else { + if (this.x !== 1 - 1) { + throw new Test262Error('#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-decrement/S11.4.5_A2.1_T2.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A2.1_T2.js new file mode 100644 index 0000000000..e57096133c --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A2.1_T2 +description: If GetBase(x) is null, throw ReferenceError +---*/ + +//CHECK#1 +try { + --x; + throw new Test262Error('#1.1: --x throw ReferenceError. Actual: ' + (--x)); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + throw new Test262Error('#1.2: --x throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A2.2_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A2.2_T1.js new file mode 100644 index 0000000000..0f9d23139b --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_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) { + throw new Test262Error('#1: var object = {valueOf: function() {return 1}}; --object === 1 - 1. Actual: ' + (--object)); +} else { + if (object !== 1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#2: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; --object === 1 - 1. Actual: ' + (--object)); +} else { + if (object !== 1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#3: var object = {valueOf: function() {return 1}, toString: function() {return {}}}; --object === 1 - 1. Actual: ' + (--object)); +} else { + if (object !== 1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#4.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; --object === 1 - 1. Actual: ' + (--object)); + } else { + if (object !== 1 - 1) { + throw new Test262Error('#4.1: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; --object; object === 1 - 1. Actual: ' + (object)); + } + } +} +catch (e) { + if (e === "error") { + throw new Test262Error('#4.2: var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; --object not throw "error"'); + } else { + throw new Test262Error('#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) { + throw new Test262Error('#5.1: var object = {toString: function() {return 1}}; --object === 1 - 1. Actual: ' + (--object)); +} else { + if (object !== 1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#6.1: var object = {valueOf: function() {return {}}, toString: function() {return 1}}; --object === 1 - 1. Actual: ' + (--object)); +} else { + if (object !== 1 - 1) { + throw new Test262Error('#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; + throw new Test262Error('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return 1}}; --object throw "error". Actual: ' + (--object)); +} +catch (e) { + if (e !== "error") { + throw new Test262Error('#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; + throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; --object throw TypeError. Actual: ' + (--object)); +} +catch (e) { + if ((e instanceof TypeError) !== true) { + throw new Test262Error('#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-decrement/S11.4.5_A3_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T1.js new file mode 100644 index 0000000000..6ff5479bd0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A3_T1 +description: Type(x) is boolean primitive or Boolean object +---*/ + +//CHECK#1 +var x = true; +--x; +if (x !== 1 - 1) { + throw new Test262Error('#1: var x = true; --x; x === 1 - 1. Actual: ' + (x)); +} + +//CHECK#2 +var x = new Boolean(false); +--x; +if (x !== 0 - 1) { + throw new Test262Error('#2: var x = new Boolean(false); --x; x === 0 - 1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T2.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T2.js new file mode 100644 index 0000000000..a71845fef6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A3_T2 +description: Type(x) is number primitive or Number object +---*/ + +//CHECK#1 +var x = 0.1; +--x; +if (x !== 0.1 - 1) { + throw new Test262Error('#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) { + throw new Test262Error('#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-decrement/S11.4.5_A3_T3.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T3.js new file mode 100644 index 0000000000..d9d6a93b06 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A3_T3 +description: Type(x) is primitive string or String object +---*/ + +//CHECK#1 +var x = "1"; +--x; +if (x !== 1 - 1) { + throw new Test262Error('#1: var x = "1"; --x; x === 1 - 1. Actual: ' + (x)); +} + +//CHECK#2 +var x = "x"; +--x; +if (isNaN(x) !== true) { + throw new Test262Error('#2: var x = "x"; --x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#3 +var x = new Number("-1"); +--x; +if (x !== -1 - 1) { + throw new Test262Error('#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-decrement/S11.4.5_A3_T4.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T4.js new file mode 100644 index 0000000000..f2b894736b --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A3_T4 +description: Type(x) is undefined or null +---*/ + +//CHECK#1 +var x; +--x; +if (isNaN(x) !== true) { + throw new Test262Error('#1: var x; --x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#2 +var x = null; +--x; +if (x !== -1) { + throw new Test262Error('#2: var x = null; --x; x === -1. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T5.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A3_T5.js new file mode 100644 index 0000000000..0b7614444c --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A3_T5 +description: Type(x) is Object object or Function object +---*/ + +//CHECK#1 +var x = {}; +--x; +if (isNaN(x) !== true) { + throw new Test262Error('#1: var x = {}; --x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#2 +var x = function(){return 1}; +--x; +if (isNaN(x) !== true) { + throw new Test262Error('#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-decrement/S11.4.5_A4_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T1.js new file mode 100644 index 0000000000..7cb3216ad8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A4_T1 +description: Type(x) is boolean primitive or Boolean object +---*/ + +//CHECK#1 +var x = true; +if (--x !== 1 - 1) { + throw new Test262Error('#1: var x = true; --x === 1 - 1. Actual: ' + (--x)); +} + +//CHECK#2 +var x = new Boolean(false); +if (--x !== 0 - 1) { + throw new Test262Error('#2: var x = new Boolean(false); --x === 0 - 1. Actual: ' + (--x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T2.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T2.js new file mode 100644 index 0000000000..6f79668e10 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A4_T2 +description: Type(x) is number primitive or Number object +---*/ + +//CHECK#1 +var x = 0.1; +if (--x !== 0.1 - 1) { + throw new Test262Error('#1: var x = 0.1; --x === 0.1 - 1. Actual: ' + (--x)); +} + +//CHECK#2 +var x = new Number(-1.1); +if (--x !== -1.1 - 1) { + throw new Test262Error('#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-decrement/S11.4.5_A4_T3.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T3.js new file mode 100644 index 0000000000..a7add2c03b --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A4_T3 +description: Type(x) is string primitive or String object +---*/ + +//CHECK#1 +var x = "1"; +if (--x !== 1 - 1) { + throw new Test262Error('#1: var x = "1"; --x === 1 - 1. Actual: ' + (--x)); +} + +//CHECK#2 +var x = "x"; +if (isNaN(--x) !== true) { + throw new Test262Error('#2: var x = "x"; --x === Not-a-Number. Actual: ' + (--x)); +} + +//CHECK#3 +var x = new String("-1"); +if (--x !== -1 - 1) { + throw new Test262Error('#3: var x = new String("-1"); --x === -1 - 1. Actual: ' + (--x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T4.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T4.js new file mode 100644 index 0000000000..cda8745456 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A4_T4 +description: Type(x) is undefined or null +---*/ + +//CHECK#1 +var x; +if (isNaN(--x) !== true) { + throw new Test262Error('#1: var x; --x; x === Not-a-Number. Actual: ' + (x)); +} + +//CHECK#2 +var x = null; +if (--x !== -1) { + throw new Test262Error('#2: var x = null; --x === -1. Actual: ' + (--x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T5.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A4_T5.js new file mode 100644 index 0000000000..6d631d188e --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_A4_T5 +description: Type(x) is Object object or Function object +---*/ + +//CHECK#1 +var x = {}; +if (isNaN(--x) !== true) { + throw new Test262Error('#1: var x = {}; --x === Not-a-Number. Actual: ' + (--x)); +} + +//CHECK#2 +var x = function(){return 1}; +if (isNaN(--x) !== true) { + throw new Test262Error('#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-decrement/S11.4.5_A5_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A5_T1.js new file mode 100644 index 0000000000..3ffed09bb1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_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 !== 1) { + throw new Test262Error('#1: scope.x === 1. Actual: ' + (scope.x)); + } + if (x !== 0) { + throw new Test262Error('#2: x === 0. Actual: ' + (x)); + } +} +testFunction(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A5_T2.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A5_T2.js new file mode 100644 index 0000000000..d8a9f39fee --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_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 !== 1) { + throw new Test262Error('#1: scope.x === 1. Actual: ' + (scope.x)); +} +if (x !== 0) { + throw new Test262Error('#2: x === 0. Actual: ' + (x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A5_T3.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A5_T3.js new file mode 100644 index 0000000000..6c02d3a490 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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.5_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 !== 1) { + throw new Test262Error('#1: innerScope.x === 1. Actual: ' + (innerScope.x)); +} +if (outerScope.x !== 0) { + throw new Test262Error('#2: outerScope.x === 0. Actual: ' + (outerScope.x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T1.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T1.js new file mode 100644 index 0000000000..149a49a0a1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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() { + throw new Test262Error("property key evaluated"); + } + }; + + --base[prop]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T2.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T2.js new file mode 100644 index 0000000000..09495dee06 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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() { + throw new Test262Error("property key evaluated"); + } + }; + + --base[prop]; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T3.js b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_A6_T3.js new file mode 100644 index 0000000000..b274872680 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/S11.4.5_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-decrement/arguments-nostrict.js b/js/src/tests/test262/language/expressions/prefix-decrement/arguments-nostrict.js new file mode 100644 index 0000000000..b82439c517 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/arguments-strict.js b/js/src/tests/test262/language/expressions/prefix-decrement/arguments-strict.js new file mode 100644 index 0000000000..363377c705 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/bigint.js b/js/src/tests/test262/language/expressions/prefix-decrement/bigint.js new file mode 100644 index 0000000000..39897ecb13 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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 decrement for references to BigInt values +esid: sec-prefix-decrement-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)::subtract(oldValue, Type(oldValue)::unit). + 4. Perform ? PutValue(expr, newValue). + 5. Return newValue. +features: [BigInt] +---*/ + +var x = 1n; +assert.sameValue(--x, 0n, "var x = 1n; --x === 0n"); +assert.sameValue(x, 0n, "var x = 1n; --x; x === 0n"); + +var x = 0n; +assert.sameValue(--x, -1n, "var x = 0n; --x === -1n"); +assert.sameValue(x, -1n, "var x = 0n; --x; x === -1n"); + +var x = 123457n; +assert.sameValue(--x, 123456n, "var x = 123457n; --x === 123456n"); +assert.sameValue(x, 123456n, "var x = 123457n; --x; x === 123456n"); + +var x = -123456n; +assert.sameValue(--x, -123457n, "var x = -123456n; --x === -123457n"); +assert.sameValue(x, -123457n, "var x = -123456n; --x; x === -123457n"); + +var x = 0x1fffffffffffff01n; +assert.sameValue(--x, 0x1fffffffffffff00n, "var x = 0x1fffffffffffff01n; --x === 0x1fffffffffffff00n"); +assert.sameValue(x, 0x1fffffffffffff00n, "var x = 0x1fffffffffffff01n; --x; x === 0x1fffffffffffff00n"); + +var x = -0x1fffffffffffff00n; +assert.sameValue(--x, -0x1fffffffffffff01n, "var x = -0x1fffffffffffff00n; --x === -0x1fffffffffffff01n"); +assert.sameValue(x, -0x1fffffffffffff01n, "var x = -0x1fffffffffffff00n; --x; x === -0x1fffffffffffff01n"); + +var x = {y:1n}; +assert.sameValue(--x.y, 0n, "var x = {y:1n}; --x.y === 0n"); +assert.sameValue(x.y, 0n, "var x = {y:1n}; --x.y; x.y === 0n"); + +var x = {y:{z:1n}}; +assert.sameValue(--x.y.z, 0n, "var x = {y:{z:1n}}; --x.y.z === 0n"); +assert.sameValue(x.y.z, 0n, "var x = {y:{z:1n}}; --x.y.z; x.y.z === 0n"); + +var x = [1n]; +assert.sameValue(--x[0], 0n, "var x = [1n]; --x[0] === 0n"); +assert.sameValue(x[0], 0n, "var x = [1n]; --x[0]; x[0] === 0n"); + +var x = [null, [null, null, 1n]]; +assert.sameValue(--x[1][2], 0n, "var x = [null, [null, null, 1n]]; --x[1][2] === 0n"); +assert.sameValue(x[1][2], 0n, "var x = [null, [null, null, 1n]]; --x[1][2]; x[1][2] === 0n"); + +var x = {y:[1n]}; +assert.sameValue(--x.y[0], 0n, "var x = {y:[1n]}; --x.y[0] === 0n"); +assert.sameValue(x.y[0], 0n, "var x = {y:[1n]}; --x.y[0]; x.y[0] === 0n"); + +var x = [{z:1n}]; +assert.sameValue(--x[0].z, 0n, "var x = [{z:1n}]; --x[0].z === 0n"); +assert.sameValue(x[0].z, 0n, "var x = [{z:1n}]; --x[0].z; x[0].z === 0n"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/browser.js b/js/src/tests/test262/language/expressions/prefix-decrement/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/browser.js diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/eval-nostrict.js b/js/src/tests/test262/language/expressions/prefix-decrement/eval-nostrict.js new file mode 100644 index 0000000000..3eff3119e7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/eval-strict.js b/js/src/tests/test262/language/expressions/prefix-decrement/eval-strict.js new file mode 100644 index 0000000000..203b5ac94a --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/eval-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. (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-decrement/operator-prefix-decrement-x-calls-putvalue-lhs-newvalue--1.js b/js/src/tests/test262/language/expressions/prefix-decrement/operator-prefix-decrement-x-calls-putvalue-lhs-newvalue--1.js new file mode 100644 index 0000000000..ee57f0c376 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/operator-prefix-decrement-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.5_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-decrement/operator-prefix-decrement-x-calls-putvalue-lhs-newvalue-.js b/js/src/tests/test262/language/expressions/prefix-decrement/operator-prefix-decrement-x-calls-putvalue-lhs-newvalue-.js new file mode 100644 index 0000000000..4c76ae6ff6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/operator-prefix-decrement-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.5_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-decrement/shell.js b/js/src/tests/test262/language/expressions/prefix-decrement/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/shell.js diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/target-cover-id.js b/js/src/tests/test262/language/expressions/prefix-decrement/target-cover-id.js new file mode 100644 index 0000000000..56a929c2cc --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/prefix-decrement/target-cover-newtarget.js b/js/src/tests/test262/language/expressions/prefix-decrement/target-cover-newtarget.js new file mode 100644 index 0000000000..f976891363 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/target-cover-yieldexpr.js b/js/src/tests/test262/language/expressions/prefix-decrement/target-cover-yieldexpr.js new file mode 100644 index 0000000000..92cac869d1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/target-newtarget.js b/js/src/tests/test262/language/expressions/prefix-decrement/target-newtarget.js new file mode 100644 index 0000000000..dd97e59f8d --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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-decrement/whitespace.js b/js/src/tests/test262/language/expressions/prefix-decrement/whitespace.js new file mode 100644 index 0000000000..f7a38319c7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/prefix-decrement/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.5_A1 +esid: sec-prefix-decrement-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); |