From e262dcd02133909af8a8bd28f5a5efa9b42d5196 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo <shu@rfrn.org> Date: Thu, 2 Mar 2017 10:15:56 -0800 Subject: [PATCH] Test that @@unscopables is looked up once for inc/dec. (#869) --- .../statements/with/unscopables-inc-dec.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/language/statements/with/unscopables-inc-dec.js diff --git a/test/language/statements/with/unscopables-inc-dec.js b/test/language/statements/with/unscopables-inc-dec.js new file mode 100644 index 0000000000..e2b12b73f8 --- /dev/null +++ b/test/language/statements/with/unscopables-inc-dec.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object-environment-records-hasbinding-n +description: > + @@unscopables should be looked up exactly once for inc/dec. +info: | + UpdateExpression : LeftHandSideExpression ++ + 1. Let lhs be the result of evaluating LeftHandSideExpression. + + GetIdentifierReference ( lex, name, strict ) + [...] + 3. Let exists be ? envRec.HasBinding(name). + + HasBinding ( N ) + [...] + 6. Let unscopables be ? Get(bindings, @@unscopables). +flags: [noStrict] +features: [Symbol.unscopables] +---*/ + +var unscopablesGetterCalled = 0; +var a, b, flag = true; +with (a = { x: 7 }) { + with (b = { x: 4, get [Symbol.unscopables]() { + unscopablesGetterCalled++; + return { x: flag=!flag }; + } }) { + x++; + } +} + +assert.sameValue(unscopablesGetterCalled, 1); +assert.sameValue(a.x, 7); +assert.sameValue(b.x, 5); + +unscopablesGetterCalled = 0; +flag = true; +with (a = { x: 7 }) { + with (b = { x: 4, get [Symbol.unscopables]() { + unscopablesGetterCalled++; + return { x: flag=!flag }; + } }) { + x--; + } +} + +assert.sameValue(unscopablesGetterCalled, 1); +assert.sameValue(a.x, 7); +assert.sameValue(b.x, 3); -- GitLab