Chromium Code Reviews| Index: src/x64/builtins-x64.cc |
| diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc |
| index 2e3adb73c566612247f73c3a1fa62c6ebac6623f..d6c63ab585bdf5b4235e4dfa536528bc4ae533c2 100644 |
| --- a/src/x64/builtins-x64.cc |
| +++ b/src/x64/builtins-x64.cc |
| @@ -1432,6 +1432,7 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
| // ----------- S t a t e ------------- |
| // -- rax : number of arguments |
| // -- rdi : constructor function |
| + // -- rdx : original constructor |
| // -- rsp[0] : return address |
| // -- rsp[(argc - n) * 8] : arg[n] (zero-based) |
| // -- rsp[(argc + 1) * 8] : receiver |
| @@ -1458,17 +1459,19 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
| { |
| Label convert, done_convert; |
| __ JumpIfSmi(rbx, &convert, Label::kNear); |
| - __ CmpObjectType(rbx, FIRST_NONSTRING_TYPE, rdx); |
| + __ CmpObjectType(rbx, FIRST_NONSTRING_TYPE, rcx); |
| __ j(below, &done_convert); |
| __ bind(&convert); |
| { |
| FrameScope scope(masm, StackFrame::INTERNAL); |
| ToStringStub stub(masm->isolate()); |
| + __ Push(rdx); |
| __ Push(rdi); |
| __ Move(rax, rbx); |
| __ CallStub(&stub); |
| __ Move(rbx, rax); |
| __ Pop(rdi); |
| + __ Pop(rdx); |
| } |
| __ bind(&done_convert); |
| } |
| @@ -1478,9 +1481,14 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
| // ----------- S t a t e ------------- |
| // -- rbx : the first argument |
| // -- rdi : constructor function |
| + // -- rdx : original constructor |
| // ----------------------------------- |
| + Label allocate, done_allocate, rt_call; |
| + |
| + // Fall back to runtime if the original constructor and constructor differ. |
| + __ cmpp(rdx, rdi); |
| + __ j(not_equal, &rt_call); |
| - Label allocate, done_allocate; |
| __ Allocate(JSValue::kSize, rax, rcx, no_reg, &allocate, TAG_OBJECT); |
| __ bind(&done_allocate); |
| @@ -1506,6 +1514,22 @@ void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
| __ Pop(rbx); |
| } |
| __ jmp(&done_allocate); |
| + |
| + // Fallback to the runtime to create new object. |
| + __ bind(&rt_call); |
| + { |
| + FrameScope scope(masm, StackFrame::INTERNAL); |
| + __ Push(rbx); |
| + __ Push(rdi); |
| + __ Push(rdi); // argument 2/1: constructor function |
|
Toon Verwaest
2015/10/26 15:10:57
I don't understand 2/1, 3/2...
Igor Sheludko
2015/10/27 12:56:12
Done.
|
| + __ Push(rdx); // argument 3/2: original constructor |
| + // TODO(ishell): allocation site? |
| + __ CallRuntime(Runtime::kNewObject, 2); |
|
Toon Verwaest
2015/10/26 15:10:57
Please add some tests here that subclassing now wo
Igor Sheludko
2015/10/27 12:56:12
Done.
|
| + __ Pop(rdi); |
| + __ Pop(rbx); |
| + } |
| + __ movp(FieldOperand(rax, JSValue::kValueOffset), rbx); |
| + __ Ret(); |
| } |
| } |