OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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: --allow-natives-syntax |
| 6 |
| 7 // Test Reflect.apply with wrong number of arguments. |
| 8 (function() { |
| 9 "use strict"; |
| 10 function bar() { return this; } |
| 11 function foo() { return Reflect.apply(bar); } |
| 12 |
| 13 assertThrows(foo); |
| 14 assertThrows(foo); |
| 15 %OptimizeFunctionOnNextCall(foo); |
| 16 assertThrows(foo); |
| 17 })(); |
| 18 (function() { |
| 19 "use strict"; |
| 20 function bar() { return this; } |
| 21 function foo() { return Reflect.apply(bar, this); } |
| 22 |
| 23 assertThrows(foo); |
| 24 assertThrows(foo); |
| 25 %OptimizeFunctionOnNextCall(foo); |
| 26 assertThrows(foo); |
| 27 })(); |
| 28 (function() { |
| 29 "use strict"; |
| 30 function bar() { return this; } |
| 31 function foo() { return Reflect.apply(bar, this, arguments, this); } |
| 32 |
| 33 assertEquals(42, foo.call(42)); |
| 34 assertEquals(42, foo.call(42)); |
| 35 %OptimizeFunctionOnNextCall(foo); |
| 36 assertEquals(42, foo.call(42)); |
| 37 })(); |
| 38 |
| 39 // Test Reflect.apply within try/catch. |
| 40 (function() { |
| 41 "use strict"; |
| 42 function foo(bar) { |
| 43 try { |
| 44 return Reflect.apply(bar, bar, arguments); |
| 45 } catch (e) { |
| 46 return 1; |
| 47 } |
| 48 } |
| 49 |
| 50 assertEquals(1, foo()); |
| 51 assertEquals(1, foo()); |
| 52 %OptimizeFunctionOnNextCall(foo); |
| 53 assertEquals(1, foo()); |
| 54 })(); |
| 55 (function() { |
| 56 "use strict"; |
| 57 function foo(bar) { |
| 58 try { |
| 59 return Reflect.apply(bar, bar, bar); |
| 60 } catch (e) { |
| 61 return 1; |
| 62 } |
| 63 } |
| 64 |
| 65 assertEquals(1, foo()); |
| 66 assertEquals(1, foo()); |
| 67 %OptimizeFunctionOnNextCall(foo); |
| 68 assertEquals(1, foo()); |
| 69 })(); |
| 70 |
| 71 // Test proper order of callable check and array-like iteration |
| 72 // in Reflect.apply. |
| 73 (function() { |
| 74 var dummy_length_counter = 0; |
| 75 var dummy = { get length() { ++dummy_length_counter; return 0; } }; |
| 76 |
| 77 function foo() { |
| 78 return Reflect.apply(undefined, this, dummy); |
| 79 } |
| 80 |
| 81 assertThrows(foo, TypeError); |
| 82 assertThrows(foo, TypeError); |
| 83 %OptimizeFunctionOnNextCall(foo); |
| 84 assertThrows(foo, TypeError); |
| 85 assertEquals(0, dummy_length_counter); |
| 86 })(); |
| 87 (function() { |
| 88 var dummy_length_counter = 0; |
| 89 var dummy = { get length() { ++dummy_length_counter; return 0; } }; |
| 90 |
| 91 function foo() { |
| 92 return Reflect.apply(null, this, dummy); |
| 93 } |
| 94 |
| 95 assertThrows(foo, TypeError); |
| 96 assertThrows(foo, TypeError); |
| 97 %OptimizeFunctionOnNextCall(foo); |
| 98 assertThrows(foo, TypeError); |
| 99 assertEquals(0, dummy_length_counter); |
| 100 })(); |
| 101 (function() { |
| 102 var dummy_length_counter = 0; |
| 103 var dummy = { get length() { ++dummy_length_counter; return 0; } }; |
| 104 |
| 105 function foo() { |
| 106 return Reflect.apply(null, this, dummy); |
| 107 } |
| 108 |
| 109 assertThrows(foo, TypeError); |
| 110 assertThrows(foo, TypeError); |
| 111 %OptimizeFunctionOnNextCall(foo); |
| 112 assertThrows(foo, TypeError); |
| 113 assertEquals(0, dummy_length_counter); |
| 114 })(); |
OLD | NEW |