Bug 1497788 - Allow duplicate AssertedPositionalParameterName. r=efaust
authorTooru Fujisawa <arai_a@mac.com>
Tue, 30 Oct 2018 09:49:40 +0900
changeset 499869 978ef31db350c9984c3a62474b7b7802bfca82d5
parent 499868 052d5b7a515ec057ee9c0cee231ee8b8413bdb3c
child 499870 f2a70b31cc32e0e5b3fb358105ad660b4b9f42e6
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1497788
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497788 - Allow duplicate AssertedPositionalParameterName. r=efaust
js/src/frontend/BinSource-auto.cpp
js/src/frontend/BinSource.cpp
js/src/frontend/BinSource.h
js/src/frontend/BinSource.yaml
--- a/js/src/frontend/BinSource-auto.cpp
+++ b/js/src/frontend/BinSource-auto.cpp
@@ -2113,25 +2113,26 @@ BinASTParser<Tok>::parseInterfaceAsserte
 {
     MOZ_ASSERT(kind == BinKind::AssertedBoundName);
     BINJS_TRY(CheckRecursionLimit(cx_));
 
 #if defined(DEBUG)
     const BinField expected_fields[2] = { BinField::Name, BinField::IsCaptured };
     MOZ_TRY(tokenizer_->checkFields(kind, fields, expected_fields));
 #endif // defined(DEBUG)
+    const bool allowDuplicateName = false;
 
     RootedAtom name(cx_);
     MOZ_TRY_VAR(name, tokenizer_->readIdentifierName());
 
     BINJS_MOZ_TRY_DECL(isCaptured, tokenizer_->readBool());
     ParseContext::Scope* scope;
     DeclarationKind declKind;
     MOZ_TRY(getBoundScope(scopeKind, scope, declKind));
-    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured));
+    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured, allowDuplicateName));
     auto result = Ok();
     return result;
 }
 
 
 /*
  interface AssertedBoundNamesScope : Node {
     FrozenArray<AssertedBoundName> boundNames;
@@ -2219,27 +2220,28 @@ BinASTParser<Tok>::parseInterfaceAsserte
 {
     MOZ_ASSERT(kind == BinKind::AssertedDeclaredName);
     BINJS_TRY(CheckRecursionLimit(cx_));
 
 #if defined(DEBUG)
     const BinField expected_fields[3] = { BinField::Name, BinField::Kind, BinField::IsCaptured };
     MOZ_TRY(tokenizer_->checkFields(kind, fields, expected_fields));
 #endif // defined(DEBUG)
+    const bool allowDuplicateName = false;
 
     RootedAtom name(cx_);
     MOZ_TRY_VAR(name, tokenizer_->readIdentifierName());
 
     BINJS_MOZ_TRY_DECL(kind_, parseAssertedDeclaredKind());
 
     BINJS_MOZ_TRY_DECL(isCaptured, tokenizer_->readBool());
     ParseContext::Scope* scope;
     DeclarationKind declKind;
     MOZ_TRY(getDeclaredScope(scopeKind, kind_, scope, declKind));
-    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured));
+    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured, allowDuplicateName));
     auto result = Ok();
     return result;
 }
 
 template<typename Tok> JS::Result<ParseNode*>
 BinASTParser<Tok>::parseInterfaceAssertedParameterName(const size_t start, const BinKind kind, const BinFields& fields)
 {
     return raiseError("FIXME: Not implemented yet in this preview release (AssertedParameterName)");
@@ -2312,16 +2314,17 @@ BinASTParser<Tok>::parseInterfaceAsserte
 {
     MOZ_ASSERT(kind == BinKind::AssertedPositionalParameterName);
     BINJS_TRY(CheckRecursionLimit(cx_));
 
 #if defined(DEBUG)
     const BinField expected_fields[3] = { BinField::Index, BinField::Name, BinField::IsCaptured };
     MOZ_TRY(tokenizer_->checkFields(kind, fields, expected_fields));
 #endif // defined(DEBUG)
+    bool allowDuplicateName = !parseContext_->sc()->strict();
 
     BINJS_MOZ_TRY_DECL(index, tokenizer_->readUnsignedLong());
 
     RootedAtom name(cx_);
     MOZ_TRY_VAR(name, tokenizer_->readIdentifierName());
     // `positionalParams` vector can be shorter than the actual
     // parameter length. Resize on demand.
     // (see also ListOfAssertedMaybePositionalParameterName)
@@ -2341,17 +2344,17 @@ BinASTParser<Tok>::parseInterfaceAsserte
     if (positionalParams.get()[index]) {
         return raiseError("AssertedPositionalParameterName has duplicate entry for the same index");
     }
     positionalParams.get()[index] = name;
     BINJS_MOZ_TRY_DECL(isCaptured, tokenizer_->readBool());
     ParseContext::Scope* scope;
     DeclarationKind declKind;
     MOZ_TRY(getBoundScope(scopeKind, scope, declKind));
-    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured));
+    MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured, allowDuplicateName));
     auto result = Ok();
     return result;
 }
 
 template<typename Tok> JS::Result<ParseNode*>
 BinASTParser<Tok>::parseInterfaceAssertedRestParameterName(const size_t start, const BinKind kind, const BinFields& fields)
 {
     return raiseError("FIXME: Not implemented yet in this preview release (AssertedRestParameterName)");
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -400,20 +400,23 @@ BinASTParser<Tok>::buildFunction(const s
     }
 
     return result;
 }
 
 template<typename Tok> JS::Result<Ok>
 BinASTParser<Tok>::addScopeName(AssertedScopeKind scopeKind, HandleAtom name,
                                 ParseContext::Scope* scope, DeclarationKind declKind,
-                                bool isCaptured)
+                                bool isCaptured, bool allowDuplicateName)
 {
     auto ptr = scope->lookupDeclaredNameForAdd(name);
     if (ptr) {
+        if (allowDuplicateName) {
+            return Ok();
+        }
         return raiseError("Variable redeclaration");
     }
 
     BINJS_TRY(scope->addDeclaredName(parseContext_, ptr, name.get(), declKind,
                                      tokenizer_->offset()));
 
     if (isCaptured) {
         auto declaredPtr = scope->lookupDeclaredName(name);
--- a/js/src/frontend/BinSource.h
+++ b/js/src/frontend/BinSource.h
@@ -189,17 +189,18 @@ class BinASTParser : public BinASTParser
                   ParseNode* body, FunctionBox* funbox);
     JS::Result<FunctionBox*>
     buildFunctionBox(GeneratorKind generatorKind, FunctionAsyncKind functionAsyncKind, FunctionSyntaxKind syntax, ParseNode* name);
 
     // Add name to a given scope.
     MOZ_MUST_USE JS::Result<Ok> addScopeName(AssertedScopeKind scopeKind, HandleAtom name,
                                              ParseContext::Scope* scope,
                                              DeclarationKind declKind,
-                                             bool isCaptured);
+                                             bool isCaptured,
+                                             bool allowDuplicateName);
 
     void captureFunctionName();
 
     // Map AssertedScopeKind and AssertedDeclaredKind for single binding to
     // corresponding ParseContext::Scope to store the binding, and
     // DeclarationKind for the binding.
     MOZ_MUST_USE JS::Result<Ok> getDeclaredScope(AssertedScopeKind scopeKind,
                                                  AssertedDeclaredKind kind,
--- a/js/src/frontend/BinSource.yaml
+++ b/js/src/frontend/BinSource.yaml
@@ -240,24 +240,26 @@ AssertedBlockScope:
         }
         auto result = Ok();
 
 AssertedBoundName:
     type-ok:
         Ok
     extra-params: AssertedScopeKind scopeKind
     extra-args: scopeKind
+    init: |
+        const bool allowDuplicateName = false;
     fields:
         isCaptured:
              after: |
                 ParseContext::Scope* scope;
                 DeclarationKind declKind;
                 MOZ_TRY(getBoundScope(scopeKind, scope, declKind));
     build: |
-        MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured));
+        MOZ_TRY(addScopeName(scopeKind, name, scope, declKind, isCaptured, allowDuplicateName));
         auto result = Ok();
 
 AssertedDeclaredName:
     inherits: AssertedBoundName
     fields:
         isCaptured:
             after: |
                 ParseContext::Scope* scope;
@@ -274,16 +276,18 @@ AssertedMaybePositionalParameterName:
     sum-arms:
         AssertedRestParameterName:
             disabled: true
         AssertedParameterName:
             disabled: true
 
 AssertedPositionalParameterName:
     inherits: AssertedMaybePositionalParameterName
+    init: |
+        bool allowDuplicateName = !parseContext_->sc()->strict();
     fields:
         name:
             after: |
                 // `positionalParams` vector can be shorter than the actual
                 // parameter length. Resize on demand.
                 // (see also ListOfAssertedMaybePositionalParameterName)
                 size_t prevLength = positionalParams.get().length();
                 if (index >= prevLength) {