Commit b065ed47 authored by Josh Wolfe's avatar Josh Wolfe Committed by Commit Bot

Support Function::SetName() with --harmony-function-tostring

This is used in chromium for html attribute event handlers.

See blink layout test fast/events/event-function-toString.html

Bug: v8:4958
Change-Id: Ib3d88af834bbb62b4ccd4683eda743d92064b075
Reviewed-on: https://chromium-review.googlesource.com/837641
Commit-Queue: Josh Wolfe <jwolfe@igalia.com>
Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50460}
parent 53a367ec
...@@ -13718,8 +13718,11 @@ Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony( ...@@ -13718,8 +13718,11 @@ Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony(
script_source, start_pos, shared->end_position()); script_source, start_pos, shared->end_position());
if (!shared->is_wrapped()) return source; if (!shared->is_wrapped()) return source;
DCHECK(!shared->name_should_print_as_anonymous());
IncrementalStringBuilder builder(isolate); IncrementalStringBuilder builder(isolate);
builder.AppendCString("function ("); builder.AppendCString("function ");
builder.AppendString(Handle<String>(shared->name(), isolate));
builder.AppendCString("(");
Handle<FixedArray> args(Script::cast(shared->script())->wrapped_arguments()); Handle<FixedArray> args(Script::cast(shared->script())->wrapped_arguments());
int argc = args->length(); int argc = args->length();
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
......
...@@ -727,6 +727,34 @@ void TestCompileFunctionInContextToStringImpl() { ...@@ -727,6 +727,34 @@ void TestCompileFunctionInContextToStringImpl() {
"}"); "}");
CHECK(expected->Equals(env.local(), result).FromJust()); CHECK(expected->Equals(env.local(), result).FromJust());
} }
// With a name:
{
v8::ScriptOrigin origin(v8_str("test"), v8_int(17), v8_int(31));
v8::ScriptCompiler::Source script_source(v8_str("return 0"), origin);
v8::TryCatch try_catch(CcTest::isolate());
v8::MaybeLocal<v8::Function> maybe_fun =
v8::ScriptCompiler::CompileFunctionInContext(
env.local(), &script_source, 0, nullptr, 0, nullptr);
CHECK_NOT_CAUGHT(env.local(), try_catch,
"v8::ScriptCompiler::CompileFunctionInContext");
v8::Local<v8::Function> fun = maybe_fun.ToLocalChecked();
CHECK(!fun.IsEmpty());
CHECK(!try_catch.HasCaught());
fun->SetName(v8_str("onclick"));
v8::Local<v8::String> result =
fun->ToString(env.local()).ToLocalChecked();
v8::Local<v8::String> expected = v8_str(
"function onclick() {\n"
"return 0\n"
"}");
CHECK(expected->Equals(env.local(), result).FromJust());
}
} }
#undef CHECK_NOT_CAUGHT #undef CHECK_NOT_CAUGHT
} }
......
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