[runtime] [proxies] adding tests for uncovered branches

fly-by fix of Proxy [[Construct]] on mips.

BUG=v8:1543
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#32758}
This commit is contained in:
cbruni 2015-12-10 07:34:49 -08:00 committed by Commit bot
parent 7ae5a4d8f7
commit c20156c550
4 changed files with 89 additions and 11 deletions

View File

@ -15074,7 +15074,7 @@ Maybe<bool> JSProxy::SetPrototype(Handle<JSProxy> proxy, Handle<Object> value,
// throw a TypeError exception.
if (bool_trap_result && !value->SameValue(*target_proto)) {
isolate->Throw(*isolate->factory()->NewTypeError(
MessageTemplate::kProxyTrapViolatesInvariant, target));
MessageTemplate::kProxyTrapViolatesInvariant, trap_name));
return Nothing<bool>();
}
// 13. Return booleanTrapResult.

View File

@ -23,7 +23,16 @@ assertSame(target, g_target);
assertEquals("foo", g_name);
assertEquals(desc, g_desc);
// Check specific steps in the spec:
// Check specific steps in the spec
// Step 4: revoked handler
var pair = Proxy.revocable(target, handler);
Object.defineProperty(proxy, "foo2", desc);
assertSame(target, g_target);
assertEquals("foo2", g_name);
assertEquals(desc, g_desc);
pair.revoke();
assertThrows('Object.defineProperty(pair.proxy, "bar", desc);', TypeError);
// Step 6: Trap isn't callable.
handler.defineProperty = 1;

View File

@ -37,6 +37,12 @@ function TestForIn(receiver, expected) {
TestForIn(proxy, ["foo", "bar"]);
// Test revoked proxy.
var pair = Proxy.revocable(target, handler);
TestForIn(pair.proxy, ["foo", "bar"]);
pair.revoke();
assertThrows(()=>{ TestForIn(pair.proxy, ["foo", "bar"]) }, TypeError);
// Properly call traps on proxies on the prototype chain.
var receiver = {
"receiver_one": 1

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-proxies
// Flags: --harmony-proxies --harmony-reflect
var target = { target: 1 };
target.__proto__ = {};
@ -11,6 +11,7 @@ var proxy = new Proxy(target, handler);
assertSame(Object.getPrototypeOf(proxy), target.__proto__ );
assertThrows(function() { Object.setPrototypeOf(proxy, undefined) }, TypeError);
assertThrows(function() { Object.setPrototypeOf(proxy, 1) }, TypeError);
@ -19,6 +20,12 @@ assertSame(proxy, Object.setPrototypeOf(proxy, prototype));
assertSame(prototype, Object.getPrototypeOf(proxy));
assertSame(prototype, Object.getPrototypeOf(target));
var pair = Proxy.revocable(target, handler);
assertSame(pair.proxy, Object.setPrototypeOf(pair.proxy, prototype));
assertSame(prototype, Object.getPrototypeOf(pair.proxy));
pair.revoke();
assertThrows('Object.setPrototypeOf(pair.proxy, prototype)', TypeError);
handler.setPrototypeOf = function(target, proto) {
return false;
};
@ -48,12 +55,68 @@ assertSame(Object.setPrototypeOf(proxy, {a:5}), proxy);
assertSame(target, seen_target);
assertEquals({a:5}, seen_prototype);
// Target is a Proxy:
var target2 = new Proxy(target, {});
var proxy2 = new Proxy(target2, {});
assertSame(Object.getPrototypeOf(proxy2), target.__proto__ );
(function setPrototypeProxyTarget() {
var target = { target: 1 };
target.__proto__ = {};
var handler = {};
var handler2 = {};
var target2 = new Proxy(target, handler2);
var proxy2 = new Proxy(target2, handler);
assertSame(Object.getPrototypeOf(proxy2), target.__proto__ );
prototype = [2,3];
assertSame(proxy2, Object.setPrototypeOf(proxy2, prototype));
assertSame(prototype, Object.getPrototypeOf(proxy2));
assertSame(prototype, Object.getPrototypeOf(target));
var prototype = [2,3];
assertSame(proxy2, Object.setPrototypeOf(proxy2, prototype));
assertSame(prototype, Object.getPrototypeOf(proxy2));
assertSame(prototype, Object.getPrototypeOf(target));
})();
(function testProxyTrapInconsistent() {
var target = { target: 1 };
target.__proto__ = {};
var handler = {};
var handler2 = {
};
var target2 = new Proxy(target, handler);
var proxy2 = new Proxy(target2, handler2);
// If the final target is extensible we can set any prototype.
var prototype = [1];
Reflect.setPrototypeOf(proxy2, prototype);
assertSame(prototype, Reflect.getPrototypeOf(target));
handler2.setPrototypeOf = function(target, value) {
Reflect.setPrototypeOf(target, value);
return true;
};
prototype = [2];
Reflect.setPrototypeOf(proxy2, prototype);
assertSame(prototype, Reflect.getPrototypeOf(target));
// Prevent getting the target's prototype used to check the invariant.
var gotPrototype = false;
handler.getPrototypeOf = function() {
gotPrototype = true;
throw TypeError()
};
// If the target is extensible we do not check the invariant.
prototype = [3];
Reflect.setPrototypeOf(proxy2, prototype);
assertFalse(gotPrototype);
assertSame(prototype, Reflect.getPrototypeOf(target));
// Changing the prototype of a non-extensible target will trigger the
// invariant-check and throw in the above handler.
Reflect.preventExtensions(target);
assertThrows(() => {Reflect.setPrototypeOf(proxy2, [4])}, TypeError);
assertTrue(gotPrototype);
assertEquals([3], Reflect.getPrototypeOf(target));
// Setting the prototype of a non-extensible target is fine if the prototype
// doesn't change.
delete handler.getPrototypeOf;
Reflect.setPrototypeOf(proxy2, prototype);
// Changing the prototype will throw.
prototype = [5];
assertThrows(() => {Reflect.setPrototypeOf(proxy2, prototype)}, TypeError);
})();