Commit 0e2ea6a5 authored by jkummerow's avatar jkummerow Committed by Commit bot

[proxies] [tests] Un-skip proxies-with-unscopables, delete proxies-symbols

- proxies-with-unscopables needed updating of trap names
- proxies-symbols doesn't make sense any more: it tested symbol fitering/
  blacklisting, but Proxies interact with Symbols just fine according to
  the current spec.

BUG=v8:1543
LOG=n

Review URL: https://codereview.chromium.org/1529473002

Cr-Commit-Position: refs/heads/master@{#32844}
parent 1596b015
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-proxies
// Helper.
function TestWithProxies(test, x, y, z) {
test(function(h) { return new Proxy({}, h) }, x, y, z)
test(function(h) {
return Proxy.createFunction(h, function() {})
}, x, y, z)
}
// No symbols should leak to proxy traps.
function TestNoSymbolsToTrap(handler) {
TestWithProxies(TestNoSymbolsToTrap2, handler)
}
function TestNoSymbolsToTrap2(create, handler) {
var p = create(handler)
var o = Object.create(p)
var symbol = Symbol("secret")
assertFalse(symbol in p)
assertFalse(symbol in o)
assertEquals(undefined, p[symbol])
assertEquals(undefined, o[symbol])
assertEquals(47, p[symbol] = 47)
assertEquals(47, o[symbol] = 47)
assertFalse(delete p[symbol])
assertTrue(delete o[symbol])
assertTrue(delete o[symbol])
assertFalse({}.hasOwnProperty.call(p, symbol))
assertFalse({}.hasOwnProperty.call(o, symbol))
assertEquals(undefined, Object.getOwnPropertyDescriptor(p, symbol))
assertEquals(undefined, Object.getOwnPropertyDescriptor(o, symbol))
}
TestNoSymbolsToTrap({
has: assertUnreachable,
hasOwn: assertUnreachable,
get: assertUnreachable,
set: assertUnreachable,
delete: assertUnreachable,
getPropertyDescriptor: assertUnreachable,
getOwnPropertyDescriptor: assertUnreachable,
defineProperty: assertUnreachable
})
// All symbols returned from proxy traps should be filtered.
function TestNoSymbolsFromTrap(handler) {
TestWithProxies(TestNoSymbolsFromTrap2, handler)
}
function TestNoSymbolsFromTrap2(create, handler) {
var p = create(handler)
var o = Object.create(p)
assertEquals(0, Object.keys(p).length)
assertEquals(0, Object.keys(o).length)
assertEquals(0, Object.getOwnPropertyNames(p).length)
assertEquals(0, Object.getOwnPropertyNames(o).length)
for (var n in p) assertUnreachable()
for (var n in o) assertUnreachable()
}
function MakeSymbolArray() {
return [Symbol(), Symbol("a")]
}
TestNoSymbolsFromTrap({
enumerate: MakeSymbolArray,
keys: MakeSymbolArray,
getPropertyNames: MakeSymbolArray,
getOwnPropertyNames: MakeSymbolArray
})
......@@ -5,22 +5,18 @@
// Flags: --harmony-proxies
// TODO(arv): Once proxies can intercept symbols, add more tests.
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 " + String(key));
if (key === 'x') return 1;
},
has: function(target, key) {
log.push("has " + String(key));
if (key === 'x') return true;
return false;
}
});
......@@ -30,27 +26,24 @@ 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(Symbol.unscopables)',
'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 " + String(key));
return undefined;
},
has: function(target, key) {
log.push("has " + String(key));
if (key === 'x') return true;
return false;
}
});
......@@ -60,8 +53,8 @@ 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(Symbol.unscopables)',
'get x'], log);
}
TestInconsistent();
......@@ -73,18 +66,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 +99,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 +125,10 @@ var global = this;
function TestGlobalShouldIgnoreUnscopables() {
global.x = 1;
var proxy = new Proxy({}, {
getPropertyDescriptor: function() {
get: function() {
assertUnreachable();
},
has: function() {
assertUnreachable();
}
});
......
......@@ -88,8 +88,6 @@
# Proxy tests rely on non ES6 version of Proxies
# TODO(neis,cbruni): figure out which Proxy tests can be reused
'harmony/proxies-example-membrane': [SKIP],
'harmony/proxies-symbols': [SKIP],
'harmony/proxies-with-unscopables': [SKIP],
'strong/load-proxy': [SKIP],
# Issue 3660: Replacing activated TurboFan frames by unoptimized code does
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment