Commit 7c160afd authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Add test for sloppy mode receiver replacement.

Adds a test that the receiver for sloppy mode functions is replaced with
the global proxy when called with an undefined receiever.

BUG=v8:4280
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#31854}
parent 84c961b7
......@@ -924,9 +924,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -948,9 +948,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -642,9 +642,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -922,9 +922,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -918,9 +918,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -925,9 +925,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -712,9 +712,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -642,9 +642,6 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
// - Support profiler (specifically profiling_counter).
// - Call ProfileEntryHookStub when isolate has a function_entry_hook.
// - Allow simulator stop operations if FLAG_stop_at is set.
// - Deal with sloppy mode functions which need to replace the
// receiver with the global proxy when called as functions (without an
// explicit receiver object).
// - Code aging of the BytecodeArray object.
// Perform stack guard check.
......
......@@ -2885,6 +2885,40 @@ TEST(InterpreterSwitch) {
}
}
TEST(InterpreterSloppyThis) {
HandleAndZoneScope handles;
i::Isolate* isolate = handles.main_isolate();
i::Factory* factory = isolate->factory();
std::pair<const char*, Handle<Object>> sloppy_this[] = {
std::make_pair("var global_val = 100;\n"
"function f() { return this.global_val; }\n",
handle(Smi::FromInt(100), isolate)),
std::make_pair("var global_val = 110;\n"
"function g() { return this.global_val; };"
"function f() { return g(); }\n",
handle(Smi::FromInt(110), isolate)),
std::make_pair("var global_val = 110;\n"
"function g() { return this.global_val };"
"function f() { 'use strict'; return g(); }\n",
handle(Smi::FromInt(110), isolate)),
std::make_pair("function f() { 'use strict'; return this; }\n",
factory->undefined_value()),
std::make_pair("function g() { 'use strict'; return this; };"
"function f() { return g(); }\n",
factory->undefined_value()),
};
for (size_t i = 0; i < arraysize(sloppy_this); i++) {
InterpreterTester tester(handles.main_isolate(), sloppy_this[i].first);
auto callable = tester.GetCallable<>();
Handle<i::Object> return_value = callable().ToHandleChecked();
CHECK(return_value->SameValue(*sloppy_this[i].second));
}
}
} // namespace interpreter
} // namespace internal
} // 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