JavaScriptCore:
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2006 02:54:40 +0000 (02:54 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2006 02:54:40 +0000 (02:54 +0000)
        Reviewed by Maciej.

        - Fixed <rdar://problem/4534904> please do not treat "debugger" as
        a reserved word while parsing JavaScript (and other ECMA reserved
        words)

        AKA

        http://bugzilla.opendarwin.org/show_bug.cgi?id=6179
        We treat "char" as a reserved word in JavaScript and firefox/IE do
        not

        (1) I unreserved most of the spec's "future reserved words" because
        they're not reserved in IE or FF. (Most, but not all, because IE
        somewhat randomly *does* reserve a few of them.)
        (2) I made 'debugger' a legitimate statement that acts like an empty
        statement because FF and IE support it.

        * kjs/grammar.y:
        * kjs/keywords.table:

LayoutTests:

        - Tests for JavaScript reserved words and the 'debugger' statement
        <rdar://problem/4534904>
        AKA
        http://bugzilla.opendarwin.org/show_bug.cgi?id=6179

        * fast/js/debugger-expected.txt: Added.
        * fast/js/debugger.html: Added.
        * fast/js/reserved-words-expected.txt: Added.
        * fast/js/reserved-words.html: Added.
        * fast/js/resources/debugger.js: Added.
        * fast/js/resources/reserved-words.js: Added.

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

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/keywords.table
LayoutTests/ChangeLog
LayoutTests/fast/js/debugger-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/debugger.html [new file with mode: 0644]
LayoutTests/fast/js/reserved-words-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/reserved-words.html [new file with mode: 0644]
LayoutTests/fast/js/resources/debugger.js [new file with mode: 0644]
LayoutTests/fast/js/resources/reserved-words.js [new file with mode: 0644]

index fcd4071affd1b985dcb613ef7b3f5f97ef9add11..e47f9f983ab71e5885f48e25d8ea017dadcc0ea6 100644 (file)
@@ -1,3 +1,26 @@
+2006-05-15  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Maciej.
+
+        - Fixed <rdar://problem/4534904> please do not treat "debugger" as
+        a reserved word while parsing JavaScript (and other ECMA reserved
+        words) 
+
+        AKA 
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=6179 
+        We treat "char" as a reserved word in JavaScript and firefox/IE do
+        not
+
+        (1) I unreserved most of the spec's "future reserved words" because 
+        they're not reserved in IE or FF. (Most, but not all, because IE
+        somewhat randomly *does* reserve a few of them.)
+        (2) I made 'debugger' a legitimate statement that acts like an empty
+        statement because FF and IE support it.
+        
+        * kjs/grammar.y:
+        * kjs/keywords.table:
+
 2006-05-15  Tim Omernick  <timo@apple.com>
 
         Reviewed by John Sullivan.
index fdefaaf2114c324d9f9c0b82edb5cd2281d348da..138dbd65c242b68910b99b171409deca71cdb145 100644 (file)
@@ -103,6 +103,7 @@ static Node *makeDeleteNode(Node *expr);
 %token IF THIS DO WHILE IN INSTANCEOF TYPEOF
 %token SWITCH WITH RESERVED
 %token THROW TRY CATCH FINALLY
+%token DEBUGGER
 
 /* give an if without an else higher precedence than an else to resolve the ambiguity */
 %nonassoc IF_WITHOUT_ELSE
@@ -163,6 +164,7 @@ static Node *makeDeleteNode(Node *expr);
 %type <stat>  BreakStatement ReturnStatement WithStatement
 %type <stat>  SwitchStatement LabelledStatement
 %type <stat>  ThrowStatement TryStatement
+%type <stat>  DebuggerStatement
 %type <stat>  SourceElement
 
 %type <slist> StatementList
@@ -627,6 +629,7 @@ Statement:
   | LabelledStatement
   | ThrowStatement
   | TryStatement
+  | DebuggerStatement
 ;
 
 Block:
@@ -808,6 +811,11 @@ TryStatement:
                                         { $$ = new TryNode($2, *$5, $7, $9); DBG($$, @1, @2); }
 ;
 
+DebuggerStatement:
+    DEBUGGER ';'                           { $$ = new EmptyStatementNode(); DBG($$, @1, @2); }
+  | DEBUGGER error                         { $$ = new EmptyStatementNode(); DBG($$, @1, @1); AUTO_SEMICOLON; }
+;
+
 FunctionDeclaration:
     FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode(*$2, $5); }
   | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
index 85dcaa0ea62c319f07d36f5f05335a1ff5393b94..158b984d7a328410f5ccab1420ca2f9df754f7c0 100644 (file)
@@ -1,9 +1,11 @@
 # main keywords
 @begin mainTable 41
+
 # types
 null           NULLTOKEN
 true           TRUETOKEN
 false          FALSETOKEN
+
 # keywords
 break          BREAK
 case           CASE
@@ -31,36 +33,40 @@ throw               THROW
 try            TRY
 typeof         TYPEOF
 with           WITH
+debugger       DEBUGGER
+
 # reserved for future use
-abstract       RESERVED
-boolean                RESERVED
-byte           RESERVED
-char           RESERVED
-class          RESERVED
-debugger       RESERVED
-double         RESERVED
-enum           RESERVED
-export         RESERVED
-extends                RESERVED
-final          RESERVED
-float          RESERVED
-goto           RESERVED
-implements     RESERVED
-import         RESERVED
-int            RESERVED
-interface      RESERVED
-long           RESERVED
-native         RESERVED
-package                RESERVED
-private                RESERVED
-protected      RESERVED
-public         RESERVED
-short          RESERVED
-static         RESERVED
-super          RESERVED
-synchronized   RESERVED
-throws         RESERVED
-transient      RESERVED
-volatile       RESERVED
+class           RESERVED
+enum            RESERVED
+export          RESERVED
+extends         RESERVED
+import          RESERVED
+super           RESERVED
+
+# these words are reserved for future use in the ECMA spec, but not in WinIE
+# (see http://bugzilla.opendarwin.org/show_bug.cgi?id=6179)
+# abstract      RESERVED
+# boolean       RESERVED
+# byte          RESERVED
+# char          RESERVED
+# double        RESERVED
+# final         RESERVED
+# float         RESERVED
+# goto          RESERVED
+# implements    RESERVED
+# int           RESERVED
+# interface     RESERVED
+# long          RESERVED
+# native        RESERVED
+# package       RESERVED
+# private       RESERVED
+# protected     RESERVED
+# public        RESERVED
+# short         RESERVED
+# static        RESERVED
+# synchronized  RESERVED
+# throws        RESERVED
+# transient     RESERVED
+# volatile      RESERVED
 @end
 
index d429e764db1b9dff9aa1b6c7bfdcf41734531c2e..b99b52e64900924307f3927945811426e1b9cf5d 100644 (file)
@@ -1,3 +1,17 @@
+2006-05-15  Geoffrey Garen  <ggaren@apple.com>
+
+        - Tests for JavaScript reserved words and the 'debugger' statement
+        <rdar://problem/4534904> 
+        AKA
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=6179
+
+        * fast/js/debugger-expected.txt: Added.
+        * fast/js/debugger.html: Added.
+        * fast/js/reserved-words-expected.txt: Added.
+        * fast/js/reserved-words.html: Added.
+        * fast/js/resources/debugger.js: Added.
+        * fast/js/resources/reserved-words.js: Added.
+
 2006-05-15  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Darin.
diff --git a/LayoutTests/fast/js/debugger-expected.txt b/LayoutTests/fast/js/debugger-expected.txt
new file mode 100644 (file)
index 0000000..424dd80
--- /dev/null
@@ -0,0 +1,9 @@
+This file tests whether the 'debugger' statement throws a syntax error. (IE respects 'debugger' as a statement that behaves like a breakpoint).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/debugger.html b/LayoutTests/fast/js/debugger.html
new file mode 100644 (file)
index 0000000..b77246c
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/debugger.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/reserved-words-expected.txt b/LayoutTests/fast/js/reserved-words-expected.txt
new file mode 100644 (file)
index 0000000..ca17f96
--- /dev/null
@@ -0,0 +1,72 @@
+This file checks which ECMAScript 3 keywords are treated as reserved words.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+SHOULD BE RESERVED:
+PASS isReserved('break') is true
+PASS isReserved('case') is true
+PASS isReserved('catch') is true
+PASS isReserved('class') is true
+PASS isReserved('const') is true
+PASS isReserved('continue') is true
+PASS isReserved('debugger') is true
+PASS isReserved('default') is true
+PASS isReserved('delete') is true
+PASS isReserved('do') is true
+PASS isReserved('else') is true
+PASS isReserved('enum') is true
+PASS isReserved('export') is true
+PASS isReserved('extends') is true
+PASS isReserved('false') is true
+PASS isReserved('finally') is true
+PASS isReserved('for') is true
+PASS isReserved('function') is true
+PASS isReserved('if') is true
+PASS isReserved('import') is true
+PASS isReserved('in') is true
+PASS isReserved('instanceof') is true
+PASS isReserved('new') is true
+PASS isReserved('null') is true
+PASS isReserved('return') is true
+PASS isReserved('super') is true
+PASS isReserved('switch') is true
+PASS isReserved('this') is true
+PASS isReserved('throw') is true
+PASS isReserved('true') is true
+PASS isReserved('try') is true
+PASS isReserved('typeof') is true
+PASS isReserved('var') is true
+PASS isReserved('void') is true
+PASS isReserved('while') is true
+PASS isReserved('with') is true
+
+SHOULD NOT BE RESERVED:
+PASS isReserved('abstract') is false
+PASS isReserved('boolean') is false
+PASS isReserved('byte') is false
+PASS isReserved('char') is false
+PASS isReserved('double') is false
+PASS isReserved('final') is false
+PASS isReserved('float') is false
+PASS isReserved('goto') is false
+PASS isReserved('implements') is false
+PASS isReserved('int') is false
+PASS isReserved('interface') is false
+PASS isReserved('long') is false
+PASS isReserved('native') is false
+PASS isReserved('package') is false
+PASS isReserved('private') is false
+PASS isReserved('protected') is false
+PASS isReserved('public') is false
+PASS isReserved('short') is false
+PASS isReserved('static') is false
+PASS isReserved('synchronized') is false
+PASS isReserved('throws') is false
+PASS isReserved('transient') is false
+PASS isReserved('volatile') is false
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/reserved-words.html b/LayoutTests/fast/js/reserved-words.html
new file mode 100644 (file)
index 0000000..78fd468
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/reserved-words.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/resources/debugger.js b/LayoutTests/fast/js/resources/debugger.js
new file mode 100644 (file)
index 0000000..5b1eca1
--- /dev/null
@@ -0,0 +1,7 @@
+description(
+"This file tests whether the 'debugger' statement throws a syntax error. (IE respects 'debugger' as a statement that behaves like a breakpoint)."
+);
+
+debugger
+debugger;
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/js/resources/reserved-words.js b/LayoutTests/fast/js/resources/reserved-words.js
new file mode 100644 (file)
index 0000000..5f72176
--- /dev/null
@@ -0,0 +1,97 @@
+function isReserved(word)
+{
+    try {
+        eval("var " + word + ";");
+        return false;
+    } catch (e) {
+        return true;
+    }
+}
+
+var reservedWords = [
+    "break",
+    "case",
+    "catch",
+    "class",
+    "const",
+    "continue",
+    "debugger",
+    "default",
+    "delete",
+    "do",
+    "else",
+    "enum",
+    "export",
+    "extends",
+    "false",
+    "finally",
+    "for",
+    "function",
+    "if",
+    "import",
+    "in",
+    "instanceof",
+    "new",
+    "null",
+    "return",
+    "super",
+    "switch",
+    "this",
+    "throw",
+    "true",
+    "try",
+    "typeof",
+    "var",
+    "void",
+    "while",
+    "with"
+];
+
+var unreservedWords = [
+    "abstract",
+    "boolean",
+    "byte",
+    "char",
+    "double",
+    "final",
+    "float",
+    "goto",
+    "implements",
+    "int",
+    "interface",
+    "long",
+    "native",
+    "package",
+    "private",
+    "protected",
+    "public",
+    "short",
+    "static",
+    "synchronized",
+    "throws",
+    "transient",
+    "volatile"
+];
+
+description(
+"This file checks which ECMAScript 3 keywords are treated as reserved words."
+);
+
+reservedWords.sort();
+unreservedWords.sort();
+
+debug("SHOULD BE RESERVED:");
+for (var p in reservedWords) {
+    shouldBeTrue("isReserved('" + reservedWords[p] + "')");
+}
+
+debug("");
+
+debug("SHOULD NOT BE RESERVED:");
+for (var p in unreservedWords) {
+    shouldBeFalse("isReserved('" + unreservedWords[p] + "')");
+}
+
+debug("");
+
+var successfullyParsed = true;