Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/js_names.dart

Issue 12049036: Cleanup the namer, and add a test with fields that used to clash with internal names used by the co… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of ssa;
6
7 class JsNames {
8 static const javaScriptKeywords = const <String>[
9 // These are current keywords
10 "break", "delete", "function", "return", "typeof", "case", "do", "if",
11 "switch", "var", "catch", "else", "in", "this", "void", "continue",
12 "false", "instanceof", "throw", "while", "debugger", "finally", "new",
13 "true", "with", "default", "for", "null", "try",
14
15 // These are future keywords
16 "abstract", "double", "goto", "native", "static", "boolean", "enum",
17 "implements", "package", "super", "byte", "export", "import", "private",
18 "synchronized", "char", "extends", "int", "protected", "throws",
19 "class", "final", "interface", "public", "transient", "const", "float",
20 "long", "short", "volatile"
21 ];
22
23 static const reservedGlobalSymbols = const <String>[
24 // Section references are from Ecma-262
25 // (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pd f)
26
27 // 15.1.1 Value Properties of the Global Object
28 "NaN", "Infinity", "undefined",
29
30 // 15.1.2 Function Properties of the Global Object
31 "eval", "parseInt", "parseFloat", "isNan", "isFinite",
32
33 // 15.1.3 URI Handling Function Properties
34 "decodeURI", "decodeURIComponent",
35 "encodeURI",
36 "encodeURIComponent",
37
38 // 15.1.4 Constructor Properties of the Global Object
39 "Object", "Function", "Array", "String", "Boolean", "Number", "Date",
40 "RegExp", "Error", "EvalError", "RangeError", "ReferenceError",
41 "SyntaxError", "TypeError", "URIError",
42
43 // 15.1.5 Other Properties of the Global Object
44 "Math",
45
46 // 10.1.6 Activation Object
47 "arguments",
48
49 // B.2 Additional Properties (non-normative)
50 "escape", "unescape",
51
52 // Window props (https://developer.mozilla.org/en/DOM/window)
53 "applicationCache", "closed", "Components", "content", "controllers",
54 "crypto", "defaultStatus", "dialogArguments", "directories",
55 "document", "frameElement", "frames", "fullScreen", "globalStorage",
56 "history", "innerHeight", "innerWidth", "length",
57 "location", "locationbar", "localStorage", "menubar",
58 "mozInnerScreenX", "mozInnerScreenY", "mozScreenPixelsPerCssPixel",
59 "name", "navigator", "opener", "outerHeight", "outerWidth",
60 "pageXOffset", "pageYOffset", "parent", "personalbar", "pkcs11",
61 "returnValue", "screen", "scrollbars", "scrollMaxX", "scrollMaxY",
62 "self", "sessionStorage", "sidebar", "status", "statusbar", "toolbar",
63 "top", "window",
64
65 // Window methods (https://developer.mozilla.org/en/DOM/window)
66 "alert", "addEventListener", "atob", "back", "blur", "btoa",
67 "captureEvents", "clearInterval", "clearTimeout", "close", "confirm",
68 "disableExternalCapture", "dispatchEvent", "dump",
69 "enableExternalCapture", "escape", "find", "focus", "forward",
70 "GeckoActiveXObject", "getAttention", "getAttentionWithCycleCount",
71 "getComputedStyle", "getSelection", "home", "maximize", "minimize",
72 "moveBy", "moveTo", "open", "openDialog", "postMessage", "print",
73 "prompt", "QueryInterface", "releaseEvents", "removeEventListener",
74 "resizeBy", "resizeTo", "restore", "routeEvent", "scroll", "scrollBy",
75 "scrollByLines", "scrollByPages", "scrollTo", "setInterval",
76 "setResizeable", "setTimeout", "showModalDialog", "sizeToContent",
77 "stop", "uuescape", "updateCommands", "XPCNativeWrapper",
78 "XPCSafeJSOjbectWrapper",
79
80 // Mozilla Window event handlers, same cite
81 "onabort", "onbeforeunload", "onchange", "onclick", "onclose",
82 "oncontextmenu", "ondragdrop", "onerror", "onfocus", "onhashchange",
83 "onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown",
84 "onmousemove", "onmouseout", "onmouseover", "onmouseup",
85 "onmozorientation", "onpaint", "onreset", "onresize", "onscroll",
86 "onselect", "onsubmit", "onunload",
87
88 // Safari Web Content Guide
89 // http://developer.apple.com/library/safari/#documentation/AppleApplication s/Reference/SafariWebContent/SafariWebContent.pdf
90 // WebKit Window member data, from WebKit DOM Reference
91 // (http://developer.apple.com/safari/library/documentation/AppleApplication s/Reference/WebKitDOMRef/DOMWindow_idl/Classes/DOMWindow/index.html)
92 "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart",
93 "ongesturestart", "ongesturechange", "ongestureend",
94
95 // extra window methods
96 "uneval",
97
98 // keywords https://developer.mozilla.org/en/New_in_JavaScript_1.7,
99 // https://developer.mozilla.org/en/New_in_JavaScript_1.8.1
100 "getPrototypeOf", "let", "yield",
101
102 // "future reserved words"
103 "abstract", "int", "short", "boolean", "interface", "static", "byte",
104 "long", "char", "final", "native", "synchronized", "float", "package",
105 "throws", "goto", "private", "transient", "implements", "protected",
106 "volatile", "double", "public",
107
108 // IE methods
109 // (http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#)
110 "attachEvent", "clientInformation", "clipboardData", "createPopup",
111 "dialogHeight", "dialogLeft", "dialogTop", "dialogWidth",
112 "onafterprint", "onbeforedeactivate", "onbeforeprint",
113 "oncontrolselect", "ondeactivate", "onhelp", "onresizeend",
114
115 // Common browser-defined identifiers not defined in ECMAScript
116 "event", "external", "Debug", "Enumerator", "Global", "Image",
117 "ActiveXObject", "VBArray", "Components",
118
119 // Functions commonly defined on Object
120 "toString", "getClass", "constructor", "prototype", "valueOf",
121
122 // Client-side JavaScript identifiers, which are needed for linkers
123 // that don't ensure GWT's window != $wnd, document != $doc, etc.
124 // Taken from the Rhino book, pg 715
125 "Anchor", "Applet", "Attr", "Canvas", "CanvasGradient",
126 "CanvasPattern", "CanvasRenderingContext2D", "CDATASection",
127 "CharacterData", "Comment", "CSS2Properties", "CSSRule",
128 "CSSStyleSheet", "Document", "DocumentFragment", "DocumentType",
129 "DOMException", "DOMImplementation", "DOMParser", "Element", "Event",
130 "ExternalInterface", "FlashPlayer", "Form", "Frame", "History",
131 "HTMLCollection", "HTMLDocument", "HTMLElement", "IFrame", "Image",
132 "Input", "JSObject", "KeyEvent", "Link", "Location", "MimeType",
133 "MouseEvent", "Navigator", "Node", "NodeList", "Option", "Plugin",
134 "ProcessingInstruction", "Range", "RangeException", "Screen", "Select",
135 "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextArea",
136 "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer",
137 "XPathException", "XPathResult", "XSLTProcessor",
138
139 // These keywords trigger the loading of the java-plugin. For the
140 // next-generation plugin, this results in starting a new Java process.
141 "java", "Packages", "netscape", "sun", "JavaObject", "JavaClass",
142 "JavaArray", "JavaMember",
143
144 // GWT-defined identifiers
145 "\$wnd", "\$doc", "\$entry", "\$moduleName", "\$moduleBase",
146 "\$gwt_version", "\$sessionId",
147
148 // Identifiers used by JsStackEmulator; later set to obfuscatable
149 "\$stack", "\$stackDepth", "\$location",
150
151 // TODO: prove why this is necessary or remove it
152 "call"
153 ];
154
155 static const reservedPropertySymbols =
156 const <String>["__PROTO__", "prototype", "constructor"];
157
158 static Set<String> _reserved;
159 static Set<String> _reservedNativeProperties;
160
161 static Set<String> get reserved {
162 if (_reserved == null) {
163 _reserved = new Set<String>();
164 _reserved.addAll(reservedPropertySymbols);
165 _reserved.addAll(reservedGlobalSymbols);
166 _reserved.addAll(javaScriptKeywords);
167 }
168 return _reserved;
169 }
170
171 static Set<String> get reservedNativeProperties {
172 // TODO(sra): We need a complete list from the DOM.
173 if (_reservedNativeProperties == null) {
174 const names = const <String>["x", "y", "z"];
175 _reservedNativeProperties = new Set<String>();
176 _reservedNativeProperties.addAll(names);
177 }
178 return _reservedNativeProperties;
179 }
180
181 // TODO(ngeoffray): only the namer should call this method.
182 // Eventually move it there.
183 /*
184 * Returns a name that does not clash with reserved JS keywords,
185 * and also ensures it won't clash with other identifiers.
186 */
187 static String getValid(String name) {
188 if (reserved.contains(name)) {
189 name = '$name\$';
190 assert(!reserved.contains(name));
191 } else if (name.contains(r'$')) {
192 name = name.replaceAll(r'$', r'$$');
193 }
194 return name;
195 }
196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698