Bug 1611777 - Part 8: Add missing emitGet in emitOptionalElemExpression. r=yulia

Aligns emitOptionalElemExpression() with emitOptionalDotExpression(), so it's
easier to compare both methods against each other.

Differential Revision: https://phabricator.services.mozilla.com/D61155

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2020-01-29 16:26:44 +00:00
parent 8ca239b387
commit e2cbc96373
2 changed files with 32 additions and 28 deletions

View File

@ -7846,22 +7846,25 @@ bool BytecodeEmitter::emitOptionalDotExpression(PropertyAccessBase* prop,
bool isSuper,
OptionalEmitter& oe) {
if (!poe.prepareForObj()) {
// [stack]
return false;
}
if (isSuper) {
UnaryNode* base = &prop->expression().as<UnaryNode>();
if (!emitGetThisForSuperBase(base)) {
// [stack] THIS
// [stack] OBJ
return false;
}
} else {
if (!emitOptionalTree(&prop->expression(), oe)) {
// [stack] OBJ
// [stack] OBJ
return false;
}
}
if (prop->isKind(ParseNodeKind::OptionalDotExpr)) {
MOZ_ASSERT(!isSuper);
if (!oe.emitJumpShortCircuit()) {
// [stack] # if Jump
// [stack] UNDEFINED-OR-NULL
@ -7872,7 +7875,7 @@ bool BytecodeEmitter::emitOptionalDotExpression(PropertyAccessBase* prop,
}
if (!poe.emitGet(prop->key().atom())) {
// [stack] PROP
// [stack] PROP
return false;
}
@ -7883,38 +7886,26 @@ bool BytecodeEmitter::emitOptionalElemExpression(PropertyByValueBase* elem,
ElemOpEmitter& eoe,
bool isSuper,
OptionalEmitter& oe) {
if (isSuper) {
if (!eoe.prepareForObj()) {
// [stack]
return false;
}
UnaryNode* base = &elem->expression().as<UnaryNode>();
if (!emitGetThisForSuperBase(base)) {
// [stack] THIS
return false;
}
if (!eoe.prepareForKey()) {
// [stack] THIS
return false;
}
if (!emitTree(&elem->key())) {
// [stack] THIS KEY
return false;
}
return true;
}
if (!eoe.prepareForObj()) {
// [stack]
return false;
}
if (!emitOptionalTree(&elem->expression(), oe)) {
// [stack] OBJ
return false;
if (isSuper) {
UnaryNode* base = &elem->expression().as<UnaryNode>();
if (!emitGetThisForSuperBase(base)) {
// [stack] OBJ
return false;
}
} else {
if (!emitOptionalTree(&elem->expression(), oe)) {
// [stack] OBJ
return false;
}
}
if (elem->isKind(ParseNodeKind::OptionalElemExpr)) {
MOZ_ASSERT(!isSuper);
if (!oe.emitJumpShortCircuit()) {
// [stack] # if Jump
// [stack] UNDEFINED-OR-NULL
@ -7938,6 +7929,7 @@ bool BytecodeEmitter::emitOptionalElemExpression(PropertyByValueBase* elem,
// [stack] ELEM
return false;
}
return true;
}

View File

@ -0,0 +1,12 @@
// Don't assert.
var obj = {
m() {
super[0]?.a
}
};
obj.m();
if (typeof reportCompare === "function")
reportCompare(true, true);