Title: [99513] trunk
Revision
99513
Author
[email protected]
Date
2011-11-07 18:25:20 -0800 (Mon, 07 Nov 2011)

Log Message

"use strict" can not contain escape sequences or line continuation
https://bugs.webkit.org/show_bug.cgi?id=71532

Reviewed by Darin Adler.

Source/_javascript_Core:

Store the actual literal length (before the escapes and line
continuation are encoded) while parsing the directive and use it
for the directive comparison.

* parser/Parser.cpp:
(JSC::Parser::parseSourceElements):
(JSC::Parser::parseStatement):
* parser/Parser.h:

LayoutTests:

* fast/js/basic-strict-mode-expected.txt:
* fast/js/script-tests/basic-strict-mode.js:
(testLineContinuation): Added.
(testEscapeSequence): Added.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (99512 => 99513)


--- trunk/LayoutTests/ChangeLog	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/LayoutTests/ChangeLog	2011-11-08 02:25:20 UTC (rev 99513)
@@ -1,3 +1,15 @@
+2011-11-07  Ariya Hidayat  <[email protected]>
+
+        "use strict" can not contain escape sequences or line continuation
+        https://bugs.webkit.org/show_bug.cgi?id=71532
+
+        Reviewed by Darin Adler.
+
+        * fast/js/basic-strict-mode-expected.txt:
+        * fast/js/script-tests/basic-strict-mode.js:
+        (testLineContinuation): Added.
+        (testEscapeSequence): Added.
+
 2011-11-07  Kentaro Hara  <[email protected]>
 
         Fixed wrong test results of fast/js/custom-constructors.html

Modified: trunk/LayoutTests/fast/js/basic-strict-mode-expected.txt (99512 => 99513)


--- trunk/LayoutTests/fast/js/basic-strict-mode-expected.txt	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/LayoutTests/fast/js/basic-strict-mode-expected.txt	2011-11-08 02:25:20 UTC (rev 99513)
@@ -8,6 +8,8 @@
 PASS testThis.call(true) is true
 PASS testThis.call(false) is false
 PASS testThis.call(undefined) is undefined
+PASS testLineContinuation.call(undefined) === undefined is false
+PASS testEscapeSequence.call(undefined) === undefined is false
 PASS testThis.call('a string') is 'a string'
 PASS testThisDotAccess.call('a string') is 'a string'.length
 PASS testThisDotAccess.call(null) threw exception TypeError: 'null' is not an object (evaluating 'this.length').

Modified: trunk/LayoutTests/fast/js/script-tests/basic-strict-mode.js (99512 => 99513)


--- trunk/LayoutTests/fast/js/script-tests/basic-strict-mode.js	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/LayoutTests/fast/js/script-tests/basic-strict-mode.js	2011-11-08 02:25:20 UTC (rev 99513)
@@ -20,12 +20,23 @@
     shouldThrow(str);
     shouldThrow("(function(){" + str + "})");
 }
+function testLineContinuation() {
+    "use stric\
+t";
+    return this;
+}
+function testEscapeSequence() {
+    "use\u0020strict";
+    return this;
+}
 
 shouldBe("testThis.call(null)", "null");
 shouldBe("testThis.call(1)", "1");
 shouldBe("testThis.call(true)", "true");
 shouldBe("testThis.call(false)", "false");
 shouldBe("testThis.call(undefined)", "undefined");
+shouldBeFalse("testLineContinuation.call(undefined) === undefined");
+shouldBeFalse("testEscapeSequence.call(undefined) === undefined");
 shouldBe("testThis.call('a string')", "'a string'");
 shouldBe("testThisDotAccess.call('a string')", "'a string'.length");
 shouldThrow("testThisDotAccess.call(null)");

Modified: trunk/Source/_javascript_Core/ChangeLog (99512 => 99513)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-08 02:25:20 UTC (rev 99513)
@@ -1,3 +1,19 @@
+2011-11-07  Ariya Hidayat  <[email protected]>
+
+        "use strict" can not contain escape sequences or line continuation
+        https://bugs.webkit.org/show_bug.cgi?id=71532
+
+        Reviewed by Darin Adler.
+
+        Store the actual literal length (before the escapes and line
+        continuation are encoded) while parsing the directive and use it
+        for the directive comparison.
+
+        * parser/Parser.cpp:
+        (JSC::Parser::parseSourceElements):
+        (JSC::Parser::parseStatement):
+        * parser/Parser.h:
+
 2011-11-06  Filip Pizlo  <[email protected]>
 
         DFG operationCreateThis slow path may get the wrong callee in case of inlining

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (99512 => 99513)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2011-11-08 02:25:20 UTC (rev 99513)
@@ -129,17 +129,20 @@
 
 template <Parser::SourceElementsMode mode, class TreeBuilder> TreeSourceElements Parser::parseSourceElements(TreeBuilder& context)
 {
+    const unsigned lengthOfUseStrictLiteral = 12; // "use strict".length
     TreeSourceElements sourceElements = context.createSourceElements();
     bool seenNonDirective = false;
     const Identifier* directive = 0;
+    unsigned directiveLiteralLength = 0;
     unsigned startOffset = m_token.m_info.startOffset;
     unsigned oldLastLineNumber = m_lexer->lastLineNumber();
     unsigned oldLineNumber = m_lexer->lineNumber();
     bool hasSetStrict = false;
-    while (TreeStatement statement = parseStatement(context, directive)) {
+    while (TreeStatement statement = parseStatement(context, directive, &directiveLiteralLength)) {
         if (mode == CheckForStrictMode && !seenNonDirective) {
             if (directive) {
-                if (!hasSetStrict && m_globalData->propertyNames->useStrictIdentifier == *directive) {
+                // "use strict" must be the exact literal without escape sequences or line continuation.
+                if (!hasSetStrict && directiveLiteralLength == lengthOfUseStrictLiteral && m_globalData->propertyNames->useStrictIdentifier == *directive) {
                     setStrictMode();
                     hasSetStrict = true;
                     failIfFalse(isValidStrictMode());
@@ -648,7 +651,7 @@
     return context.createBlockStatement(m_lexer->lastLineNumber(), subtree, start, m_lastLine);
 }
 
-template <class TreeBuilder> TreeStatement Parser::parseStatement(TreeBuilder& context, const Identifier*& directive)
+template <class TreeBuilder> TreeStatement Parser::parseStatement(TreeBuilder& context, const Identifier*& directive, unsigned* directiveLiteralLength)
 {
     DepthManager statementDepth(&m_statementDepth);
     m_statementDepth++;
@@ -702,6 +705,8 @@
         return parseExpressionOrLabelStatement(context);
     case STRING:
         directive = m_token.m_data.ident;
+        if (directiveLiteralLength)
+            *directiveLiteralLength = m_token.m_info.endOffset - m_token.m_info.startOffset;
         nonTrivialExpressionCount = m_nonTrivialExpressionCount;
     default:
         TreeStatement exprStatement = parseExpressionStatement(context);

Modified: trunk/Source/_javascript_Core/parser/Parser.h (99512 => 99513)


--- trunk/Source/_javascript_Core/parser/Parser.h	2011-11-08 02:14:56 UTC (rev 99512)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2011-11-08 02:25:20 UTC (rev 99513)
@@ -856,7 +856,7 @@
     
     enum SourceElementsMode { CheckForStrictMode, DontCheckForStrictMode };
     template <SourceElementsMode mode, class TreeBuilder> TreeSourceElements parseSourceElements(TreeBuilder&);
-    template <class TreeBuilder> TreeStatement parseStatement(TreeBuilder&, const Identifier*& directive);
+    template <class TreeBuilder> TreeStatement parseStatement(TreeBuilder&, const Identifier*& directive, unsigned* directiveLiteralLength = 0);
     template <class TreeBuilder> TreeStatement parseFunctionDeclaration(TreeBuilder&);
     template <class TreeBuilder> TreeStatement parseVarDeclaration(TreeBuilder&);
     template <class TreeBuilder> TreeStatement parseConstDeclaration(TreeBuilder&);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to