Chromium Code Reviews| Index: test/mjsunit/harmony/proxies-with-unscopables.js |
| diff --git a/test/mjsunit/harmony/proxies-with-unscopables.js b/test/mjsunit/harmony/proxies-with-unscopables.js |
| index 1237b2b361041cbba35d369038067d157e82c03f..2cb45f7d266faff443d298ab6ed62b04e69fefa4 100644 |
| --- a/test/mjsunit/harmony/proxies-with-unscopables.js |
| +++ b/test/mjsunit/harmony/proxies-with-unscopables.js |
| @@ -5,22 +5,24 @@ |
| // Flags: --harmony-proxies |
| -// TODO(arv): Once proxies can intercept symbols, add more tests. |
| +function str(x) { |
| + if (typeof x === "symbol") return "<Symbol>"; |
| + return "" + x; |
| +} |
|
neis
2015/12/14 15:53:55
Why not use String(x)? Then you can test for "Sym
Jakob Kummerow
2015/12/14 15:59:12
Done.
|
| function TestBasics() { |
| var log = []; |
| var proxy = new Proxy({}, { |
| - getPropertyDescriptor: function(key) { |
| - log.push(key); |
| - if (key === 'x') { |
| - return { |
| - value: 1, |
| - configurable: true |
| - }; |
| - } |
| - return undefined; |
| + get: function(target, key) { |
| + log.push("get " + str(key)); |
| + if (key === 'x') return 1; |
| + }, |
| + has: function(target, key) { |
| + log.push("has " + str(key)); |
| + if (key === 'x') return true; |
| + return false; |
| } |
| }); |
| @@ -30,27 +32,23 @@ function TestBasics() { |
| assertEquals(1, x); |
| } |
| - // One 'x' for HasBinding and one for GetBindingValue |
| - assertEquals(['assertEquals', 'x', 'x'], log); |
| + assertEquals(['has assertEquals', 'has x', 'get <Symbol>', 'get x'], log); |
| } |
| TestBasics(); |
| function TestInconsistent() { |
| var log = []; |
| - var calls = 0; |
| var proxy = new Proxy({}, { |
| - getPropertyDescriptor: function(key) { |
| - log.push(key); |
| - if (key === 'x' && calls < 1) { |
| - calls++; |
| - return { |
| - value: 1, |
| - configurable: true |
| - }; |
| - } |
| + get: function(target, key) { |
| + log.push("get " + str(key)); |
| return undefined; |
| + }, |
| + has: function(target, key) { |
| + log.push("has " + str(key)); |
| + if (key === 'x') return true; |
| + return false; |
| } |
| }); |
| @@ -60,8 +58,7 @@ function TestInconsistent() { |
| assertEquals(void 0, x); |
| } |
| - // One 'x' for HasBinding and one for GetBindingValue |
| - assertEquals(['assertEquals', 'x', 'x'], log); |
| + assertEquals(['has assertEquals', 'has x', 'get <Symbol>', 'get x'], log); |
| } |
| TestInconsistent(); |
| @@ -73,18 +70,13 @@ function TestUseProxyAsUnscopables() { |
| }; |
| var calls = 0; |
| var proxy = new Proxy({}, { |
| - has: function(key) { |
| + has: function() { |
| assertUnreachable(); |
| }, |
| - getPropertyDescriptor: function(key) { |
| - calls++; |
| + get: function(target, key) { |
| assertEquals('x', key); |
| - return { |
| - value: calls === 2 ? true : undefined, |
| - configurable: true, |
| - enumerable: true, |
| - writable: true, |
| - }; |
| + calls++; |
| + return calls === 2 ? true : undefined; |
| } |
| }); |
| @@ -111,10 +103,10 @@ function TestThrowInHasUnscopables() { |
| var calls = 0; |
| var proxy = new Proxy({}, { |
| - has: function(key) { |
| + has: function() { |
| assertUnreachable(); |
| }, |
| - getPropertyDescriptor: function(key) { |
| + get: function(target, key) { |
| if (calls++ === 0) { |
| throw new CustomError(); |
| } |
| @@ -137,7 +129,10 @@ var global = this; |
| function TestGlobalShouldIgnoreUnscopables() { |
| global.x = 1; |
| var proxy = new Proxy({}, { |
| - getPropertyDescriptor: function() { |
| + get: function() { |
| + assertUnreachable(); |
| + }, |
| + has: function() { |
| assertUnreachable(); |
| } |
| }); |