Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| 11 | 11 |
| 12 static const javaScriptKeywords = const <String>[ | 12 static const javaScriptKeywords = const <String>[ |
| 13 // These are current keywords. | 13 // These are current keywords. |
| 14 "break", "delete", "function", "return", "typeof", "case", "do", "if", | 14 "break", "delete", "function", "return", "typeof", "case", "do", "if", |
| 15 "switch", "var", "catch", "else", "in", "this", "void", "continue", | 15 "switch", "var", "catch", "else", "in", "this", "void", "continue", |
| 16 "false", "instanceof", "throw", "while", "debugger", "finally", "new", | 16 "false", "instanceof", "throw", "while", "debugger", "finally", "new", |
| 17 "true", "with", "default", "for", "null", "try", | 17 "true", "with", "default", "for", "null", "try", |
| 18 | 18 |
| 19 // These are future keywords. | 19 // These are future keywords. |
| 20 "abstract", "double", "goto", "native", "static", "boolean", "enum", | 20 "abstract", "double", "goto", "native", "static", "boolean", "enum", |
| 21 "implements", "package", "super", "byte", "export", "import", "private", | 21 "implements", "package", "super", "byte", "export", "import", "private", |
| 22 "synchronized", "char", "extends", "int", "protected", "throws", | 22 "synchronized", "char", "extends", "int", "protected", "throws", |
| 23 "class", "final", "interface", "public", "transient", "const", "float", | 23 "class", "final", "interface", "public", "transient", "const", "float", |
| 24 "long", "short", "volatile" | 24 "long", "short", "volatile" |
| 25 ]; | 25 ]; |
| 26 | 26 |
| 27 static const reservedPropertySymbols = | 27 static const reservedPropertySymbols = |
| 28 const <String>["__proto__", "prototype", "constructor"]; | 28 const <String>["__proto__", "prototype", "constructor", "call"]; |
| 29 | |
| 30 // Symbols that we might be using in our JS snippets. | |
| 31 static const reservedGlobalSymbols = const <String>[ | |
| 32 // Section references are from Ecma-262 | |
| 33 // (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pd f) | |
| 34 | |
| 35 // 15.1.1 Value Properties of the Global Object | |
| 36 "NaN", "Infinity", "undefined", | |
| 37 | |
| 38 // 15.1.2 Function Properties of the Global Object | |
| 39 "eval", "parseInt", "parseFloat", "isNaN", "isFinite", | |
| 40 | |
| 41 // 15.1.3 URI Handling Function Properties | |
| 42 "decodeURI", "decodeURIComponent", | |
| 43 "encodeURI", | |
| 44 "encodeURIComponent", | |
| 45 | |
| 46 // 15.1.4 Constructor Properties of the Global Object | |
| 47 "Object", "Function", "Array", "String", "Boolean", "Number", "Date", | |
| 48 "RegExp", "Error", "EvalError", "RangeError", "ReferenceError", | |
| 49 "SyntaxError", "TypeError", "URIError", | |
| 50 | |
| 51 // 15.1.5 Other Properties of the Global Object | |
| 52 "Math", | |
| 53 | |
| 54 // 10.1.6 Activation Object | |
| 55 "arguments", | |
| 56 | |
| 57 // B.2 Additional Properties (non-normative) | |
| 58 "escape", "unescape", | |
| 59 | |
| 60 // Window props (https://developer.mozilla.org/en/DOM/window) | |
| 61 "applicationCache", "closed", "Components", "content", "controllers", | |
| 62 "crypto", "defaultStatus", "dialogArguments", "directories", | |
| 63 "document", "frameElement", "frames", "fullScreen", "globalStorage", | |
| 64 "history", "innerHeight", "innerWidth", "length", | |
| 65 "location", "locationbar", "localStorage", "menubar", | |
| 66 "mozInnerScreenX", "mozInnerScreenY", "mozScreenPixelsPerCssPixel", | |
| 67 "name", "navigator", "opener", "outerHeight", "outerWidth", | |
| 68 "pageXOffset", "pageYOffset", "parent", "personalbar", "pkcs11", | |
| 69 "returnValue", "screen", "scrollbars", "scrollMaxX", "scrollMaxY", | |
| 70 "self", "sessionStorage", "sidebar", "status", "statusbar", "toolbar", | |
| 71 "top", "window", | |
| 72 | |
| 73 // Window methods (https://developer.mozilla.org/en/DOM/window) | |
| 74 "alert", "addEventListener", "atob", "back", "blur", "btoa", | |
| 75 "captureEvents", "clearInterval", "clearTimeout", "close", "confirm", | |
| 76 "disableExternalCapture", "dispatchEvent", "dump", | |
| 77 "enableExternalCapture", "escape", "find", "focus", "forward", | |
| 78 "GeckoActiveXObject", "getAttention", "getAttentionWithCycleCount", | |
| 79 "getComputedStyle", "getSelection", "home", "maximize", "minimize", | |
| 80 "moveBy", "moveTo", "open", "openDialog", "postMessage", "print", | |
| 81 "prompt", "QueryInterface", "releaseEvents", "removeEventListener", | |
| 82 "resizeBy", "resizeTo", "restore", "routeEvent", "scroll", "scrollBy", | |
| 83 "scrollByLines", "scrollByPages", "scrollTo", "setInterval", | |
| 84 "setResizeable", "setTimeout", "showModalDialog", "sizeToContent", | |
| 85 "stop", "uuescape", "updateCommands", "XPCNativeWrapper", | |
| 86 "XPCSafeJSOjbectWrapper", | |
| 87 | |
| 88 // Mozilla Window event handlers, same cite | |
| 89 "onabort", "onbeforeunload", "onchange", "onclick", "onclose", | |
| 90 "oncontextmenu", "ondragdrop", "onerror", "onfocus", "onhashchange", | |
| 91 "onkeydown", "onkeypress", "onkeyup", "onload", "onmousedown", | |
| 92 "onmousemove", "onmouseout", "onmouseover", "onmouseup", | |
| 93 "onmozorientation", "onpaint", "onreset", "onresize", "onscroll", | |
| 94 "onselect", "onsubmit", "onunload", | |
| 95 | |
| 96 // Safari Web Content Guide | |
| 97 // http://developer.apple.com/library/safari/#documentation/AppleApplication s/Reference/SafariWebContent/SafariWebContent.pdf | |
| 98 // WebKit Window member data, from WebKit DOM Reference | |
| 99 // (http://developer.apple.com/safari/library/documentation/AppleApplication s/Reference/WebKitDOMRef/DOMWindow_idl/Classes/DOMWindow/index.html) | |
| 100 "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart", | |
| 101 "ongesturestart", "ongesturechange", "ongestureend", | |
| 102 | |
| 103 // extra window methods | |
| 104 "uneval", | |
| 105 | |
| 106 // keywords https://developer.mozilla.org/en/New_in_JavaScript_1.7, | |
| 107 // https://developer.mozilla.org/en/New_in_JavaScript_1.8.1 | |
| 108 "getPrototypeOf", "let", "yield", | |
| 109 | |
| 110 // "future reserved words" | |
| 111 "abstract", "int", "short", "boolean", "interface", "static", "byte", | |
| 112 "long", "char", "final", "native", "synchronized", "float", "package", | |
| 113 "throws", "goto", "private", "transient", "implements", "protected", | |
| 114 "volatile", "double", "public", | |
| 115 | |
| 116 // IE methods | |
| 117 // (http://msdn.microsoft.com/en-us/library/ms535873(VS.85).aspx#) | |
| 118 "attachEvent", "clientInformation", "clipboardData", "createPopup", | |
| 119 "dialogHeight", "dialogLeft", "dialogTop", "dialogWidth", | |
| 120 "onafterprint", "onbeforedeactivate", "onbeforeprint", | |
| 121 "oncontrolselect", "ondeactivate", "onhelp", "onresizeend", | |
| 122 | |
| 123 // Common browser-defined identifiers not defined in ECMAScript | |
| 124 "event", "external", "Debug", "Enumerator", "Global", "Image", | |
| 125 "ActiveXObject", "VBArray", "Components", | |
| 126 | |
| 127 // Functions commonly defined on Object | |
| 128 "toString", "getClass", "constructor", "prototype", "valueOf", | |
| 129 | |
| 130 // Client-side JavaScript identifiers | |
| 131 "Anchor", "Applet", "Attr", "Canvas", "CanvasGradient", | |
| 132 "CanvasPattern", "CanvasRenderingContext2D", "CDATASection", | |
| 133 "CharacterData", "Comment", "CSS2Properties", "CSSRule", | |
| 134 "CSSStyleSheet", "Document", "DocumentFragment", "DocumentType", | |
| 135 "DOMException", "DOMImplementation", "DOMParser", "Element", "Event", | |
| 136 "ExternalInterface", "FlashPlayer", "Form", "Frame", "History", | |
| 137 "HTMLCollection", "HTMLDocument", "HTMLElement", "IFrame", "Image", | |
| 138 "Input", "JSObject", "KeyEvent", "Link", "Location", "MimeType", | |
| 139 "MouseEvent", "Navigator", "Node", "NodeList", "Option", "Plugin", | |
| 140 "ProcessingInstruction", "Range", "RangeException", "Screen", "Select", | |
| 141 "Table", "TableCell", "TableRow", "TableSelection", "Text", "TextArea", | |
| 142 "UIEvent", "Window", "XMLHttpRequest", "XMLSerializer", | |
| 143 "XPathException", "XPathResult", "XSLTProcessor", | |
| 144 | |
| 145 // These keywords trigger the loading of the java-plugin. For the | |
|
erikcorry
2013/01/31 13:21:31
Gah!
| |
| 146 // next-generation plugin, this results in starting a new Java process. | |
| 147 "java", "Packages", "netscape", "sun", "JavaObject", "JavaClass", | |
| 148 "JavaArray", "JavaMember" | |
| 149 ]; | |
| 29 | 150 |
| 30 static Set<String> _jsReserved = null; | 151 static Set<String> _jsReserved = null; |
| 31 Set<String> get jsReserved { | 152 Set<String> get jsReserved { |
| 32 if (_jsReserved == null) { | 153 if (_jsReserved == null) { |
| 33 _jsReserved = new Set<String>(); | 154 _jsReserved = new Set<String>(); |
| 34 _jsReserved.addAll(javaScriptKeywords); | 155 _jsReserved.addAll(javaScriptKeywords); |
| 35 _jsReserved.addAll(reservedPropertySymbols); | 156 _jsReserved.addAll(reservedPropertySymbols); |
| 157 _jsReserved.addAll(reservedGlobalSymbols); | |
| 36 } | 158 } |
| 37 return _jsReserved; | 159 return _jsReserved; |
| 38 } | 160 } |
| 39 | 161 |
| 40 final String CURRENT_ISOLATE = r'$'; | 162 final String CURRENT_ISOLATE = r'$'; |
| 41 | 163 |
| 42 /** | 164 /** |
| 43 * Map from top-level or static elements to their unique identifiers provided | 165 * Map from top-level or static elements to their unique identifiers provided |
| 44 * by [getName]. | 166 * by [getName]. |
| 45 * | 167 * |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 return const SourceString(r'$or'); | 717 return const SourceString(r'$or'); |
| 596 } else if (value == '-') { | 718 } else if (value == '-') { |
| 597 return const SourceString(r'$sub'); | 719 return const SourceString(r'$sub'); |
| 598 } else if (value == 'unary-') { | 720 } else if (value == 'unary-') { |
| 599 return const SourceString(r'$negate'); | 721 return const SourceString(r'$negate'); |
| 600 } else { | 722 } else { |
| 601 return name; | 723 return name; |
| 602 } | 724 } |
| 603 } | 725 } |
| 604 } | 726 } |
| OLD | NEW |