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