Bug 1530034 - Use mozilla::Maybe in BytecodeEmitter when reasonable. r=jorendorff

Depends on D20884

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ted Campbell 2019-02-25 14:04:14 +00:00
parent 8ad32e5644
commit 5016fe699c
2 changed files with 11 additions and 23 deletions

View File

@ -136,9 +136,7 @@ BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, SharedContext* sc,
hasSingletons(false),
hasTryFinally(false),
emittingRunOnceLambda(false),
emitterMode(emitterMode),
scriptStartOffsetSet(false),
functionBodyEndPosSet(false) {
emitterMode(emitterMode) {
MOZ_ASSERT_IF(emitterMode == LazyFunction, lazyScript);
if (sc->isFunctionBox()) {
@ -1622,8 +1620,7 @@ void BytecodeEmitter::reportNeedMoreArgsError(ParseNode* pn,
}
void BytecodeEmitter::reportError(ParseNode* pn, unsigned errorNumber, ...) {
MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
uint32_t offset = pn ? pn->pn_pos.begin : this->scriptStartOffset;
uint32_t offset = pn ? pn->pn_pos.begin : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
@ -1636,8 +1633,7 @@ void BytecodeEmitter::reportError(ParseNode* pn, unsigned errorNumber, ...) {
void BytecodeEmitter::reportError(const Maybe<uint32_t>& maybeOffset,
unsigned errorNumber, ...) {
MOZ_ASSERT_IF(!maybeOffset, this->scriptStartOffsetSet);
uint32_t offset = maybeOffset ? *maybeOffset : this->scriptStartOffset;
uint32_t offset = maybeOffset ? *maybeOffset : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
@ -1650,8 +1646,7 @@ void BytecodeEmitter::reportError(const Maybe<uint32_t>& maybeOffset,
bool BytecodeEmitter::reportExtraWarning(ParseNode* pn, unsigned errorNumber,
...) {
MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
uint32_t offset = pn ? pn->pn_pos.begin : this->scriptStartOffset;
uint32_t offset = pn ? pn->pn_pos.begin : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
@ -1665,8 +1660,7 @@ bool BytecodeEmitter::reportExtraWarning(ParseNode* pn, unsigned errorNumber,
bool BytecodeEmitter::reportExtraWarning(const Maybe<uint32_t>& maybeOffset,
unsigned errorNumber, ...) {
MOZ_ASSERT_IF(!maybeOffset, this->scriptStartOffsetSet);
uint32_t offset = maybeOffset ? *maybeOffset : this->scriptStartOffset;
uint32_t offset = maybeOffset ? *maybeOffset : *scriptStartOffset;
va_list args;
va_start(args, errorNumber);
@ -6247,8 +6241,7 @@ bool BytecodeEmitter::emitReturn(UnaryNode* returnNode) {
// We know functionBodyEndPos is set because "return" is only
// valid in a function, and so we've passed through
// emitFunctionScript.
MOZ_ASSERT(functionBodyEndPosSet);
if (!updateSourceCoordNotes(functionBodyEndPos)) {
if (!updateSourceCoordNotes(*functionBodyEndPos)) {
return false;
}

View File

@ -234,13 +234,10 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
const EmitterMode emitterMode;
MOZ_INIT_OUTSIDE_CTOR uint32_t scriptStartOffset;
bool scriptStartOffsetSet;
mozilla::Maybe<uint32_t> scriptStartOffset;
// The end location of a function body that is being emitted.
MOZ_INIT_OUTSIDE_CTOR uint32_t functionBodyEndPos;
// Whether functionBodyEndPos was set.
bool functionBodyEndPosSet;
mozilla::Maybe<uint32_t> functionBodyEndPos;
/*
* Note that BytecodeEmitters are magic: they own the arena "top-of-stack"
@ -425,14 +422,12 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
}
void setFunctionBodyEndPos(TokenPos pos) {
functionBodyEndPos = pos.end;
functionBodyEndPosSet = true;
functionBodyEndPos = mozilla::Some(pos.end);
}
void setScriptStartOffsetIfUnset(TokenPos pos) {
if (!scriptStartOffsetSet) {
scriptStartOffset = pos.begin;
scriptStartOffsetSet = true;
if (scriptStartOffset.isNothing()) {
scriptStartOffset = mozilla::Some(pos.begin);
}
}