haikuwebkit/LayoutTests/js/class-syntax-name.html

9 lines
209 B
HTML
Raw Permalink Normal View History

ES6: Classes: Program level class statement throws exception in strict mode https://bugs.webkit.org/show_bug.cgi?id=143038 Reviewed by Ryosuke Niwa. Source/JavaScriptCore: Classes expose a name to the current lexical environment. This treats "class X {}" like "var X = class X {}". Ideally it would be "let X = class X {}". Also, improve error messages for class statements where the class is missing a name. * parser/Parser.h: * parser/Parser.cpp: (JSC::Parser<LexerType>::parseClass): Fill name in info parameter if needed. Better error message if name is needed and missing. (JSC::Parser<LexerType>::parseClassDeclaration): Pass info parameter to get name, and expose the name as a variable name. (JSC::Parser<LexerType>::parsePrimaryExpression): Pass info parameter that is ignored. * parser/ParserFunctionInfo.h: Add a parser info for class, to extract the name. LayoutTests: This updates a number of existing tests that were relying on poor behavior. `shouldBe` and friends use eval within a function not at the global scope. This means `shouldBe('class X { ... }')` behaves like `shouldBe('var x = ...')` not `shouldBe('x = ...')`. This means `x` will not be available in the next `shouldBe` call. Add a test specifically to cover the scoping of the class name in regular and strict mode code. Currently we treat it like var with one failing test that would pass when we treat it like let. * js/class-syntax-name.html: Added. * js/script-tests/class-syntax-name.js: Added. (runTestShouldBe): (runTestShouldBeTrue): (runTestShouldThrow): (runTestShouldNotThrow): Test class name scoping. * js/class-syntax-call-expected.txt: * js/class-syntax-declaration-expected.txt: * js/class-syntax-default-constructor-expected.txt: * js/class-syntax-name-expected.txt: Added. * js/script-tests/class-syntax-call.js: * js/script-tests/class-syntax-declaration.js: * js/script-tests/class-syntax-default-constructor.js: Canonical link: https://commits.webkit.org/161082@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181973 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-03-25 21:33:59 +00:00
<!DOCTYPE html>
<html>
<body>
<script src="../resources/js-test-pre.js"></script>
<script src="script-tests/class-syntax-name.js"></script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>