From c1e1c56dc0977e21d89017109e978148ba333bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 19 May 2015 17:46:34 +0200 Subject: [PATCH] Increment/Decrement with property accessor expression The increment/decrement operator evaluates its operand expression once. When the operand expression is a property accessor, RequireObjectCoercible and ToPropertyKey are called on the property accessor in the correct order. --- .../postfix-decrement/S11.3.2_A6_T1.js | 31 +++++++++++++++++++ .../postfix-decrement/S11.3.2_A6_T2.js | 31 +++++++++++++++++++ .../postfix-decrement/S11.3.2_A6_T3.js | 22 +++++++++++++ .../postfix-increment/S11.3.1_A6_T1.js | 31 +++++++++++++++++++ .../postfix-increment/S11.3.1_A6_T2.js | 31 +++++++++++++++++++ .../postfix-increment/S11.3.1_A6_T3.js | 22 +++++++++++++ .../prefix-decrement/S11.4.5_A6_T1.js | 31 +++++++++++++++++++ .../prefix-decrement/S11.4.5_A6_T2.js | 31 +++++++++++++++++++ .../prefix-decrement/S11.4.5_A6_T3.js | 22 +++++++++++++ .../prefix-increment/S11.4.4_A6_T1.js | 31 +++++++++++++++++++ .../prefix-increment/S11.4.4_A6_T2.js | 31 +++++++++++++++++++ .../prefix-increment/S11.4.4_A6_T3.js | 22 +++++++++++++ 12 files changed, 336 insertions(+) create mode 100755 test/language/expressions/postfix-decrement/S11.3.2_A6_T1.js create mode 100755 test/language/expressions/postfix-decrement/S11.3.2_A6_T2.js create mode 100755 test/language/expressions/postfix-decrement/S11.3.2_A6_T3.js create mode 100755 test/language/expressions/postfix-increment/S11.3.1_A6_T1.js create mode 100755 test/language/expressions/postfix-increment/S11.3.1_A6_T2.js create mode 100755 test/language/expressions/postfix-increment/S11.3.1_A6_T3.js create mode 100755 test/language/expressions/prefix-decrement/S11.4.5_A6_T1.js create mode 100755 test/language/expressions/prefix-decrement/S11.4.5_A6_T2.js create mode 100755 test/language/expressions/prefix-decrement/S11.4.5_A6_T3.js create mode 100755 test/language/expressions/prefix-increment/S11.4.4_A6_T1.js create mode 100755 test/language/expressions/prefix-increment/S11.4.4_A6_T2.js create mode 100755 test/language/expressions/prefix-increment/S11.4.4_A6_T3.js diff --git a/test/language/expressions/postfix-decrement/S11.3.2_A6_T1.js b/test/language/expressions/postfix-decrement/S11.3.2_A6_T1.js new file mode 100755 index 0000000000..960a0b4da7 --- /dev/null +++ b/test/language/expressions/postfix-decrement/S11.3.2_A6_T1.js @@ -0,0 +1,31 @@ +// 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]--; +}); diff --git a/test/language/expressions/postfix-decrement/S11.3.2_A6_T2.js b/test/language/expressions/postfix-decrement/S11.3.2_A6_T2.js new file mode 100755 index 0000000000..9a033e79f7 --- /dev/null +++ b/test/language/expressions/postfix-decrement/S11.3.2_A6_T2.js @@ -0,0 +1,31 @@ +// 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]--; +}); diff --git a/test/language/expressions/postfix-decrement/S11.3.2_A6_T3.js b/test/language/expressions/postfix-decrement/S11.3.2_A6_T3.js new file mode 100755 index 0000000000..951c72303e --- /dev/null +++ b/test/language/expressions/postfix-decrement/S11.3.2_A6_T3.js @@ -0,0 +1,22 @@ +// 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]--; diff --git a/test/language/expressions/postfix-increment/S11.3.1_A6_T1.js b/test/language/expressions/postfix-increment/S11.3.1_A6_T1.js new file mode 100755 index 0000000000..077c0b26fc --- /dev/null +++ b/test/language/expressions/postfix-increment/S11.3.1_A6_T1.js @@ -0,0 +1,31 @@ +// 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]++; +}); diff --git a/test/language/expressions/postfix-increment/S11.3.1_A6_T2.js b/test/language/expressions/postfix-increment/S11.3.1_A6_T2.js new file mode 100755 index 0000000000..4eb9d5b712 --- /dev/null +++ b/test/language/expressions/postfix-increment/S11.3.1_A6_T2.js @@ -0,0 +1,31 @@ +// 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]++; +}); diff --git a/test/language/expressions/postfix-increment/S11.3.1_A6_T3.js b/test/language/expressions/postfix-increment/S11.3.1_A6_T3.js new file mode 100755 index 0000000000..4611e4551b --- /dev/null +++ b/test/language/expressions/postfix-increment/S11.3.1_A6_T3.js @@ -0,0 +1,22 @@ +// 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]++; diff --git a/test/language/expressions/prefix-decrement/S11.4.5_A6_T1.js b/test/language/expressions/prefix-decrement/S11.4.5_A6_T1.js new file mode 100755 index 0000000000..567a7534a5 --- /dev/null +++ b/test/language/expressions/prefix-decrement/S11.4.5_A6_T1.js @@ -0,0 +1,31 @@ +// 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]; +}); diff --git a/test/language/expressions/prefix-decrement/S11.4.5_A6_T2.js b/test/language/expressions/prefix-decrement/S11.4.5_A6_T2.js new file mode 100755 index 0000000000..7eec750dad --- /dev/null +++ b/test/language/expressions/prefix-decrement/S11.4.5_A6_T2.js @@ -0,0 +1,31 @@ +// 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]; +}); diff --git a/test/language/expressions/prefix-decrement/S11.4.5_A6_T3.js b/test/language/expressions/prefix-decrement/S11.4.5_A6_T3.js new file mode 100755 index 0000000000..592c328607 --- /dev/null +++ b/test/language/expressions/prefix-decrement/S11.4.5_A6_T3.js @@ -0,0 +1,22 @@ +// 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]; diff --git a/test/language/expressions/prefix-increment/S11.4.4_A6_T1.js b/test/language/expressions/prefix-increment/S11.4.4_A6_T1.js new file mode 100755 index 0000000000..bce4f1a1ec --- /dev/null +++ b/test/language/expressions/prefix-increment/S11.4.4_A6_T1.js @@ -0,0 +1,31 @@ +// 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]; +}); diff --git a/test/language/expressions/prefix-increment/S11.4.4_A6_T2.js b/test/language/expressions/prefix-increment/S11.4.4_A6_T2.js new file mode 100755 index 0000000000..e2b5e85e21 --- /dev/null +++ b/test/language/expressions/prefix-increment/S11.4.4_A6_T2.js @@ -0,0 +1,31 @@ +// 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]; +}); diff --git a/test/language/expressions/prefix-increment/S11.4.4_A6_T3.js b/test/language/expressions/prefix-increment/S11.4.4_A6_T3.js new file mode 100755 index 0000000000..94473bb288 --- /dev/null +++ b/test/language/expressions/prefix-increment/S11.4.4_A6_T3.js @@ -0,0 +1,22 @@ +// 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];