Commit 953874e9 authored by verwaest's avatar verwaest Committed by Commit bot

Use displayName in Error.stack rendering if present.

BUG=v8:4761
LOG=y

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

Cr-Commit-Position: refs/heads/master@{#34105}
parent 3e36babe
......@@ -4480,7 +4480,7 @@ Local<Value> Function::GetDisplayName() const {
}
auto func = i::Handle<i::JSFunction>::cast(self);
i::Handle<i::String> property_name =
isolate->factory()->NewStringFromStaticChars("displayName");
isolate->factory()->display_name_string();
i::Handle<i::Object> value =
i::JSReceiver::GetDataProperty(func, property_name);
if (value->IsString()) {
......
......@@ -618,6 +618,11 @@ function CallSiteGetFunctionName() {
return %CallSiteGetFunctionNameRT(this);
}
function CallSiteGetDebugName() {
// See if the function knows its own name
return %CallSiteGetDebugNameRT(this);
}
function CallSiteGetMethodName() {
// See if we can find a unique property on the receiver that holds
// this function.
......@@ -676,10 +681,13 @@ function CallSiteToString() {
var line = "";
var functionName = this.getFunctionName();
var addSuffix = true;
var debugName = this.getDebugName();
var isConstructor = this.isConstructor();
var isMethodCall = !(this.isToplevel() || isConstructor);
if (isMethodCall) {
if (debugName) {
if (isConstructor) line += "new ";
line += debugName;
} else if (isMethodCall) {
var typeName = GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), true);
var methodName = this.getMethodName();
if (functionName) {
......@@ -700,13 +708,9 @@ function CallSiteToString() {
} else if (functionName) {
line += functionName;
} else {
line += fileLocation;
addSuffix = false;
}
if (addSuffix) {
line += " (" + fileLocation + ")";
return line + fileLocation;
}
return line;
return line + " (" + fileLocation + ")";
}
utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [
......@@ -718,6 +722,7 @@ utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [
"getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL,
"getFunction", CallSiteGetFunction,
"getFunctionName", CallSiteGetFunctionName,
"getDebugName", CallSiteGetDebugName,
"getMethodName", CallSiteGetMethodName,
"getFileName", CallSiteGetFileName,
"getLineNumber", CallSiteGetLineNumber,
......
......@@ -191,6 +191,14 @@ Handle<Object> CallSite::GetFunctionName() {
return isolate_->factory()->null_value();
}
Handle<Object> CallSite::GetDebugName() {
Handle<Object> name = JSReceiver::GetDataProperty(
fun_, isolate_->factory()->display_name_string());
if (name->IsString() && String::cast(*name)->length() != 0) {
return Handle<String>::cast(name);
}
return isolate_->factory()->null_value();
}
Handle<Object> CallSite::GetScriptNameOrSourceUrl() {
Handle<Object> script_obj(fun_->shared()->script(), isolate_);
......
......@@ -51,6 +51,7 @@ class CallSite {
Handle<Object> GetFileName();
Handle<Object> GetFunctionName();
Handle<Object> GetDebugName();
Handle<Object> GetScriptNameOrSourceUrl();
Handle<Object> GetMethodName();
// Return 1-based line number, including line offset.
......
......@@ -348,6 +348,7 @@ static inline Object* ReturnBoolean(bool value, Isolate* isolate) {
CALLSITE_GET(GetFileName, ReturnDereferencedHandle)
CALLSITE_GET(GetFunctionName, ReturnDereferencedHandle)
CALLSITE_GET(GetDebugName, ReturnDereferencedHandle)
CALLSITE_GET(GetScriptNameOrSourceUrl, ReturnDereferencedHandle)
CALLSITE_GET(GetMethodName, ReturnDereferencedHandle)
CALLSITE_GET(GetLineNumber, ReturnPositiveNumberOrNull)
......
......@@ -294,7 +294,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_I18N(F)
#endif
#define FOR_EACH_INTRINSIC_INTERNAL(F) \
F(CheckIsBootstrapping, 0, 1) \
F(ExportFromRuntime, 1, 1) \
......@@ -325,6 +324,7 @@ namespace internal {
F(FormatMessageString, 4, 1) \
F(CallSiteGetFileNameRT, 1, 1) \
F(CallSiteGetFunctionNameRT, 1, 1) \
F(CallSiteGetDebugNameRT, 1, 1) \
F(CallSiteGetScriptNameOrSourceUrlRT, 1, 1) \
F(CallSiteGetMethodNameRT, 1, 1) \
F(CallSiteGetLineNumberRT, 1, 1) \
......@@ -342,7 +342,6 @@ namespace internal {
F(IncrementUseCounter, 1, 1) \
F(GetAndResetRuntimeCallStats, 0, 1)
#define FOR_EACH_INTRINSIC_JSON(F) \
F(QuoteJSONString, 1, 1) \
F(BasicJSONStringify, 1, 1) \
......
// Copyright 2016 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.
var o = { f: function() { throw new Error(); } };
o.g1 = function() { o.f() }
o.g2 = o.g1;
o.h = function() { o.g1() }
o.f.displayName = "MySpecialFunction";
try {
o.h();
} catch (e) {
assertTrue(e.stack.indexOf("MySpecialFunction") != -1);
}
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