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 --harmony-reflect 6 7(function testNonCallable() { 8 var proxy = new Proxy({},{}); 9 assertThrows(function(){ proxy() }, TypeError); 10 11 var proxy2 = new Proxy(proxy, {}); 12 assertThrows(function(){ proxy2() }, TypeError); 13})(); 14 15(function testCallProxyFallbackNoArguments() { 16 var called = false; 17 var target = function() { 18 called = true; 19 } 20 var proxy = new Proxy(target, {}); 21 assertFalse(called); 22 proxy(); 23 assertTrue(called); 24 25 called = false; 26 var proxy2 = new Proxy(proxy, {}); 27 assertFalse(called); 28 proxy2(); 29 assertTrue(called); 30})(); 31 32(function testCallProxyFallback1Argument() { 33 var called = false; 34 var target = function(a) { 35 called = true; 36 assertEquals('1', a); 37 } 38 var proxy = new Proxy(target, {}); 39 assertFalse(called); 40 proxy('1'); 41 assertTrue(called); 42})(); 43 44(function testCallProxyFallback2Arguments() { 45 var called = false; 46 var target = function(a, b) { 47 called = true; 48 assertEquals('1', a); 49 assertEquals('2', b); 50 } 51 var proxy = new Proxy(target, {}); 52 assertFalse(called); 53 proxy('1', '2'); 54 assertTrue(called); 55})(); 56 57(function testCallProxyFallbackChangedReceiver() { 58 var apply_receiver = {receiver:true}; 59 var seen_receiver = undefined; 60 var target = function() { 61 seen_receiver = this; 62 } 63 var proxy = new Proxy(target, {}); 64 assertEquals(undefined, seen_receiver); 65 Reflect.apply(proxy, apply_receiver, [1,2,3,4]); 66 assertSame(apply_receiver, seen_receiver); 67})(); 68 69(function testCallProxyTrap() { 70 var called_target = false; 71 var called_handler = false; 72 var target = function(a, b) { 73 called_target = true; 74 assertEquals(1, a); 75 assertEquals(2, b); 76 } 77 var handler = { 78 apply: function(target, this_arg, args) { 79 target.apply(this_arg, args); 80 called_handler = true; 81 } 82 } 83 var proxy = new Proxy(target, handler); 84 assertFalse(called_target); 85 assertFalse(called_handler); 86 Reflect.apply(proxy, {rec:1}, [1,2]); 87 assertTrue(called_target); 88 assertTrue(called_handler); 89})(); 90