X87: new classes: special construct stub for derived classs and TDZ for this.

port 6f97a4948f (r26409)

original commit message:

   new classes: special construct stub for derived classs and TDZ for `this`.

BUG=
R=weiliang.lin@intel.com

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

Cr-Commit-Position: refs/heads/master@{#26512}
This commit is contained in:
cdai2 2015-02-09 16:05:24 +08:00
parent e10291d843
commit 91d9054350
2 changed files with 65 additions and 2 deletions

View File

@ -500,6 +500,57 @@ void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
}
void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- eax: number of arguments
// -- edi: constructor function
// -- ebx: allocation site or undefined
// -- edx: original constructor
// -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{
FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
// Preserve actual arguments count.
__ SmiTag(eax);
__ push(eax);
__ SmiUntag(eax);
// receiver is the hole.
__ push(Immediate(masm->isolate()->factory()->the_hole_value()));
// Set up pointer to last argument.
__ lea(ebx, Operand(ebp, StandardFrameConstants::kCallerSPOffset));
// Copy arguments and receiver to the expression stack.
Label loop, entry;
__ mov(ecx, eax);
__ jmp(&entry);
__ bind(&loop);
__ push(Operand(ebx, ecx, times_4, 0));
__ bind(&entry);
__ dec(ecx);
__ j(greater_equal, &loop);
ParameterCount actual(eax);
__ InvokeFunction(edi, actual, CALL_FUNCTION, NullCallWrapper());
// Restore context from the frame.
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
__ mov(ebx, Operand(esp, 0));
}
__ pop(ecx); // Return address.
__ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize));
__ push(ecx);
__ ret(0);
}
static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
bool is_construct) {
ProfileEntryHookStub::MaybeCallEntryHook(masm);

View File

@ -1450,6 +1450,10 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) {
bool skip_init_check;
if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) {
skip_init_check = false;
} else if (var->is_this()) {
CHECK((info_->shared_info()->kind() & kSubclassConstructor) != 0);
// TODO(dslomov): implement 'this' hole check elimination.
skip_init_check = false;
} else {
// Check that we always have valid source position.
DCHECK(var->initializer_position() != RelocInfo::kNoPosition);
@ -3128,6 +3132,15 @@ void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
EmitLoadSuperConstructor(super_ref);
__ push(result_register());
Variable* this_var = super_ref->this_var()->var();
GetVar(eax, this_var);
__ cmp(eax, isolate()->factory()->the_hole_value());
Label uninitialized_this;
__ j(equal, &uninitialized_this);
__ push(Immediate(this_var->name()));
__ CallRuntime(Runtime::kThrowReferenceError, 1);
__ bind(&uninitialized_this);
// Push the arguments ("left-to-right") on the stack.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
@ -3162,8 +3175,7 @@ void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
RecordJSReturnSite(expr);
// TODO(dslomov): implement TDZ for `this`.
EmitVariableAssignment(super_ref->this_var()->var(), Token::ASSIGN);
EmitVariableAssignment(this_var, Token::INIT_CONST);
context()->Plug(eax);
}