1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Redistribution and use in source and binary forms, with or without
5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// modification, are permitted provided that the following conditions
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// are met:
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 1.  Redistributions of source code must retain the above copyright
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     notice, this list of conditions and the following disclaimer.
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// 2.  Redistributions in binary form must reproduce the above copyright
10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     notice, this list of conditions and the following disclaimer in the
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     documentation and/or other materials provided with the distribution.
12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction isReserved(word)
25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch{
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    try {
27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch        eval("var " + word + ";");
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch        return false;
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    } catch (e) {
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch        return true;
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    }
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar reservedWords = [
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "break",
36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "case",
37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "catch",
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "class",
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "const",
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "continue",
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "debugger",
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "default",
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "delete",
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "do",
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "else",
46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "enum",
47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "export",
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "extends",
49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "false",
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "finally",
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "for",
52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "function",
53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "if",
54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "import",
55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "in",
56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "instanceof",
57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "new",
58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "null",
59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "return",
60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "super",
61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "switch",
62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "this",
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "throw",
64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "true",
65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "try",
66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "typeof",
67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "var",
68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "void",
69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "while",
70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "with"
71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch];
72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar unreservedWords = [
74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "abstract",
75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "boolean",
76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "byte",
77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "char",
78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "double",
79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "final",
80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "float",
81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "goto",
82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "implements",
83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "int",
84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "interface",
85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "long",
86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "native",
87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "package",
88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "private",
89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "protected",
90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "public",
91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "short",
92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "static",
93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "synchronized",
94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "throws",
95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "transient",
96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    "volatile"
97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch];
98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdescription(
100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch"This file checks which ECMAScript 3 keywords are treated as reserved words."
101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch);
102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochreservedWords.sort();
104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochunreservedWords.sort();
105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdebug("SHOULD BE RESERVED:");
107b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var p in reservedWords) {
108b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    shouldBeTrue("isReserved('" + reservedWords[p] + "')");
109b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
110b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
111b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdebug("");
112b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
113b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdebug("SHOULD NOT BE RESERVED:");
114b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfor (var p in unreservedWords) {
115b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    shouldBeFalse("isReserved('" + unreservedWords[p] + "')");
116b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
117b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
118b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochdebug("");
119