Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 | "use strict"; |
| 6 | |
| 7 | function getTypeName(receiver) { |
| 8 | Error.prepareStackTrace = function(e, stack) { return stack; } |
| 9 | var stack = (function() { return new Error().stack; }).call(receiver); |
| 10 | Error.prepareStackTrace = undefined; |
| 11 | return stack[0].getTypeName(); |
| 12 | } |
| 13 | |
| 14 | assertNull(getTypeName(undefined)); |
| 15 | assertNull(getTypeName(null)); |
| 16 | assertEquals("Number", getTypeName(1)); |
| 17 | assertEquals("String", getTypeName("")); |
| 18 | assertEquals("Boolean", getTypeName(false)); |
| 19 | assertEquals("Object", getTypeName({})); |
| 20 | assertEquals("Array", getTypeName([])); |
| 21 | assertEquals("Custom", getTypeName(new (function Custom(){})())); |