Bug 1533620 - Verify that catch scope has correct item. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Mon, 11 Mar 2019 14:36:08 +0000
changeset 524397 9b356aa135ac45caa24e4ae7e8fe98d143a90d71
parent 524396 f1c6fa74a15e23e4fedd2a540950311a12051dd0
child 524398 6b9b50bc446d892779619254ce852f8b2f0c9bcf
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1533620
milestone67.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 1533620 - Verify that catch scope has correct item. r=Yoric Depends on D22647 Differential Revision: https://phabricator.services.mozilla.com/D22648
js/src/frontend/BinASTParser.cpp
js/src/frontend/BinSource.yaml
js/src/jit-test/tests/binast/invalid/catch-scope-missing.binjs
js/src/jit-test/tests/binast/invalid/catch-scope-missing.dir
js/src/jit-test/tests/binast/invalid/catch-scope-unmatched.binjs
js/src/jit-test/tests/binast/invalid/catch-scope-unmatched.dir
js/src/jsapi-tests/binast/invalid/tests/catch-scope-missing.js
js/src/jsapi-tests/binast/invalid/tests/catch-scope-missing.py
js/src/jsapi-tests/binast/invalid/tests/catch-scope-unmatched.js
js/src/jsapi-tests/binast/invalid/tests/catch-scope-unmatched.py
--- a/js/src/frontend/BinASTParser.cpp
+++ b/js/src/frontend/BinASTParser.cpp
@@ -2130,17 +2130,20 @@ JS::Result<LexicalScopeNode*> BinASTPars
 #endif  // defined(DEBUG)
   ParseContext::Statement stmt(pc_, StatementKind::Catch);
   ParseContext::Scope currentScope(cx_, pc_, usedNames_);
   BINJS_TRY(currentScope.init(pc_));
 
   MOZ_TRY(parseAssertedBoundNamesScope());
 
   BINJS_MOZ_TRY_DECL(binding, parseBinding());
-
+  if (!currentScope.lookupDeclaredName(
+          binding->template as<NameNode>().atom())) {
+    return raiseError("Missing catch variable in scope");
+  }
   BINJS_MOZ_TRY_DECL(body, parseBlock());
 
   MOZ_TRY(checkClosedVars(currentScope));
   BINJS_TRY_DECL(bindings, NewLexicalScopeData(cx_, currentScope, alloc_, pc_));
   BINJS_TRY_DECL(result, handler_.newLexicalScope(*bindings, body));
   BINJS_TRY(handler_.setupCatchScope(result, binding, body));
   return result;
 }
--- a/js/src/frontend/BinSource.yaml
+++ b/js/src/frontend/BinSource.yaml
@@ -683,16 +683,22 @@ CallExpression:
 
 CatchClause:
   type-ok:
     LexicalScopeNode*
   init: |
     ParseContext::Statement stmt(pc_, StatementKind::Catch);
     ParseContext::Scope currentScope(cx_, pc_, usedNames_);
     BINJS_TRY(currentScope.init(pc_));
+  fields:
+    binding:
+      after: |
+        if (!currentScope.lookupDeclaredName(binding->template as<NameNode>().atom())) {
+          return raiseError("Missing catch variable in scope");
+        }
   build: |
     MOZ_TRY(checkClosedVars(currentScope));
     BINJS_TRY_DECL(bindings,
                    NewLexicalScopeData(cx_, currentScope, alloc_, pc_));
     BINJS_TRY_DECL(result, handler_.newLexicalScope(*bindings, body));
     BINJS_TRY(handler_.setupCatchScope(result, binding, body));
 
 CompoundAssignmentExpression:
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f5cc65576aa61ddf9bd0d0d543c4782aa64232d8
GIT binary patch
literal 218
zc$`I!u?mAQ6h%WQwuqEY{Q&9g(6y6_hy@*tn{-H%*ETdJlElHkucWjtkIOli%gd_f
zN^oDcX<eu7O>j_7xcRchhf``T7zaF)n!O3rBZNLCf1xME8#;jX_Wa|788Nz2>N}O*
z#F<cBsAuKp9|FuVr;fdHNhb@@w;y+A_LMm4U|5<x>DsC($@*4+G4x$q6e~)i03n3;
Nc)2LtAhbh1egM>sMo0hv
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/binast/invalid/catch-scope-missing.dir
@@ -0,0 +1,1 @@
+// |jit-test| error:SyntaxError
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..554b95a2157c7d63971b4987cc8a2169f741a23f
GIT binary patch
literal 241
zc${<c^z#a4igpij^!0TNip@+(%`3?)skGK+5>jz2E>0~fNlkIe$xqG>PR=h#<pML6
z;1c<zc`1I0xv6>>BE?|!MlkW<<f6=i68D_^q{JMsjFMAkUP@+Ox+mDew9M2ZG3UgR
z<P7JW#M0ta9*BCSkfKVkXmCklNop=oWpr>zkf)z}Fv6i+EKEsEsnH=puC53{6Fv?G
V1_mYpCLqbc!^Xq{q_~*CJOE)mO~?QM
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/binast/invalid/catch-scope-unmatched.dir
@@ -0,0 +1,1 @@
+// |jit-test| error:SyntaxError
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/binast/invalid/tests/catch-scope-missing.js
@@ -0,0 +1,3 @@
+try {
+} catch (e) {
+}
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/binast/invalid/tests/catch-scope-missing.py
@@ -0,0 +1,20 @@
+def filter_ast(ast):
+    # catch with missing AssertedBoundName
+    import filter_utils as utils
+
+    utils.assert_interface(ast, 'Script')
+    global_stmts = utils.get_field(ast, 'statements')
+
+    try_stmt = utils.get_element(global_stmts, 0)
+    utils.assert_interface(try_stmt, 'TryCatchStatement')
+
+    catch = utils.get_field(try_stmt, 'catchClause')
+    utils.assert_interface(catch, 'CatchClause')
+
+    scope = utils.get_field(catch, 'bindingScope')
+    utils.assert_interface(scope, 'AssertedBoundNamesScope')
+
+    names = utils.get_field(scope, 'boundNames')
+    utils.remove_element(names, 0)
+
+    return ast
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/binast/invalid/tests/catch-scope-unmatched.js
@@ -0,0 +1,3 @@
+try {
+} catch (e) {
+}
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/binast/invalid/tests/catch-scope-unmatched.py
@@ -0,0 +1,25 @@
+def filter_ast(ast):
+    # catch with unmatched AssertedBoundName
+    import filter_utils as utils
+
+    utils.assert_interface(ast, 'Script')
+    global_stmts = utils.get_field(ast, 'statements')
+
+    try_stmt = utils.get_element(global_stmts, 0)
+    utils.assert_interface(try_stmt, 'TryCatchStatement')
+
+    catch = utils.get_field(try_stmt, 'catchClause')
+    utils.assert_interface(catch, 'CatchClause')
+
+    scope = utils.get_field(catch, 'bindingScope')
+    utils.assert_interface(scope, 'AssertedBoundNamesScope')
+
+    names = utils.get_field(scope, 'boundNames')
+    bound_name = utils.get_element(names, 0)
+    utils.assert_interface(bound_name, 'AssertedBoundName')
+
+    name = utils.get_field(bound_name, 'name')
+
+    utils.set_identifier_name(name, 'b')
+
+    return ast