| Index: src/arm64/builtins-arm64.cc
|
| diff --git a/src/arm64/builtins-arm64.cc b/src/arm64/builtins-arm64.cc
|
| index 08d0a116aaaeffa84df91ca15e570a1ea102425e..190486a2a7146b5d12417c8a2bbf8c2d2d4a63b0 100644
|
| --- a/src/arm64/builtins-arm64.cc
|
| +++ b/src/arm64/builtins-arm64.cc
|
| @@ -331,6 +331,7 @@ static void Generate_Runtime_NewObject(MacroAssembler* masm,
|
|
|
| static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| bool is_api_function,
|
| + bool use_new_target,
|
| bool create_memento) {
|
| // ----------- S t a t e -------------
|
| // -- x0 : number of arguments
|
| @@ -360,11 +361,17 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| Register argc = x0;
|
| Register constructor = x1;
|
| Register original_constructor = x3;
|
| - // x1: constructor function
|
| +
|
| + // Preserve the incoming parameters on the stack.
|
| __ SmiTag(argc);
|
| - __ Push(argc, constructor);
|
| - // sp[0] : Constructor function.
|
| - // sp[1]: number of arguments (smi-tagged)
|
| + if (use_new_target) {
|
| + __ Push(argc, constructor, original_constructor);
|
| + } else {
|
| + __ Push(argc, constructor);
|
| + }
|
| + // sp[0]: new.target (if used)
|
| + // sp[0/1]: Constructor function.
|
| + // sp[1/2]: number of arguments (smi-tagged)
|
|
|
| Label rt_call, count_incremented, allocated, normal_new;
|
| __ Cmp(constructor, original_constructor);
|
| @@ -580,7 +587,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| __ Bind(&allocated);
|
|
|
| if (create_memento) {
|
| - __ Peek(x10, 2 * kXRegSize);
|
| + int offset = (use_new_target ? 3 : 2) * kXRegSize;
|
| + __ Peek(x10, offset);
|
| __ JumpIfRoot(x10, Heap::kUndefinedValueRootIndex, &count_incremented);
|
| // r2 is an AllocationSite. We are creating a memento from it, so we
|
| // need to increment the memento create count.
|
| @@ -592,18 +600,24 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| __ bind(&count_incremented);
|
| }
|
|
|
| + // Restore the parameters.
|
| + if (use_new_target) {
|
| + __ Pop(original_constructor);
|
| + }
|
| __ Pop(constructor);
|
|
|
| - __ Push(x4, x4);
|
| -
|
| // Reload the number of arguments from the stack.
|
| // Set it up in x0 for the function call below.
|
| - // jssp[0]: receiver
|
| - // jssp[1]: receiver
|
| - // jssp[2]: number of arguments (smi-tagged)
|
| - __ Peek(argc, 2 * kXRegSize); // Load number of arguments.
|
| + // jssp[0]: number of arguments (smi-tagged)
|
| + __ Peek(argc, 0); // Load number of arguments.
|
| __ SmiUntag(argc);
|
|
|
| + if (use_new_target) {
|
| + __ Push(original_constructor, x4, x4);
|
| + } else {
|
| + __ Push(x4, x4);
|
| + }
|
| +
|
| // Set up pointer to last argument.
|
| __ Add(x2, fp, StandardFrameConstants::kCallerSPOffset);
|
|
|
| @@ -614,7 +628,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| // x2: address of last argument (caller sp)
|
| // jssp[0]: receiver
|
| // jssp[1]: receiver
|
| - // jssp[2]: number of arguments (smi-tagged)
|
| + // jssp[2]: new.target (if used)
|
| + // jssp[2/3]: number of arguments (smi-tagged)
|
| // Compute the start address of the copy in x3.
|
| __ Add(x3, x2, Operand(argc, LSL, kPointerSizeLog2));
|
| Label loop, entry, done_copying_arguments;
|
| @@ -645,14 +660,17 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| }
|
|
|
| // Store offset of return address for deoptimizer.
|
| - if (!is_api_function) {
|
| + // TODO(arv): Remove the "!use_new_target" before supporting optimization
|
| + // of functions that reference new.target
|
| + if (!is_api_function && !use_new_target) {
|
| masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
|
| }
|
|
|
| // Restore the context from the frame.
|
| // x0: result
|
| // jssp[0]: receiver
|
| - // jssp[1]: number of arguments (smi-tagged)
|
| + // jssp[1]: new.target (if used)
|
| + // jssp[1/2]: number of arguments (smi-tagged)
|
| __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
|
|
| // If the result is an object (in the ECMA sense), we should get rid
|
| @@ -680,8 +698,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
| __ Bind(&exit);
|
| // x0: result
|
| // jssp[0]: receiver (newly allocated object)
|
| - // jssp[1]: number of arguments (smi-tagged)
|
| - __ Peek(x1, kXRegSize);
|
| + // jssp[1]: new.target (if used)
|
| + // jssp[1/2]: number of arguments (smi-tagged)
|
| + int offset = (use_new_target ? 2 : 1) * kXRegSize;
|
| + __ Peek(x1, offset);
|
|
|
| // Leave construct frame.
|
| }
|
| @@ -694,12 +714,17 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
|
|
|
|
| void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
|
| - Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new);
|
| + Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new);
|
| }
|
|
|
|
|
| void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
|
| - Generate_JSConstructStubHelper(masm, true, false);
|
| + Generate_JSConstructStubHelper(masm, true, false, false);
|
| +}
|
| +
|
| +
|
| +void Builtins::Generate_JSConstructStubNewTarget(MacroAssembler* masm) {
|
| + Generate_JSConstructStubHelper(masm, false, true, FLAG_pretenuring_call_new);
|
| }
|
|
|
|
|
|
|