[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:
parent
39ed694bbd
commit
8c32ef6ee8
@ -1869,7 +1869,7 @@ void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
|
||||
|
||||
|
||||
void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
|
||||
UNIMPLEMENTED();
|
||||
execution_result()->SetResultInRegister(Register::function_closure());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user