Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --harmony-proxies | |
| 6 | |
| 7 var target = { target: 1 }; | |
| 8 target.__proto__ = {}; | |
| 9 var handler = { handler: 1 }; | |
| 10 var proxy = new Proxy(target, handler); | |
| 11 | |
| 12 assertSame(Object.getPrototypeOf(proxy), target.__proto__ ); | |
| 13 | |
| 14 assertThrows(function() { Object.setPrototypeOf(proxy, undefined) }); | |
| 15 assertThrows(function() { Object.setPrototypeOf(proxy, 1) }); | |
| 16 | |
| 17 var prototype = [1]; | |
| 18 assertSame(proxy, Object.setPrototypeOf(proxy, prototype)); | |
| 19 assertSame(prototype, Object.getPrototypeOf(proxy)); | |
| 20 assertSame(prototype, Object.getPrototypeOf(target)); | |
| 21 | |
| 22 handler.setPrototypeOf = function(target, proto) { | |
| 23 return false; | |
| 24 }; | |
| 25 assertThrows(function() { Object.setPrototypeOf(proxy, {a:1}) }); | |
| 26 | |
| 27 handler.setPrototypeOf = function(target, proto) { | |
| 28 return undefined; | |
| 29 }; | |
| 30 assertThrows(function() { Object.setPrototypeOf(proxy, {a:2}) }); | |
| 31 | |
| 32 handler.setPrototypeOf = function(proto) {A}; | |
| 33 assertThrows(function() { Object.setPrototypeOf(proxy, {a:3}) }); | |
| 34 | |
| 35 handler.setPrototypeOf = function(target, proto) { | |
| 36 throw Exception(); | |
| 37 }; | |
| 38 assertThrows(function() { Object.setPrototypeOf(proxy, {a:4}) }); | |
| 39 | |
| 40 var seen_prototype; | |
| 41 var seen_target; | |
| 42 handler.setPrototypeOf = function(target, proto) { | |
| 43 seen_target = target; | |
| 44 seen_prototype = proto; | |
| 45 return true; | |
| 46 } | |
| 47 assertSame(Object.setPrototypeOf(proxy, {a:5}), proxy); | |
| 48 assertSame(target, seen_target); | |
| 49 assertEquals({a:5}, seen_prototype); | |
| 50 | |
| 51 // Target is a Proxy: | |
| 52 var target2 = new Proxy(target, {}); | |
| 53 var proxy2 = new Proxy(target2, {}); | |
| 54 assertSame(Object.getPrototypeOf(proxy2), target.__proto__ ); | |
| 55 | |
| 56 prototype = [2,3]; | |
| 57 assertSame(proxy2, Object.setPrototypeOf(proxy2, prototype)); | |
| 58 assertSame(prototype, Object.getPrototypeOf(proxy2)); | |
| 59 assertSame(prototype, Object.getPrototypeOf(target)); | |
|
neis
2015/11/16 19:09:54
For consistency, can you name this file proxies-se
| |
| OLD | NEW |