Upgrade to V8 3.3
Merge V8 at 3.3.10.39
Simple merge required updates to makefiles only.
Bug: 5688872
Change-Id: I14703f418235f5ce6013b9b3e2e502407a9f6dfd
diff --git a/test/preparser/non-use-strict-hex-escape.js b/test/preparser/non-use-strict-hex-escape.js
new file mode 100644
index 0000000..bf28923
--- /dev/null
+++ b/test/preparser/non-use-strict-hex-escape.js
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// A string looking like "use strict", but with a hex escape in it,
+// doesn't trigger strict mode.
+
+function foo() {
+ "use\x20strict";
+ var x = "hello\040world";
+ return x;
+}
\ No newline at end of file
diff --git a/test/preparser/non-use-strict-octal-escape.js b/test/preparser/non-use-strict-octal-escape.js
new file mode 100644
index 0000000..9e00742
--- /dev/null
+++ b/test/preparser/non-use-strict-octal-escape.js
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// A string looking like "use strict", but with an octal escape in it,
+// doesn't trigger strict mode.
+
+function foo() {
+ "use\040strict";
+ var x = "hello\040world";
+ return x;
+}
\ No newline at end of file
diff --git a/test/preparser/non-use-strict-uhex-escape.js b/test/preparser/non-use-strict-uhex-escape.js
new file mode 100644
index 0000000..5fba673
--- /dev/null
+++ b/test/preparser/non-use-strict-uhex-escape.js
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// A string looking like "use strict", but with a long hex escape in it,
+// doesn't trigger strict mode.
+
+function foo() {
+ "use\u0020strict";
+ var x = "hello\040world";
+ return x;
+}
\ No newline at end of file
diff --git a/test/preparser/nonstrict-arguments.js b/test/preparser/nonstrict-arguments.js
new file mode 100644
index 0000000..890f62e
--- /dev/null
+++ b/test/preparser/nonstrict-arguments.js
@@ -0,0 +1,51 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Eval restrictions should not trigger outside of strict-mode code.
+
+var arguments = 42;
+arguments = arguments++;
+arguments += --arguments;
+arguments -= ++arguments;
+arguments *= arguments--;
+function arguments(arguments) {};
+try {} catch (arguments) {}
+
+function strict() {
+ "use strict";
+ // Reading eval and arguments is allowed.
+ eval(arguments);
+}
+
+var arguments = 42;
+arguments = arguments++;
+arguments += --arguments;
+arguments -= ++arguments;
+arguments *= arguments--;
+function arguments(arguments) {};
+try {} catch (arguments) {}
+
diff --git a/test/preparser/nonstrict-eval.js b/test/preparser/nonstrict-eval.js
new file mode 100644
index 0000000..ad994ab
--- /dev/null
+++ b/test/preparser/nonstrict-eval.js
@@ -0,0 +1,51 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Eval restrictions should not trigger outside of strict-mode code.
+
+var eval = 42;
+eval = eval++;
+eval += --eval;
+eval -= ++eval;
+eval *= eval--;
+function eval(eval) {};
+try {} catch (eval) {}
+
+function strict() {
+ "use strict";
+ // Reading eval and arguments is allowed.
+ eval(arguments);
+}
+
+var eval = 42;
+eval = eval++;
+eval += --eval;
+eval -= ++eval;
+eval *= eval--;
+function eval(eval) {};
+try {} catch (eval) {}
+
diff --git a/test/preparser/nonstrict-with.js b/test/preparser/nonstrict-with.js
new file mode 100644
index 0000000..12d05a0
--- /dev/null
+++ b/test/preparser/nonstrict-with.js
@@ -0,0 +1,43 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The with statement is allowed in non-strict code, and even around
+// strict code.
+
+with ({}) {}
+
+with ({x : 42}) {
+ var foo = function () {
+ "use strict";
+ return x;
+ };
+}
+
+with ({}) {}
+
+
+
diff --git a/test/preparser/preparser.expectation b/test/preparser/preparser.expectation
new file mode 100644
index 0000000..638f90e
--- /dev/null
+++ b/test/preparser/preparser.expectation
@@ -0,0 +1,14 @@
+# Expectations for .js preparser tests.
+# Only mentions tests that throw SyntaxError, and optionally specifies
+# the message and location expected in the exception.
+# Format:
+# testname[:message[:beg_pos,end_pos]]
+strict-octal-number:strict_octal_literal
+strict-octal-string:strict_octal_literal
+strict-octal-regexp:strict_octal_literal
+strict-octal-use-strict-after:strict_octal_literal
+strict-octal-use-strict-before:strict_octal_literal
+
+strict-const:strict_const
+
+strict-with:strict_mode_with
diff --git a/test/preparser/preparser.status b/test/preparser/preparser.status
new file mode 100644
index 0000000..db17778
--- /dev/null
+++ b/test/preparser/preparser.status
@@ -0,0 +1,39 @@
+# Copyright 2011 the V8 project authors. All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+prefix preparser
+
+# We don't parse RegExps at scanning time, so we can't fail on octal
+# escapes (we need to parse to distinguish octal escapes from valid
+# back-references).
+strict-octal-regexp: FAIL
+
+##############################################################################
+[ $arch == mips ]
+
+# Skip all tests on MIPS.
+*: SKIP
diff --git a/test/preparser/strict-const.js b/test/preparser/strict-const.js
new file mode 100644
index 0000000..91e9e39
--- /dev/null
+++ b/test/preparser/strict-const.js
@@ -0,0 +1,29 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"use strict";
+const x = 42;
\ No newline at end of file
diff --git a/test/preparser/strict-function-statement.pyt b/test/preparser/strict-function-statement.pyt
new file mode 100644
index 0000000..08c4288
--- /dev/null
+++ b/test/preparser/strict-function-statement.pyt
@@ -0,0 +1,99 @@
+# Copyright 2011 the V8 project authors. All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# In strict mode, function declarations may only appear as source elements.
+
+# A template that performs the same strict-mode test in different
+# scopes (global scope, function scope, and nested function scope).
+def StrictTest(name, source):
+ Test(name, '"use strict";\n' + source, "strict_function")
+ Test(name + '-infunc',
+ 'function foo() {\n "use strict";\n' + source +'\n}\n',
+ "strict_function")
+ Test(name + '-infunc2',
+ 'function foo() {\n "use strict";\n function bar() {\n' +
+ source +'\n }\n}\n',
+ "strict_function")
+
+# Not testing with-scope, since with is not allowed in strict mode at all.
+
+StrictTest("block", """
+ { function foo() { } }
+""")
+
+StrictTest("try-w-catch", """
+ try { function foo() { } } catch (e) { }
+""")
+
+StrictTest("try-w-finally", """
+ try { function foo() { } } finally { }
+""")
+
+StrictTest("catch", """
+ try { } catch (e) { function foo() { } }
+""")
+
+StrictTest("finally", """
+ try { } finally { function foo() { } }
+""")
+
+StrictTest("for", """
+ for (;;) { function foo() { } }
+""")
+
+StrictTest("while", """
+ while (true) { function foo() { } }
+""")
+
+StrictTest("do", """
+ do { function foo() { } } while (true);
+""")
+
+StrictTest("then", """
+ if (true) { function foo() { } }
+""")
+
+
+StrictTest("then-w-else", """
+ if (true) { function foo() { } } else { }
+""")
+
+
+StrictTest("else", """
+ if (true) { } else { function foo() { } }
+""")
+
+StrictTest("switch-case", """
+ switch (true) { case true: function foo() { } }
+""")
+
+StrictTest("labeled", """
+ label: function foo() { }
+""")
+
+
+
diff --git a/test/preparser/strict-identifiers.pyt b/test/preparser/strict-identifiers.pyt
new file mode 100644
index 0000000..a0f4612
--- /dev/null
+++ b/test/preparser/strict-identifiers.pyt
@@ -0,0 +1,209 @@
+# Copyright 2011 the V8 project authors. All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Templatated tests with eval/arguments/future reserved words.
+
+# ----------------------------------------------------------------------
+# Constants and utility functions
+
+reserved_words = [
+ 'class',
+ 'const', # Has other error message than other reserved words.
+ 'enum',
+ 'export',
+ 'extends',
+ 'import',
+ 'super'
+ ]
+
+strict_reserved_words = [
+ 'implements',
+ 'interface',
+ 'let',
+ 'package',
+ 'private',
+ 'protected',
+ 'public',
+ 'static',
+ 'yield'
+ ]
+
+assign_ops = {
+ "=": "assign",
+ "+=": "addeq",
+ "-=": "subeq",
+ "*=": "muleq",
+ "/=": "diveq",
+ "%=": "modeq",
+ "&=": "andeq",
+ "|=": "oreq",
+ "^=": "xoreq",
+ "<<=": "shleq",
+ ">>=": "asreq",
+ ">>>=": "lsreq"
+ }
+
+
+# A template that performs the same strict-mode test in different
+# scopes (global scope, function scope, and nested function scope).
+def StrictTemplate(name, source):
+ def MakeTests(replacement, expectation):
+ Template(name, '"use strict";\n' + source)(replacement, expectation)
+ Template(name + '-infunc',
+ 'function foo() {\n "use strict";\n' + source +'\n}\n')(
+ replacement, expectation)
+ Template(name + '-infunc2',
+ 'function foo() {\n "use strict";\n function bar() {\n' +
+ source +'\n }\n}\n')(replacement, expectation)
+ return MakeTests
+
+# ----------------------------------------------------------------------
+# Test templates
+
+arg_name_own = Template("argument-name-own-$id", """
+ function foo($id) {
+ "use strict";
+ }
+""")
+
+arg_name_nested = Template("argument-name-nested-$id", """
+ function foo() {
+ "use strict";
+ function bar($id) { }
+ }
+""")
+
+func_name_own = Template("function-name-own-$id", """
+ function $id(foo) {
+ "use strict";
+ }
+""")
+
+func_name_nested = Template("function-name-nested-$id", """
+ function foo() {
+ "use strict";
+ function $id(bar) { }
+ }
+""")
+
+catch_var = StrictTemplate("catch-$id", """
+ try { } catch ($id) { }
+""")
+
+declare_var = StrictTemplate("var-$id", """
+ var $id = 42;
+""")
+
+assign_var = StrictTemplate("assign-$id-$opname", """
+ var x = $id $op 42;
+""")
+
+prefix_var = StrictTemplate("prefix-$opname-$id", """
+ var x = $op$id;
+""")
+
+postfix_var = StrictTemplate("postfix-$opname-$id", """
+ var x = $id$op;
+""")
+
+read_var = StrictTemplate("read-reserved-$id", """
+ var x = $id;
+""")
+
+setter_arg = StrictTemplate("setter-param-$id", """
+ var x = {set foo($id) { }};
+""")
+
+non_strict_use = Template("nonstrict-$id", """
+ var $id = 42;
+ $id++;
+ $id--;
+ ++$id;
+ --$id;
+ $id += 10;
+ $id -= 10;
+ try {} catch ($id) { }
+ function $id($id) { }
+ var x = {$id: 42};
+ x = {get $id() {}, set $id(value) {}};
+ function foo() { "use strict;" }
+ var $id = 42;
+ $id++;
+ $id--;
+ ++$id;
+ --$id;
+ $id += 10;
+ $id -= 10;
+ try {} catch ($id) { }
+ function $id($id) { }
+ x = {$id: 42};
+ x = {get $id() {}, set $id(value) {}};
+""")
+
+# ----------------------------------------------------------------------
+# Run tests
+
+# eval and arguments have specific exceptions for different uses.
+for id in ["eval", "arguments"]:
+ arg_name_own({"id": id}, "strict_param_name")
+ arg_name_nested({"id": id}, "strict_param_name")
+ func_name_own({"id": id}, "strict_function_name")
+ func_name_nested({"id": id}, "strict_function_name")
+ setter_arg({"id": id}, "strict_param_name")
+ for op in assign_ops.keys():
+ assign_var({"id": id, "op":op, "opname": assign_ops[op]},
+ "strict_lhs_assignment")
+ catch_var({"id": id}, "strict_catch_variable")
+ declare_var({"id": id}, "strict_var_name")
+ prefix_var({"id": id, "op":"++", "opname":"inc"}, "strict_lhs_prefix")
+ prefix_var({"id": id, "op":"--", "opname":"dec"}, "strict_lhs_prefix")
+ postfix_var({"id": id, "op":"++", "opname":"inc"}, "strict_lhs_postfix")
+ postfix_var({"id": id, "op":"--", "opname":"dec"}, "strict_lhs_postfix")
+ non_strict_use({"id": id}, None)
+
+
+# Reserved words just throw the same exception in all cases
+# (with "const" being special, as usual).
+for reserved_word in reserved_words + strict_reserved_words:
+ message = "strict_reserved_word"
+ if (reserved_word == "const"): message = "unexpected_token"
+ arg_name_own({"id":reserved_word}, message)
+ arg_name_nested({"id":reserved_word}, message)
+ setter_arg({"id": reserved_word}, message)
+ func_name_own({"id":reserved_word}, message)
+ func_name_nested({"id":reserved_word}, message)
+ for op in assign_ops.keys():
+ assign_var({"id":reserved_word, "op":op, "opname": assign_ops[op]}, message)
+ catch_var({"id":reserved_word}, message)
+ declare_var({"id":reserved_word}, message)
+ prefix_var({"id":reserved_word, "op":"++", "opname":"inc"}, message)
+ prefix_var({"id":reserved_word, "op":"--", "opname":"dec"}, message)
+ postfix_var({"id":reserved_word, "op":"++", "opname":"inc"}, message)
+ postfix_var({"id":reserved_word, "op":"--", "opname":"dec"}, message)
+ read_var({"id": reserved_word}, message)
+
+
diff --git a/test/preparser/strict-octal-indirect-regexp.js b/test/preparser/strict-octal-indirect-regexp.js
new file mode 100644
index 0000000..122bd3d
--- /dev/null
+++ b/test/preparser/strict-octal-indirect-regexp.js
@@ -0,0 +1,34 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with call to RegExp containing octal escape:
+
+function foo() {
+ "use strict";
+ var re = RegExp("Hello\\040World");
+ return re;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-octal-number.js b/test/preparser/strict-octal-number.js
new file mode 100644
index 0000000..d387d6a
--- /dev/null
+++ b/test/preparser/strict-octal-number.js
@@ -0,0 +1,34 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with octal number literal.
+
+function foo() {
+ "use strict";
+ var x = 012;
+ return x;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-octal-regexp.js b/test/preparser/strict-octal-regexp.js
new file mode 100644
index 0000000..fded9bf
--- /dev/null
+++ b/test/preparser/strict-octal-regexp.js
@@ -0,0 +1,34 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with octal escape in RegExp literal.
+
+function foo() {
+ "use strict";
+ var re = /hello\040world/;
+ return re;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-octal-string.js b/test/preparser/strict-octal-string.js
new file mode 100644
index 0000000..40408e6
--- /dev/null
+++ b/test/preparser/strict-octal-string.js
@@ -0,0 +1,34 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with octal escape in string literal.
+
+function foo() {
+ "use strict";
+ var x = "hello\040world";
+ return x;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-octal-use-strict-after.js b/test/preparser/strict-octal-use-strict-after.js
new file mode 100644
index 0000000..1af078a
--- /dev/null
+++ b/test/preparser/strict-octal-use-strict-after.js
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with octal escape in string/directive prologue looking like
+// "use strict", after "use strict" directive.
+
+function foo() {
+ "use strict";
+ "use\040strict";
+ return true;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-octal-use-strict-before.js b/test/preparser/strict-octal-use-strict-before.js
new file mode 100644
index 0000000..1dbb571
--- /dev/null
+++ b/test/preparser/strict-octal-use-strict-before.js
@@ -0,0 +1,35 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Strict mode with octal escape in string/directive prologue looking like
+// "use strict, before "use strict" directive.
+
+function foo() {
+ "use\040strict";
+ "use strict";
+ return true;
+}
\ No newline at end of file
diff --git a/test/preparser/strict-with.js b/test/preparser/strict-with.js
new file mode 100644
index 0000000..a19355e
--- /dev/null
+++ b/test/preparser/strict-with.js
@@ -0,0 +1,33 @@
+// Copyright 2011 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The with statement is not allowed in strict code.
+
+function foo() {
+ "use strict";
+ with ({}) {}
+}
\ No newline at end of file
diff --git a/test/preparser/testcfg.py b/test/preparser/testcfg.py
index c78d03b..39b62c3 100644
--- a/test/preparser/testcfg.py
+++ b/test/preparser/testcfg.py
@@ -30,14 +30,16 @@
from os.path import join, dirname, exists
import platform
import utils
-
+import re
class PreparserTestCase(test.TestCase):
- def __init__(self, root, path, executable, mode, context):
+ def __init__(self, root, path, executable, mode, throws, context, source):
super(PreparserTestCase, self).__init__(context, path, mode)
self.executable = executable
self.root = root
+ self.throws = throws
+ self.source = source
def GetLabel(self):
return "%s %s %s" % (self.mode, self.path[-2], self.path[-1])
@@ -45,9 +47,20 @@
def GetName(self):
return self.path[-1]
+ def HasSource(self):
+ return self.source is not None
+
+ def GetSource():
+ return self.source
+
def BuildCommand(self, path):
- testfile = join(self.root, self.GetName()) + ".js"
- result = [self.executable, testfile]
+ if (self.source is not None):
+ result = [self.executable, "-e", self.source]
+ else:
+ testfile = join(self.root, self.GetName()) + ".js"
+ result = [self.executable, testfile]
+ if (self.throws):
+ result += ['throws'] + self.throws
return result
def GetCommand(self):
@@ -65,19 +78,74 @@
def GetBuildRequirements(self):
return ['preparser']
+ def GetExpectations(self):
+ expects_file = join(self.root, 'preparser.expectation')
+ map = {}
+ if exists(expects_file):
+ rule_regex = re.compile("^([\w\-]+)(?::([\w\-]+))?(?::(\d+),(\d+))?$")
+ for line in utils.ReadLinesFrom(expects_file):
+ if (line[0] == '#'): continue
+ rule_match = rule_regex.match(line)
+ if rule_match:
+ expects = []
+ if (rule_match.group(2)):
+ expects = expects + [rule_match.group(2)]
+ if (rule_match.group(3)):
+ expects = expects + [rule_match.group(3), rule_match.group(4)]
+ map[rule_match.group(1)] = expects
+ return map;
+
+ def ParsePythonTestTemplates(self, result, filename,
+ executable, current_path, mode):
+ pathname = join(self.root, filename + ".pyt")
+ source = open(pathname).read();
+ def Test(name, source, expectation):
+ throws = None
+ if (expectation is not None):
+ throws = [expectation]
+ test = PreparserTestCase(self.root,
+ current_path + [filename, name],
+ executable,
+ mode, throws, self.context,
+ source.replace("\n", " "))
+ result.append(test)
+ def Template(name, source):
+ def MkTest(replacement, expectation):
+ testname = name
+ testsource = source
+ for key in replacement.keys():
+ testname = testname.replace("$"+key, replacement[key]);
+ testsource = testsource.replace("$"+key, replacement[key]);
+ Test(testname, testsource, expectation)
+ return MkTest
+ eval(compile(source, pathname, "exec"),
+ {"Test": Test, "Template": Template}, {})
+
def ListTests(self, current_path, path, mode, variant_flags):
executable = join('obj', 'preparser', mode, 'preparser')
if utils.IsWindows():
executable += '.exe'
executable = join(self.context.buildspace, executable)
+ expectations = self.GetExpectations()
+ result = []
# Find all .js files in tests/preparser directory.
filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")]
filenames.sort()
- result = []
for file in filenames:
+ throws = None;
+ if (file in expectations):
+ throws = expectations[file]
result.append(PreparserTestCase(self.root,
current_path + [file], executable,
- mode, self.context))
+ mode, throws, self.context, None))
+ # Find all .pyt files in test/preparser directory.
+ filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")]
+ filenames.sort()
+ for file in filenames:
+ # Each file as a python source file to be executed in a specially
+ # perparsed environment (defining the Template and Test functions)
+ self.ParsePythonTestTemplates(result, file,
+ executable, current_path, mode)
return result
def GetTestStatus(self, sections, defs):
@@ -85,6 +153,9 @@
if exists(status_file):
test.ReadConfigurationInto(status_file, sections, defs)
+ def VariantFlags(self):
+ return [[]];
+
def GetConfiguration(context, root):
return PreparserTestConfiguration(context, root)