Commit 8c32ef6e authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Add support for VisitThisFunction.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#31859}
parent 39ed694b
...@@ -1869,7 +1869,7 @@ void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { ...@@ -1869,7 +1869,7 @@ void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
UNIMPLEMENTED(); execution_result()->SetResultInRegister(Register::function_closure());
} }
......
...@@ -5147,6 +5147,47 @@ TEST(DeadCodeRemoval) { ...@@ -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 interpreter
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -2919,6 +2919,20 @@ TEST(InterpreterSloppyThis) { ...@@ -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 interpreter
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
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