Bug 1585519 - Part 1: Add MOZ_UNLIKELY to error handling code. r=Yoric
Differential Revision: https://phabricator.services.mozilla.com/D48013
This commit is contained in:
@@ -122,12 +122,12 @@ JS::Result<ParseNode*> BinASTParserPerTokenizer<Tok>::parseAux(
|
||||
|
||||
BinASTParseContext globalpc(cx_, this, globalsc,
|
||||
/* newDirectives = */ nullptr);
|
||||
if (!globalpc.init()) {
|
||||
if (MOZ_UNLIKELY(!globalpc.init())) {
|
||||
return cx_->alreadyReportedError();
|
||||
}
|
||||
|
||||
ParseContext::VarScope varScope(cx_, &globalpc, usedNames_);
|
||||
if (!varScope.init(&globalpc)) {
|
||||
if (MOZ_UNLIKELY(!varScope.init(&globalpc))) {
|
||||
return cx_->alreadyReportedError();
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ JS::Result<ParseNode*> BinASTParserPerTokenizer<Tok>::parseAux(
|
||||
|
||||
mozilla::Maybe<GlobalScope::Data*> bindings =
|
||||
NewGlobalScopeData(cx_, varScope, alloc_, pc_);
|
||||
if (!bindings) {
|
||||
if (MOZ_UNLIKELY(!bindings)) {
|
||||
return cx_->alreadyReportedError();
|
||||
}
|
||||
globalsc->bindings = *bindings;
|
||||
@@ -245,14 +245,14 @@ JS::Result<FunctionBox*> BinASTParserPerTokenizer<Tok>::buildFunctionBox(
|
||||
|
||||
if (pc_ && syntax == FunctionSyntaxKind::Statement) {
|
||||
auto ptr = pc_->varScope().lookupDeclaredName(atom);
|
||||
if (!ptr) {
|
||||
if (MOZ_UNLIKELY(!ptr)) {
|
||||
return raiseError(
|
||||
"FunctionDeclaration without corresponding AssertedDeclaredName.");
|
||||
}
|
||||
|
||||
DeclarationKind declaredKind = ptr->value()->kind();
|
||||
if (DeclarationKindIsVar(declaredKind)) {
|
||||
if (!pc_->atBodyLevel()) {
|
||||
if (MOZ_UNLIKELY(!pc_->atBodyLevel())) {
|
||||
return raiseError(
|
||||
"body-level FunctionDeclaration inside non-body-level context.");
|
||||
}
|
||||
@@ -282,7 +282,7 @@ JS::Result<FunctionBox*> BinASTParserPerTokenizer<Tok>::buildFunctionBox(
|
||||
auto* funbox = alloc_.new_<FunctionBox>(
|
||||
cx_, traceListHead_, fun, /* toStringStart = */ 0, *directives,
|
||||
/* extraWarning = */ false, generatorKind, functionAsyncKind);
|
||||
if (!funbox) {
|
||||
if (MOZ_UNLIKELY(!funbox)) {
|
||||
return raiseOOM();
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::getDeclaredScope(
|
||||
scopeKind == AssertedScopeKind::Var);
|
||||
switch (kind) {
|
||||
case AssertedDeclaredKind::Var:
|
||||
if (scopeKind == AssertedScopeKind::Block) {
|
||||
if (MOZ_UNLIKELY(scopeKind == AssertedScopeKind::Block)) {
|
||||
return raiseError("AssertedBlockScope cannot contain 'var' binding");
|
||||
}
|
||||
declKind = DeclarationKind::Var;
|
||||
@@ -510,7 +510,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkBinding(JSAtom* name) {
|
||||
: *pc_->innermostScope();
|
||||
|
||||
auto ptr = scope.lookupDeclaredName(name->asPropertyName());
|
||||
if (!ptr) {
|
||||
if (MOZ_UNLIKELY(!ptr)) {
|
||||
return raiseMissingVariableInAssertedScope(name);
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (positionalParams.get()[i]) {
|
||||
if (MOZ_UNLIKELY(positionalParams.get()[i])) {
|
||||
return raiseError(
|
||||
"Expected positional parameter per "
|
||||
"AssertedParameterScope.paramNames, got rest parameter");
|
||||
@@ -559,14 +559,14 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
// Simple or default parameter.
|
||||
|
||||
// Step 2.a.
|
||||
if (i >= positionalParams.get().length()) {
|
||||
if (MOZ_UNLIKELY(i >= positionalParams.get().length())) {
|
||||
return raiseError(
|
||||
"AssertedParameterScope.paramNames doesn't have corresponding "
|
||||
"entry to positional parameter");
|
||||
}
|
||||
|
||||
JSAtom* name = positionalParams.get()[i];
|
||||
if (!name) {
|
||||
if (MOZ_UNLIKELY(!name)) {
|
||||
// Step 2.a.ii.1.
|
||||
return raiseError(
|
||||
"Expected destructuring/rest parameter per "
|
||||
@@ -574,7 +574,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
}
|
||||
|
||||
// Step 2.a.i.
|
||||
if (param->as<NameNode>().name() != name) {
|
||||
if (MOZ_UNLIKELY(param->as<NameNode>().name() != name)) {
|
||||
// Step 2.a.ii.1.
|
||||
return raiseError(
|
||||
"Name mismatch between AssertedPositionalParameterName in "
|
||||
@@ -594,7 +594,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (positionalParams.get()[i]) {
|
||||
if (MOZ_UNLIKELY(positionalParams.get()[i])) {
|
||||
return raiseError(
|
||||
"Expected positional parameter per "
|
||||
"AssertedParameterScope.paramNames, got destructuring parameter");
|
||||
@@ -605,7 +605,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
if (positionalParams.get().length() > params->count()) {
|
||||
if (MOZ_UNLIKELY(positionalParams.get().length() > params->count())) {
|
||||
// `positionalParams` has unchecked entries.
|
||||
return raiseError(
|
||||
"AssertedParameterScope.paramNames has unmatching items than the "
|
||||
@@ -620,7 +620,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkPositionalParameterIndices(
|
||||
template <typename Tok>
|
||||
JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkFunctionLength(
|
||||
uint32_t expectedLength) {
|
||||
if (pc_->functionBox()->length != expectedLength) {
|
||||
if (MOZ_UNLIKELY(pc_->functionBox()->length != expectedLength)) {
|
||||
return raiseError("Function length does't match");
|
||||
}
|
||||
return Ok();
|
||||
@@ -633,7 +633,7 @@ JS::Result<Ok> BinASTParserPerTokenizer<Tok>::checkClosedVars(
|
||||
if (UsedNamePtr p = usedNames_.lookup(bi.name())) {
|
||||
bool closedOver;
|
||||
p->value().noteBoundInScope(pc_->scriptId(), scope.id(), &closedOver);
|
||||
if (closedOver && !bi.closedOver()) {
|
||||
if (MOZ_UNLIKELY(closedOver && !bi.closedOver())) {
|
||||
return raiseInvalidClosedVar(bi.name());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user