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 // Test access of the new.target value in functions that also allocate local |
| 6 // function contexts of varying sizes, making sure the value is not clobbered. |
| 7 |
| 8 function makeFun(n) { |
| 9 var source = "(function f" + n + "() { "; |
| 10 for (var i = 0; i < n; ++i) source += "var v" + i + "; "; |
| 11 source += "(function() { 0 "; |
| 12 for (var i = 0; i < n; ++i) source += "+ v" + i + " "; |
| 13 source += "})(); return { value: new.target }; })"; |
| 14 return eval(source); |
| 15 } |
| 16 |
| 17 // Exercise fast case. |
| 18 var a = makeFun(4); |
| 19 assertEquals(a, new a().value); |
| 20 assertEquals(undefined, a().value); |
| 21 |
| 22 // Exercise slow case. |
| 23 var b = makeFun(128); |
| 24 assertEquals(b, new b().value); |
| 25 assertEquals(undefined, b().value); |
OLD | NEW |