PPC: [runtime] Throw exception for derived constructors in correct context.
Port c86f1897ac
Original commit message:
When derived constructors return a non-object (or not undefined) we
currently throw an exception directly in the callee context. This was
achieved by desugaring the return statement for derived classes. To
be spec compliamnt a separate ConstructStubForDerived is introduced.
Instead of trowing directly, the desugared return statement inside
a derived constructor only returns an integer to indicate an incompatible
result.
R=cbruni@chromium.org, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=v8:4509
LOG=n
Review URL: https://codereview.chromium.org/1595593002
Cr-Commit-Position: refs/heads/master@{#33341}
This commit is contained in:
parent
316ef28676
commit
bbb95fba40
@ -421,7 +421,8 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
|
|||||||
|
|
||||||
static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
||||||
bool is_api_function,
|
bool is_api_function,
|
||||||
bool create_implicit_receiver) {
|
bool create_implicit_receiver,
|
||||||
|
bool check_derived_construct) {
|
||||||
// ----------- S t a t e -------------
|
// ----------- S t a t e -------------
|
||||||
// -- r3 : number of arguments
|
// -- r3 : number of arguments
|
||||||
// -- r4 : constructor function
|
// -- r4 : constructor function
|
||||||
@ -680,6 +681,19 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
|||||||
// Leave construct frame.
|
// Leave construct frame.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ES6 9.2.2. Step 13+
|
||||||
|
// Check that the result is not a Smi, indicating that the constructor result
|
||||||
|
// from a derived class is neither undefined nor an Object.
|
||||||
|
if (check_derived_construct) {
|
||||||
|
Label dont_throw;
|
||||||
|
__ JumpIfNotSmi(r3, &dont_throw);
|
||||||
|
{
|
||||||
|
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
|
||||||
|
__ CallRuntime(Runtime::kThrowDerivedConstructorReturnedNonObject);
|
||||||
|
}
|
||||||
|
__ bind(&dont_throw);
|
||||||
|
}
|
||||||
|
|
||||||
__ SmiToPtrArrayOffset(r4, r4);
|
__ SmiToPtrArrayOffset(r4, r4);
|
||||||
__ add(sp, sp, r4);
|
__ add(sp, sp, r4);
|
||||||
__ addi(sp, sp, Operand(kPointerSize));
|
__ addi(sp, sp, Operand(kPointerSize));
|
||||||
@ -691,23 +705,23 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
|
|||||||
|
|
||||||
|
|
||||||
void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
|
void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
|
||||||
Generate_JSConstructStubHelper(masm, false, true);
|
Generate_JSConstructStubHelper(masm, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
|
void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
|
||||||
Generate_JSConstructStubHelper(masm, true, true);
|
Generate_JSConstructStubHelper(masm, true, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
|
void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
|
||||||
Generate_JSConstructStubHelper(masm, false, false);
|
Generate_JSConstructStubHelper(masm, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Builtins::Generate_JSBuiltinsConstructStubForDerived(
|
void Builtins::Generate_JSBuiltinsConstructStubForDerived(
|
||||||
MacroAssembler* masm) {
|
MacroAssembler* masm) {
|
||||||
Generate_JSConstructStubHelper(masm, false, false);
|
Generate_JSConstructStubHelper(masm, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user