Commit f2cce3c4 authored by yangguo's avatar yangguo Committed by Commit bot

Check for null and undefined when getting type name for stack trace.

R=svenpanne@chromium.org
BUG=v8:3718
LOG=N

Review URL: https://codereview.chromium.org/1164933005

Cr-Commit-Position: refs/heads/master@{#28840}
parent dd854449
......@@ -908,6 +908,7 @@ function FormatStackTrace(obj, raw_stack) {
function GetTypeName(receiver, requireConstructor) {
if (IS_NULL_OR_UNDEFINED(receiver)) return null;
var constructor = receiver.constructor;
if (!constructor) {
return requireConstructor ? null :
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
function getTypeName(receiver) {
Error.prepareStackTrace = function(e, stack) { return stack; }
var stack = (function() { return new Error().stack; }).call(receiver);
Error.prepareStackTrace = undefined;
return stack[0].getTypeName();
}
assertNull(getTypeName(undefined));
assertNull(getTypeName(null));
assertEquals("Number", getTypeName(1));
assertEquals("String", getTypeName(""));
assertEquals("Boolean", getTypeName(false));
assertEquals("Object", getTypeName({}));
assertEquals("Array", getTypeName([]));
assertEquals("Custom", getTypeName(new (function Custom(){})()));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment