Bug 1497792 - Make arguments objects for more functions in BinAST. (r=arai)
authorEric Faust <efausbmo@gmail.com>
Mon, 15 Oct 2018 17:17:58 -0400
changeset 489586 0855e7bda81620c0c3029b14cece477261f3e08f
parent 489585 4ba3494b8b7637420f6b01eaf5f1199227798915
child 489587 582fd4a0f638a2b3b8000972cf55dd5df8503d7a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersarai
bugs1497792
milestone64.0a1
Bug 1497792 - Make arguments objects for more functions in BinAST. (r=arai)
js/src/frontend/BinSource.cpp
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -335,26 +335,37 @@ BinASTParser<Tok>::buildFunction(const s
 
         // TODO (efaust): This capture will have to come from encoder side for arrow functions.
     }
 
     // This models PerHandlerParser::declaeFunctionArgumentsObject, with some subtleties removed,
     // as they don't yet apply to us.
     HandlePropertyName arguments = cx_->names().arguments;
     if (hasUsedName(arguments) || parseContext_->functionBox()->bindingsAccessedDynamically()) {
+        funbox->usesArguments = true;
+
         ParseContext::Scope& funScope = parseContext_->functionScope();
         ParseContext::Scope::AddDeclaredNamePtr p = funScope.lookupDeclaredNameForAdd(arguments);
         if (!p) {
             BINJS_TRY(funScope.addDeclaredName(parseContext_, p, arguments, DeclarationKind::Var,
                                                DeclaredNameInfo::npos));
             funbox->declaredArguments = true;
-            funbox->usesArguments = true;
+        } else if (p->value()->kind() != DeclarationKind::Var) {
+            // Lexicals, formal parameters, and body level functions shadow.
+            funbox->usesArguments = false;
+        }
 
+        if (funbox->usesArguments) {
             funbox->setArgumentsHasLocalBinding();
-            funbox->setDefinitelyNeedsArgsObj();
+
+            if (parseContext_->sc()->bindingsAccessedDynamically() ||
+                parseContext_->sc()->hasDebuggerStatement())
+            {
+                funbox->setDefinitelyNeedsArgsObj();
+            }
         }
     }
 
     if (funbox->needsDotGeneratorName()) {
         ParseContext::Scope& funScope = parseContext_->functionScope();
         HandlePropertyName dotGenerator = cx_->names().dotGenerator;
         ParseContext::Scope::AddDeclaredNamePtr p = funScope.lookupDeclaredNameForAdd(dotGenerator);
         if (!p) {