Chromium Code Reviews| Index: test/mjsunit/harmony/proxy/proxy-setPrototypeOf.js |
| diff --git a/test/mjsunit/harmony/proxy/proxy-setPrototypeOf.js b/test/mjsunit/harmony/proxy/proxy-setPrototypeOf.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b77d7d71c70b36d7fef6953453f6e553eb7a455 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/proxy/proxy-setPrototypeOf.js |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 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-proxies |
| + |
| +var target = { target: 1 }; |
| +target.__proto__ = {}; |
| +var handler = { handler: 1 }; |
| +var proxy = new Proxy(target, handler); |
| + |
| +assertSame(Object.getPrototypeOf(proxy), target.__proto__ ); |
| + |
| +assertThrows(function() { Object.setPrototypeOf(proxy, undefined) }); |
| +assertThrows(function() { Object.setPrototypeOf(proxy, 1) }); |
| + |
| +var prototype = [1]; |
| +assertSame(proxy, Object.setPrototypeOf(proxy, prototype)); |
| +assertSame(prototype, Object.getPrototypeOf(proxy)); |
| +assertSame(prototype, Object.getPrototypeOf(target)); |
| + |
| +handler.setPrototypeOf = function(target, proto) { |
| + return false; |
| +}; |
| +assertThrows(function() { Object.setPrototypeOf(proxy, {a:1}) }); |
| + |
| +handler.setPrototypeOf = function(target, proto) { |
| + return undefined; |
| +}; |
| +assertThrows(function() { Object.setPrototypeOf(proxy, {a:2}) }); |
| + |
| +handler.setPrototypeOf = function(proto) {A}; |
| +assertThrows(function() { Object.setPrototypeOf(proxy, {a:3}) }); |
| + |
| +handler.setPrototypeOf = function(target, proto) { |
| + throw Exception(); |
| +}; |
| +assertThrows(function() { Object.setPrototypeOf(proxy, {a:4}) }); |
| + |
| +var seen_prototype; |
| +var seen_target; |
| +handler.setPrototypeOf = function(target, proto) { |
| + seen_target = target; |
| + seen_prototype = proto; |
| + return true; |
| +} |
| +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__ ); |
| + |
| +prototype = [2,3]; |
| +assertSame(proxy2, Object.setPrototypeOf(proxy2, prototype)); |
| +assertSame(prototype, Object.getPrototypeOf(proxy2)); |
| +assertSame(prototype, Object.getPrototypeOf(target)); |
|
neis
2015/11/16 19:09:54
For consistency, can you name this file proxies-se
|