Commit 045fa997 authored by adamk's avatar adamk Committed by Commit bot

Handle ES2015 Function.name in CallSite::GetMethodName

CallSite depends on using the function name to get ahold of the property
name from which an exception was thrown. This fix properly handles the
ES2015 names for getters and setters. The new tests pass both with
--harmony-function-name off and on.

BUG=v8:3699
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#34469}
parent fe6f290c
......@@ -236,10 +236,21 @@ Handle<Object> CallSite::GetMethodName() {
Handle<Object> function_name(fun_->shared()->name(), isolate_);
if (function_name->IsName()) {
Handle<Name> name = Handle<Name>::cast(function_name);
// ES2015 gives getters and setters name prefixes which must
// be stripped to find the property name.
if (name->IsString() && FLAG_harmony_function_name) {
Handle<String> name_string = Handle<String>::cast(name);
if (name_string->IsUtf8EqualTo(CStrVector("get "), true) ||
name_string->IsUtf8EqualTo(CStrVector("set "), true)) {
name = isolate_->factory()->NewProperSubString(name_string, 4,
name_string->length());
}
}
if (CheckMethodName(isolate_, obj, name, fun_,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR))
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) {
return name;
}
}
HandleScope outer_scope(isolate_);
Handle<Object> result;
......
......@@ -2,19 +2,25 @@
// 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(); } };
var o = {
f: function() { throw new Error(); },
get j() { o.h(); },
set k(_) { o.j; },
};
o.g1 = function() { o.f() }
o.g2 = o.g1;
o.h = function() { o.g1() }
Error.prepareStackTrace = function(e, frames) { return frames; }
try {
o.h();
o.k = 42;
} catch (e) {
Error.prepareStackTrace = function(e, frames) { return frames; };
var frames = e.stack;
Error.prepareStackTrace = undefined;
assertEquals("f", frames[0].getMethodName());
assertEquals(null, frames[1].getMethodName());
assertEquals("h", frames[2].getMethodName());
assertEquals(null, frames[3].getMethodName());
assertEquals("j", frames[3].getMethodName());
assertEquals("k", frames[4].getMethodName());
assertEquals(null, frames[5].getMethodName());
}
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