001 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
002 // for details. All rights reserved. Use of this source code is governed by a
003 // BSD-style license that can be found in the LICENSE file.
004
005 package com.google.dart.compiler.backend.js;
006
007 import gnu.trove.THashSet;
008
009 import java.util.Collections;
010 import java.util.Set;
011
012 /**
013 * Determines whether or not a particular string is a JavaScript keyword or not.
014 */
015 public class JsReservedIdentifiers {
016 public static final Set<String> reservedGlobalSymbols;
017
018 static {
019 String[] commonBuiltins = new String[] {
020 // 15.1.1 Value Properties of the Global Object
021 "NaN", "Infinity", "undefined",
022
023 // 15.1.2 Function Properties of the Global Object
024 "eval", "parseInt", "parseFloat", "isNan", "isFinite",
025
026 // 15.1.3 URI Handling Function Properties
027 "decodeURI", "decodeURIComponent",
028 "encodeURI",
029 "encodeURIComponent",
030
031 // 15.1.4 Constructor Properties of the Global Object
032 "Object", "Function", "Array", "String", "Boolean", "Number", "Date",
033 "RegExp", "Error", "EvalError", "RangeError", "ReferenceError",
034 "SyntaxError", "TypeError", "URIError",
035
036 // 15.1.5 Other Properties of the Global Object
037 "Math",
038
039 // 10.1.6 Activation Object
040 "arguments",
041
042 // B.2 Additional Properties (non-normative)
043 "escape", "unescape",
044
045 // Window props (https://developer.mozilla.org/en/DOM/window)
046 "applicationCache", "closed", "Components", "content", "controllers",
047 "crypto", "defaultStatus", "dialogArguments", "directories",
048 "document", "frameElement", "frames", "fullScreen", "globalStorage",
049 "history", "innerHeight", "innerWidth", "length",
050 "location", "locationbar", "localStorage", "menubar",
051 "mozInnerScreenX", "mozInnerScreenY", "mozScreenPixelsPerCssPixel",
052 "name", "navigator", "opener", "outerHeight", "outerWidth",
053 "pageXOffset", "pageYOffset", "parent", "personalbar", "pkcs11",
054 "returnValue", "screen", "scrollbars", "scrollMaxX", "scrollMaxY",
055 "self", "sessionStorage", "sidebar", "status", "statusbar", "toolbar",
056 "top", "window",
057
058 // Window methods (https://developer.mozilla.org/en/DOM/window)
059 "alert", "addEventListener", "atob", "back", "blur", "btoa",
060 "captureEvents", "clearInterval", "clearTimeout", "close", "confirm",
061 "disableExternalCapture", "dispatchEvent", "dump",
062 "enableExternalCapture", "escape", "find", "focus", "forward",
063 "GeckoActiveXObject", "getAttention", "getAttentionWithCycleCount",
064 "getComputedStyle", "getSelection", "home", "maximize", "minimize",
065 "moveBy", "moveTo", "open", "openDialog", "postMessage", "print",
066 "prompt", "QueryInterface", "releaseEvents", "removeEventListener",
067 "resizeBy", "resizeTo", "restore", "routeEvent", "scroll", "scrollBy",
068 "scrollByLines", "scrollByPages", "scrollTo", "setInterval",
069 "setResizeable", "setTimeout", "showModalDialog", "sizeToContent",
070 "stop", "uuescape", "updateCommands", "XPCNativeWrapper",
071 "XPCSafeJSOjbectWrapper",
072
073 // Mozilla Window event handlers, same cite
074 "onabort", "onbeforeunload", "onchange", "onclick", "onclose",
075 "oncontextmenu", "ondragdrop", "onerror", "onfocus", "onhashchange",
076 "onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown",
077 "onmousemove", "onmouseout", "onmouseover", "onmouseup",
078 "onmozorientation", "onpaint", "onreset", "onresize", "onscroll",
079 "onselect", "onsubmit", "onunload",
080
081 // Safari Web Content Guide
082 // http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/SafariWebContent.pdf
083 // WebKit Window member data, from WebKit DOM Reference
084 // (http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/WebKitDOMRef/DOMWindow_idl/Classes/DOMWindow/index.html)
085 // TODO(fredsa) Many, many more functions and member data to add
086 "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart",
087 "ongesturestart", "ongesturechange", "ongestureend",
088
089 // extra window methods
090 "uneval",
091
092 // keywords https://developer.mozilla.org/en/New_in_JavaScript_1.7,
093 // https://developer.mozilla.org/en/New_in_JavaScript_1.8.1
094 "getPrototypeOf", "let", "yield",
095
096 // "future reserved words"
097 "abstract", "int", "short", "boolean", "interface", "static", "byte",
098 "long", "char", "final", "native", "synchronized", "float", "package",
099 "throws", "goto", "private", "transient", "implements", "protected",
100 "volatile", "double", "public",
101
102 // IE methods
103 // (http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#)
104 "attachEvent", "clientInformation", "clipboardData", "createPopup",
105 "dialogHeight", "dialogLeft", "dialogTop", "dialogWidth",
106 "onafterprint", "onbeforedeactivate", "onbeforeprint",
107 "oncontrolselect", "ondeactivate", "onhelp", "onresizeend",
108
109 // Common browser-defined identifiers not defined in ECMAScript
110 "event", "external", "Debug", "Enumerator", "Global", "Image",
111 "ActiveXObject", "VBArray", "Components",
112
113 // Functions commonly defined on Object
114 "toString", "getClass", "constructor", "prototype", "valueOf",
115
116 // Client-side JavaScript identifiers, which are needed for linkers
117 // that don't ensure GWT's window != $wnd, document != $doc, etc.
118 // Taken from the Rhino book, pg 715
119 "Anchor", "Applet", "Attr", "Canvas", "CanvasGradient",
120 "CanvasPattern", "CanvasRenderingContext2D", "CDATASection",
121 "CharacterData", "Comment", "CSS2Properties", "CSSRule",
122 "CSSStyleSheet", "Document", "DocumentFragment", "DocumentType",
123 "DOMException", "DOMImplementation", "DOMParser", "Element", "Event",
124 "ExternalInterface", "FlashPlayer", "Form", "Frame", "History",
125 "HTMLCollection", "HTMLDocument", "HTMLElement", "IFrame", "Image",
126 "Input", "JSObject", "KeyEvent", "Link", "Location", "MimeType",
127 "MouseEvent", "Navigator", "Node", "NodeList", "Option", "Plugin",
128 "ProcessingInstruction", "Range", "RangeException", "Screen", "Select",
129 "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextArea",
130 "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer",
131 "XPathException", "XPathResult", "XSLTProcessor",
132
133 // These keywords trigger the loading of the java-plugin. For the
134 // next-generation plugin, this results in starting a new Java process.
135 "java", "Packages", "netscape", "sun", "JavaObject", "JavaClass",
136 "JavaArray", "JavaMember",
137
138 // GWT-defined identifiers
139 "$wnd", "$doc", "$entry", "$moduleName", "$moduleBase", "$gwt_version", "$sessionId",
140
141 // Identifiers used by JsStackEmulator; later set to obfuscatable
142 "$stack", "$stackDepth", "$location",
143 };
144
145 reservedGlobalSymbols = new THashSet<String>(commonBuiltins.length);
146 Collections.addAll(reservedGlobalSymbols, commonBuiltins);
147 }
148
149 private JsReservedIdentifiers() {
150 }
151 }