[Interpreter] Add support for VisitThisFunction.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#31859}
This commit is contained in:
rmcilroy 2015-11-06 07:00:26 -08:00 committed by Commit bot
parent 39ed694bbd
commit 8c32ef6ee8
3 changed files with 56 additions and 1 deletions

View File

@ -1869,7 +1869,7 @@ void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
UNIMPLEMENTED();
execution_result()->SetResultInRegister(Register::function_closure());
}

View File

@ -5147,6 +5147,47 @@ TEST(DeadCodeRemoval) {
}
}
TEST(ThisFunction) {
InitializedHandleScope handle_scope;
BytecodeGeneratorHelper helper;
int closure = Register::function_closure().index();
ExpectedSnippet<int> snippets[] = {
{"var f;\n f = function f() { }",
1 * kPointerSize,
1,
9,
{
B(LdaTheHole), //
B(Star), R(0), //
B(Ldar), R(closure), //
B(Star), R(0), //
B(LdaUndefined), //
B(Return), //
}},
{"var f;\n f = function f() { return f; }",
1 * kPointerSize,
1,
10,
{
B(LdaTheHole), //
B(Star), R(0), //
B(Ldar), R(closure), //
B(Star), R(0), //
B(Ldar), R(0), //
B(Return), //
}},
};
for (size_t i = 0; i < arraysize(snippets); i++) {
Handle<BytecodeArray> bytecode_array =
helper.MakeBytecodeForFunction(snippets[i].code_snippet);
CheckBytecodeArrayEqual(snippets[i], bytecode_array);
}
}
} // namespace interpreter
} // namespace internal
} // namespace v8

View File

@ -2919,6 +2919,20 @@ TEST(InterpreterSloppyThis) {
}
}
TEST(InterpreterThisFunction) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
i::Factory* factory = isolate->factory();
InterpreterTester tester(handles.main_isolate(),
"var f;\n f = function f() { return f.name; }");
auto callable = tester.GetCallable<>();
Handle<i::Object> return_value = callable().ToHandleChecked();
CHECK(return_value->SameValue(*factory->NewStringFromStaticChars("f")));
}
} // namespace interpreter
} // namespace internal
} // namespace v8