parseClass should popScope after pushScope
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 04:58:55 +0000 (04:58 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 04:58:55 +0000 (04:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142689

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

Pop the parser scope as needed.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseClass):

LayoutTests:

Added a regression test for the test case that caught this bug.

* TestExpectations: Skipped the test since ES6 class syntax isn't enabled by default.
* js/class-syntax-scoping-expected.txt: Added.
* js/class-syntax-scoping.html: Added.
* js/script-tests/class-syntax-scoping.js: Added.
(test):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181503 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/js/class-syntax-scoping-expected.txt [new file with mode: 0644]
LayoutTests/js/class-syntax-scoping.html [new file with mode: 0644]
LayoutTests/js/script-tests/class-syntax-scoping.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/parser/Parser.cpp

index 434ef8f..6698f76 100644 (file)
@@ -1,3 +1,18 @@
+2015-03-14  Ryosuke Niwa  <rniwa@webkit.org>
+
+        parseClass should popScope after pushScope
+        https://bugs.webkit.org/show_bug.cgi?id=142689
+
+        Reviewed by Benjamin Poulain.
+
+        Added a regression test for the test case that caught this bug.
+
+        * TestExpectations: Skipped the test since ES6 class syntax isn't enabled by default.
+        * js/class-syntax-scoping-expected.txt: Added.
+        * js/class-syntax-scoping.html: Added.
+        * js/script-tests/class-syntax-scoping.js: Added.
+        (test):
+
 2015-03-14  Michael Saboff  <msaboff@apple.com>
 
         ES6: Add binary and octal literal support
index b76e3ce..54a96b4 100644 (file)
@@ -71,6 +71,7 @@ webkit.org/b/140491 js/class-syntax-call.html [ Failure ]
 webkit.org/b/140491 js/class-syntax-declaration.html [ Failure ]
 webkit.org/b/140491 js/class-syntax-expression.html [ Failure ]
 webkit.org/b/140491 js/class-syntax-extends.html [ Failure ]
+webkit.org/b/140491 js/class-syntax-scoping.html [ Failure ]
 webkit.org/b/140491 js/class-syntax-super.html [ Failure ]
 
 # This test verifies dynamic manipulation of the mroot and msqrt elements.
diff --git a/LayoutTests/js/class-syntax-scoping-expected.txt b/LayoutTests/js/class-syntax-scoping-expected.txt
new file mode 100644 (file)
index 0000000..1a8dd35
--- /dev/null
@@ -0,0 +1,10 @@
+Tests for scoping of variables in ES6 class syntax
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS test() is "PASS"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/class-syntax-scoping.html b/LayoutTests/js/class-syntax-scoping.html
new file mode 100644 (file)
index 0000000..6be618c
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../resources/js-test-pre.js"></script>
+<script src="script-tests/class-syntax-scoping.js"></script>
+<script src="../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/js/script-tests/class-syntax-scoping.js b/LayoutTests/js/script-tests/class-syntax-scoping.js
new file mode 100644 (file)
index 0000000..3f45e2c
--- /dev/null
@@ -0,0 +1,16 @@
+//@ skip
+
+description('Tests for scoping of variables in ES6 class syntax');
+
+var local = "FAIL";
+function test() {
+    var local = "PASS";
+    class A {
+        getLocal(x) { return local; }
+    };
+    return new A().getLocal();
+}
+
+shouldBe('test()', '"PASS"');
+
+var successfullyParsed = true;
index 813bb2f..3220116 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-14  Ryosuke Niwa  <rniwa@webkit.org>
+
+        parseClass should popScope after pushScope
+        https://bugs.webkit.org/show_bug.cgi?id=142689
+
+        Reviewed by Benjamin Poulain.
+
+        Pop the parser scope as needed.
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseClass):
+
 2015-03-14  Dean Jackson  <dino@apple.com>
 
         Feature flag for Animations Level 2
index 78fc37a..d800afb 100644 (file)
@@ -1552,6 +1552,7 @@ template <class TreeBuilder> TreeClassExpression Parser<LexerType>::parseClass(T
     // FIXME: Create a Miranda function instead.
     semanticFailIfFalse(constructor, "Class declaration without a constructor is not supported yet");
 
+    failIfFalse(popScope(classScope, TreeBuilder::NeedsFreeVariableInfo), "Parser error");
     consumeOrFail(CLOSEBRACE, "Expected a closing '}' after a class body");
 
     return context.createClassExpr(location, *className, constructor, parentClass, instanceMethods, staticMethods);