Index: test/mjsunit/harmony/unscopables.js |
diff --git a/test/mjsunit/harmony/unscopables.js b/test/mjsunit/harmony/unscopables.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f76396d32285944b24b9a6d3d0b42ae92ea6d026 |
--- /dev/null |
+++ b/test/mjsunit/harmony/unscopables.js |
@@ -0,0 +1,200 @@ |
+// Copyright 2014 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --harmony-unscopables |
+ |
+ |
+(function TestBasics() { |
rossberg
2014/07/11 11:59:07
Some of these tests should probably be run on diff
arv (Not doing code reviews)
2014/07/11 21:47:28
Our proxies do not support symbol property names s
|
+ var x = 1; |
+ var y = 2; |
+ var z = 3; |
+ var object = { |
+ x: 4, |
+ y: 5 |
+ }; |
+ |
+ with (object) { |
+ assertEquals(x, 4); |
+ assertEquals(y, 5); |
+ assertEquals(z, 3); |
+ } |
+ |
+ object[Symbol.unscopables] = {x: true}; |
+ with (object) { |
+ assertEquals(x, 1); |
+ assertEquals(y, 5); |
+ assertEquals(z, 3); |
+ } |
+ |
+ object[Symbol.unscopables] = {x: 0, y: true}; |
+ with (object) { |
+ assertEquals(x, 1); |
+ assertEquals(y, 2); |
+ assertEquals(z, 3); |
+ } |
+})(); |
+ |
+ |
+(function TestOnProto() { |
+ var x = 1; |
+ var y = 2; |
+ var z = 3; |
+ var proto = { |
+ x: 4 |
+ }; |
+ var object = { |
+ __proto__: proto, |
+ y: 5 |
+ }; |
+ |
+ with (object) { |
+ assertEquals(x, 4); |
+ assertEquals(y, 5); |
+ assertEquals(z, 3); |
+ } |
+ |
+ proto[Symbol.unscopables] = {x: true}; |
+ with (object) { |
+ assertEquals(x, 1); |
+ assertEquals(y, 5); |
+ assertEquals(z, 3); |
+ } |
+ |
+ object[Symbol.unscopables] = {y: true}; |
+ with (object) { |
+ assertEquals(x, 1); |
+ assertEquals(y, 2); |
+ assertEquals(z, 3); |
+ } |
+ |
+ proto[Symbol.unscopables] = {y: true}; |
+ object[Symbol.unscopables] = {x: true}; |
+ with (object) { |
+ assertEquals(x, 4); |
+ assertEquals(y, 5); |
+ assertEquals(z, 3); |
+ } |
+})(); |
+ |
+ |
+(function TestNonObject() { |
+ var x = 1; |
+ var y = 2; |
+ var object = { |
+ x: 3, |
+ y: 4 |
+ }; |
+ |
+ object[Symbol.unscopables] = 'xy'; |
+ with (object) { |
+ assertEquals(x, 3); |
+ assertEquals(y, 4); |
+ } |
+ |
+ object[Symbol.unscopables] = null; |
+ with (object) { |
+ assertEquals(x, 3); |
+ assertEquals(y, 4); |
+ } |
+})(); |
+ |
+ |
+(function TestChangeDuringWith() { |
rossberg
2014/07/11 11:59:07
It would be good to have a variation of this test
arv (Not doing code reviews)
2014/07/11 21:47:28
Done.
|
+ var x = 1; |
+ var y = 2; |
+ var object = { |
+ x: 3, |
+ y: 4 |
+ }; |
+ |
+ with (object) { |
+ assertEquals(3, x); |
+ assertEquals(4, y); |
+ object[Symbol.unscopables] = {x: true}; |
+ assertEquals(1, x); |
+ assertEquals(4, y); |
+ } |
+})(); |
+ |
+ |
+var global = this; |
+(function TestGlobal() { |
+ global.values = 'global.values'; |
+ Array.prototype.values = 'Array.prototype.values'; |
+ Array.prototype[Symbol.unscopables] = {values: true}; |
+ Array.prototype.__proto__ = {values: 42}; |
+ var array = []; |
+ with (array) { |
+ assertEquals(values, 42); |
+ } |
+})(); |
+ |
+ |
+(function TestAccessorReceiver() { |
rossberg
2014/07/11 11:59:07
Hm, this test doesn't use unscopables at all...
arv (Not doing code reviews)
2014/07/11 21:47:29
Since --harmony-unscopables changes how with works
|
+ var x = 'local variable'; |
+ |
+ var proto = { |
+ get x() { |
+ assertEquals(this, object); |
+ return this._x; |
+ }, |
+ _x: 'proto' |
+ }; |
+ var object = { |
+ __proto__: proto, |
+ _x: 'object' |
+ }; |
+ |
+ with (object) { |
+ assertEquals(x, 'object'); |
+ } |
+})(); |
+ |
+ |
+(function TestUnscopablesGetter() { |
+ var x = 'local variable'; |
+ var object = { |
+ x: 'object' |
+ }; |
+ |
+ var callCount = 0; |
+ Object.defineProperty(object, Symbol.unscopables, { |
+ get: function() { |
+ callCount++; |
+ return {}; |
+ }, |
+ configurable: true |
+ }); |
+ with (object) { |
+ assertEquals(x, 'object'); |
+ } |
+ // Once for HasBinding and once for GetBindingValue |
+ assertEquals(callCount, 2); |
+ |
+ callCount = 0; |
+ Object.defineProperty(object, Symbol.unscopables, { |
rossberg
2014/07/11 11:59:07
It would definitely be good to have variants of th
arv (Not doing code reviews)
2014/07/11 21:47:28
Done.
|
+ get: function() { |
+ callCount++; |
+ return callCount === 1 ? {x: true} : {}; |
+ } |
+ }); |
+ with (object) { |
+ assertEquals(x, 'local variable'); |
+ } |
+ // Once for HasBinding |
+ assertEquals(callCount, 1); |
+ |
+ callCount = 0; |
+ Object.defineProperty(object, Symbol.unscopables, { |
+ get: function() { |
+ callCount++; |
+ return callCount === 1 ? {} : {x: true}; |
+ } |
+ }); |
+ with (object) { |
+ assertEquals(x, undefined); |
+ } |
+ // Once for HasBinding, once for GetBindingValue. |
+ assertEquals(callCount, 2); |
+})(); |