Commit e0ec097b authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: Resolve references to "this" the same way as normal variables

Port 18619d35

Original commit message:
Make the parser handle references to "this" as unresolved variables, so the
same logic as for the rest of function parameters is used for the receiver.
Minor additions to the code generation handle copying the receiver to the
context, along with the rest of the function parameters.

Based on work by Adrian Perez de Castro <aperez@igalia.com>.

R=wingo@igalia.com, dstence@us.ibm.com,  michael_dawson@ca.ibm.com
BUG=

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

Cr-Commit-Position: refs/heads/master@{#28272}
parent d4ea33f4
...@@ -124,7 +124,7 @@ void FullCodeGenerator::Generate() { ...@@ -124,7 +124,7 @@ void FullCodeGenerator::Generate() {
// global proxy when called as functions (without an explicit receiver // global proxy when called as functions (without an explicit receiver
// object). // object).
if (is_sloppy(info->language_mode()) && !info->is_native() && if (is_sloppy(info->language_mode()) && !info->is_native() &&
info->MayUseThis()) { info->MayUseThis() && info->scope()->has_this_declaration()) {
Label ok; Label ok;
int receiver_offset = info->scope()->num_parameters() * kPointerSize; int receiver_offset = info->scope()->num_parameters() * kPointerSize;
__ LoadP(r5, MemOperand(sp, receiver_offset), r0); __ LoadP(r5, MemOperand(sp, receiver_offset), r0);
...@@ -221,8 +221,9 @@ void FullCodeGenerator::Generate() { ...@@ -221,8 +221,9 @@ void FullCodeGenerator::Generate() {
__ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset)); __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset));
// Copy any necessary parameters into the context. // Copy any necessary parameters into the context.
int num_parameters = info->scope()->num_parameters(); int num_parameters = info->scope()->num_parameters();
for (int i = 0; i < num_parameters; i++) { int first_parameter = info->scope()->has_this_declaration() ? -1 : 0;
Variable* var = scope()->parameter(i); for (int i = first_parameter; i < num_parameters; i++) {
Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
if (var->IsContextSlot()) { if (var->IsContextSlot()) {
int parameter_offset = StandardFrameConstants::kCallerSPOffset + int parameter_offset = StandardFrameConstants::kCallerSPOffset +
(num_parameters - 1 - i) * kPointerSize; (num_parameters - 1 - i) * kPointerSize;
...@@ -3049,8 +3050,9 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { ...@@ -3049,8 +3050,9 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
__ LoadP(r7, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); __ LoadP(r7, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
// r6: the receiver of the enclosing function. // r6: the receiver of the enclosing function.
int receiver_offset = 2 + info_->scope()->num_parameters(); Variable* this_var = scope()->LookupThis();
__ LoadP(r6, MemOperand(fp, receiver_offset * kPointerSize), r0); DCHECK_NOT_NULL(this_var);
GetVar(r6, this_var);
// r5: language mode. // r5: language mode.
__ LoadSmiLiteral(r5, Smi::FromInt(language_mode())); __ LoadSmiLiteral(r5, Smi::FromInt(language_mode()));
......
...@@ -119,7 +119,7 @@ bool LCodeGen::GeneratePrologue() { ...@@ -119,7 +119,7 @@ bool LCodeGen::GeneratePrologue() {
// global proxy when called as functions (without an explicit receiver // global proxy when called as functions (without an explicit receiver
// object). // object).
if (is_sloppy(info_->language_mode()) && info()->MayUseThis() && if (is_sloppy(info_->language_mode()) && info()->MayUseThis() &&
!info_->is_native()) { !info_->is_native() && info_->scope()->has_this_declaration()) {
Label ok; Label ok;
int receiver_offset = info_->scope()->num_parameters() * kPointerSize; int receiver_offset = info_->scope()->num_parameters() * kPointerSize;
__ LoadP(r5, MemOperand(sp, receiver_offset)); __ LoadP(r5, MemOperand(sp, receiver_offset));
...@@ -199,8 +199,9 @@ bool LCodeGen::GeneratePrologue() { ...@@ -199,8 +199,9 @@ bool LCodeGen::GeneratePrologue() {
__ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset)); __ StoreP(r3, MemOperand(fp, StandardFrameConstants::kContextOffset));
// Copy any necessary parameters into the context. // Copy any necessary parameters into the context.
int num_parameters = scope()->num_parameters(); int num_parameters = scope()->num_parameters();
for (int i = 0; i < num_parameters; i++) { int first_parameter = scope()->has_this_declaration() ? -1 : 0;
Variable* var = scope()->parameter(i); for (int i = first_parameter; i < num_parameters; i++) {
Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i);
if (var->IsContextSlot()) { if (var->IsContextSlot()) {
int parameter_offset = StandardFrameConstants::kCallerSPOffset + int parameter_offset = StandardFrameConstants::kCallerSPOffset +
(num_parameters - 1 - i) * kPointerSize; (num_parameters - 1 - i) * kPointerSize;
......
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