OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" | 7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" |
8 | 8 |
9 import os | 9 import os |
| 10 from sets import Set |
| 11 from generator import AnalyzeOperation, AnalyzeConstructor |
10 | 12 |
11 from generator import AnalyzeOperation, AnalyzeConstructor | 13 # This is list of all methods with native c++ implementations |
| 14 # If performing a dartium merge, the best practice is to comment out this list, |
| 15 # ensure everything runs, and then uncomment this list which might possibly |
| 16 # introduce breaking changes due to changes to these method signatures. |
| 17 _js_custom_members = Set([ |
| 18 'Document.createElement', |
| 19 'Element.id', |
| 20 'Element.tagName', |
| 21 'Element.className', |
| 22 'Element.setAttribute', |
| 23 'Element.getAttribute', |
| 24 # Consider adding this method so there is a fast path to access only |
| 25 # element children. |
| 26 # 'NonDocumentTypeChildNode.nextElementSibling', |
| 27 'Node.appendChild', # actually not removed, just native implementation. |
| 28 'Node.cloneNode', |
| 29 'Node.insertBefore', |
| 30 'Node.lastChild', |
| 31 'Node.firstChild', |
| 32 'Node.parentElement', |
| 33 'Node.parentNode', |
| 34 'Node.childNodes', |
| 35 'Node.removeChild', |
| 36 'Node.contains', |
| 37 'Node.nextSibling', |
| 38 'Node.previousSibling', |
| 39 'ChildNode.remove', |
| 40 'Document.createTextNode', |
| 41 'Window.location', |
| 42 'Location.href', |
| 43 'Node.querySelector', |
| 44 |
| 45 'HTMLElement.hidden', |
| 46 'HTMLElement.style', |
| 47 'Element.attributes', |
| 48 'Window.innerWidth', |
| 49 |
| 50 'NodeList.length', |
| 51 'NodeList.item', |
| 52 'ParentNode.children', |
| 53 'ParentNode.firstElementChild', |
| 54 'ParentNode.lastElementChild', |
| 55 'Event.target', |
| 56 'MouseEvent.clientY', |
| 57 'MouseEvent.clientX', |
| 58 |
| 59 'Node.nodeType', |
| 60 'Node.textContent', |
| 61 |
| 62 'HTMLCollection.length', |
| 63 'HTMLCollection.item', |
| 64 'Node.lastElementChild', |
| 65 'Node.firstElementChild', |
| 66 'HTMLElement_tabIndex', |
| 67 |
| 68 'Element.clientWidth', |
| 69 'Element.clientHeight', |
| 70 'Document.body', |
| 71 'Element.removeAttribute', |
| 72 'Element.getBoundingClientRect', |
| 73 'CSSStyleDeclaration.getPropertyValue', |
| 74 'CSSStyleDeclaration.setProperty', |
| 75 'CSSStyleDeclaration.__propertyQuery__', |
| 76 |
| 77 # TODO(jacobr): consider implementing these methods as well as they show |
| 78 # up in benchmarks for some sample applications. |
| 79 #'Document.createEvent', |
| 80 #'Document.initEvent', |
| 81 #'EventTarget.dispatchEvent', |
| 82 ]) |
| 83 |
| 84 # Uncomment out this line to short circuited native methods and run all of |
| 85 # dart:html through JS interop except for createElement which is slightly more |
| 86 # tightly natively wired. |
| 87 # _js_custom_members = Set([]) |
12 | 88 |
13 HEADER = """/* Copyright (c) 2014, the Dart project authors. Please see the AUT
HORS file | 89 HEADER = """/* Copyright (c) 2014, the Dart project authors. Please see the AUT
HORS file |
14 * for details. All rights reserved. Use of this source code is governed by a | 90 * for details. All rights reserved. Use of this source code is governed by a |
15 * BSD-style license that can be found in the LICENSE file. | 91 * BSD-style license that can be found in the LICENSE file. |
16 * | 92 * |
17 * DO NOT EDIT | 93 * DO NOT EDIT |
18 * Auto-generated _blink library. | 94 * Auto-generated _blink library. |
19 */ | 95 */ |
20 library dart.dom._blink; | 96 library dart.dom._blink; |
21 | 97 |
(...skipping 21 matching lines...) Expand all Loading... |
43 static window() native "Utils_window"; | 119 static window() native "Utils_window"; |
44 | 120 |
45 static forwardingPrint(message) native "Utils_forwardingPrint"; | 121 static forwardingPrint(message) native "Utils_forwardingPrint"; |
46 | 122 |
47 static spawnDomUri(uri) native "Utils_spawnDomUri"; | 123 static spawnDomUri(uri) native "Utils_spawnDomUri"; |
48 | 124 |
49 static void spawnDomHelper(Function f, int replyTo) native "Utils_spawnDomHelp
er"; | 125 static void spawnDomHelper(Function f, int replyTo) native "Utils_spawnDomHelp
er"; |
50 | 126 |
51 static register(document, tag, customType, extendsTagName) native "Utils_regis
ter"; | 127 static register(document, tag, customType, extendsTagName) native "Utils_regis
ter"; |
52 | 128 |
53 static createElement(document, tagName) native "Utils_createElement"; | 129 // Defines an interceptor if there is an appropriate JavaScript prototype to d
efine it on. |
| 130 // In any case, returns a typed JS wrapper compatibile with dart:html and the
new |
| 131 // typed JS Interop. |
| 132 static defineInterceptorCustomElement(jsObject, Type type) native "Utils_defin
eInterceptorCustomElement"; |
| 133 static setInstanceInterceptor(o, Type type, {bool customElement: false}) nativ
e "Utils_setInstanceInterceptor"; |
54 | 134 |
55 static constructElement(element_type, jsObject) native "Utils_constructor_crea
te"; | 135 // This method will throw if the element isn't actually a real Element. |
56 | |
57 static initializeCustomElement(element) native "Utils_initializeCustomElement"
; | 136 static initializeCustomElement(element) native "Utils_initializeCustomElement"
; |
58 | |
59 static changeElementWrapper(element, type) native "Utils_changeElementWrapper"
; | |
60 } | 137 } |
61 | 138 |
62 class Blink_DOMWindowCrossFrame { | 139 class Blink_DOMWindowCrossFrame { |
63 // FIXME: Return to using explicit cross frame entry points after roll to M35 | 140 // FIXME: Return to using explicit cross frame entry points after roll to M35 |
64 static get_history(_DOMWindowCrossFrame) native "Window_history_cross_frame_Ge
tter"; | 141 static get_history(_DOMWindowCrossFrame) native "Window_history_cross_frame_Ge
tter"; |
65 | 142 |
66 static get_location(_DOMWindowCrossFrame) native "Window_location_cross_frame_
Getter"; | 143 static get_location(_DOMWindowCrossFrame) native "Window_location_cross_frame_
Getter"; |
67 | 144 |
68 static get_closed(_DOMWindowCrossFrame) native "Window_closed_Getter"; | 145 static get_closed(_DOMWindowCrossFrame) native "Window_closed_Getter"; |
69 | 146 |
(...skipping 29 matching lines...) Expand all Loading... |
99 static item(_DOMStringMap, key) native "DOMStringMap_item_Callback"; | 176 static item(_DOMStringMap, key) native "DOMStringMap_item_Callback"; |
100 | 177 |
101 static setItem(_DOMStringMap, key, value) native "DOMStringMap_setItem_Callbac
k"; | 178 static setItem(_DOMStringMap, key, value) native "DOMStringMap_setItem_Callbac
k"; |
102 | 179 |
103 static remove(_DOMStringMap, key) native "DOMStringMap_remove_Callback"; | 180 static remove(_DOMStringMap, key) native "DOMStringMap_remove_Callback"; |
104 | 181 |
105 static get_keys(_DOMStringMap) native "DOMStringMap_getKeys_Callback"; | 182 static get_keys(_DOMStringMap) native "DOMStringMap_getKeys_Callback"; |
106 } | 183 } |
107 | 184 |
108 // Calls through JsNative but returns DomException instead of error strings. | 185 // Calls through JsNative but returns DomException instead of error strings. |
| 186 class Stats { |
| 187 Stats(this.name) { |
| 188 counts = new Map<String, int>(); |
| 189 } |
| 190 |
| 191 String name; |
| 192 Map<String, int> counts; |
| 193 clear() { |
| 194 counts.clear(); |
| 195 } |
| 196 |
| 197 track(String v) { |
| 198 counts[v] = counts.putIfAbsent(v, ()=> 0) + 1; |
| 199 } |
| 200 toString() { |
| 201 StringBuffer sb = new StringBuffer(); |
| 202 sb.write('================'); |
| 203 sb.write('$name ${counts.length}'); |
| 204 var keys = counts.keys.toList(); |
| 205 keys.sort((a,b) => counts[b].compareTo(counts[a])); |
| 206 for (var key in keys) { |
| 207 print("$key => ${counts[key]}"); |
| 208 } |
| 209 sb.write('---------------'); |
| 210 sb.write('================'); |
| 211 return sb; |
| 212 } |
| 213 } |
| 214 |
| 215 bool TRACK_STATS = true; |
| 216 dumpStats() { |
| 217 print("------------ STATS ----------------"); |
| 218 print(Blink_JsNative_DomException.getPropertyStats.toString()); |
| 219 print(Blink_JsNative_DomException.setPropertyStats.toString()); |
| 220 print(Blink_JsNative_DomException.callMethodStats.toString()); |
| 221 print(Blink_JsNative_DomException.constructorStats.toString()); |
| 222 print("-----------------------------------"); |
| 223 } |
| 224 |
| 225 clearStats() { |
| 226 Blink_JsNative_DomException.getPropertyStats.clear(); |
| 227 Blink_JsNative_DomException.setPropertyStats.clear(); |
| 228 Blink_JsNative_DomException.callMethodStats.clear(); |
| 229 Blink_JsNative_DomException.constructorStats.clear(); |
| 230 } |
| 231 |
109 class Blink_JsNative_DomException { | 232 class Blink_JsNative_DomException { |
110 static getProperty(js.JsObject o, name) { | 233 static var getPropertyStats = new Stats('get property'); |
| 234 static var setPropertyStats = new Stats('set property'); |
| 235 static var callMethodStats = new Stats('call method'); |
| 236 static var constructorStats = new Stats('constructor'); |
| 237 |
| 238 static var constructors = new Map<String, dynamic>(); |
| 239 |
| 240 static getProperty(o, String name) { |
111 try { | 241 try { |
| 242 if (TRACK_STATS) getPropertyStats.track(name); |
112 return js.JsNative.getProperty(o, name); | 243 return js.JsNative.getProperty(o, name); |
113 } catch (e) { | 244 } catch (e) { |
114 // Re-throw any errors (returned as a string) as a DomException. | 245 // Re-throw any errors (returned as a string) as a DomException. |
115 throw new DomException.jsInterop(e); | 246 throw new DomException.jsInterop(e); |
116 } | 247 } |
117 } | 248 } |
118 | 249 |
119 static callMethod(js.JsObject o, String method, List args) { | 250 static propertyQuery(o, String name) { |
120 try { | 251 try { |
| 252 if (TRACK_STATS) getPropertyStats.track('__propertyQuery__'); |
| 253 return js.JsNative.getProperty(o, name); |
| 254 } catch (e) { |
| 255 // Re-throw any errors (returned as a string) as a DomException. |
| 256 throw new DomException.jsInterop(e); |
| 257 } |
| 258 } |
| 259 |
| 260 static callConstructor0(String name) { |
| 261 try { |
| 262 if (TRACK_STATS) constructorStats.track(name); |
| 263 var constructor = constructors.putIfAbsent(name, () => js.context[name]); |
| 264 return js.JsNative.callConstructor0(constructor); |
| 265 } catch (e) { |
| 266 // Re-throw any errors (returned as a string) as a DomException. |
| 267 throw new DomException.jsInterop(e); |
| 268 } |
| 269 } |
| 270 |
| 271 static callConstructor(String name, List args) { |
| 272 try { |
| 273 if (TRACK_STATS) constructorStats.track(name); |
| 274 var constructor = constructors.putIfAbsent(name, () => js.context[name]); |
| 275 return js.JsNative.callConstructor(constructor, args); |
| 276 } catch (e) { |
| 277 // Re-throw any errors (returned as a string) as a DomException. |
| 278 throw new DomException.jsInterop(e); |
| 279 } |
| 280 } |
| 281 |
| 282 static setProperty(o, String name, value) { |
| 283 try { |
| 284 if (TRACK_STATS) setPropertyStats.track(name); |
| 285 return js.JsNative.setProperty(o, name, value); |
| 286 } catch (e) { |
| 287 // Re-throw any errors (returned as a string) as a DomException. |
| 288 throw new DomException.jsInterop(e); |
| 289 } |
| 290 } |
| 291 |
| 292 static callMethod(o, String method, List args) { |
| 293 try { |
| 294 if (TRACK_STATS) callMethodStats.track(method); |
121 return js.JsNative.callMethod(o, method, args); | 295 return js.JsNative.callMethod(o, method, args); |
122 } catch (e) { | 296 } catch (e) { |
123 // Re-throw any errors (returned as a string) as a DomException. | 297 // Re-throw any errors (returned as a string) as a DomException. |
124 throw new DomException.jsInterop(e); | 298 throw new DomException.jsInterop(e); |
125 } | 299 } |
126 } | 300 } |
127 }""" | 301 }""" |
128 | 302 |
129 CLASS_DEFINITION = """class Blink%s { | 303 CLASS_DEFINITION = """class Blink%s { |
130 static final instance = new Blink%s(); | 304 static final instance = new Blink%s(); |
131 | 305 |
132 """ | 306 """ |
133 | 307 |
134 CLASS_DEFINITION_EXTENDS = """class Blink%s extends Blink%s { | 308 CLASS_DEFINITION_EXTENDS = """class Blink%s extends Blink%s { |
135 static final instance = new Blink%s(); | 309 static final instance = new Blink%s(); |
136 | 310 |
137 """ | 311 """ |
138 | 312 |
139 #(interface_name) | 313 #(interface_name) |
140 CONSTRUCTOR_0 = ' constructorCallback_0_() => new js.JsObject(Blink_JsNative_Do
mException.getProperty(js.context, "%s"), []);\n\n' | 314 |
| 315 # |
| 316 CONSTRUCTOR_0 = [' constructorCallback_0_()', |
| 317 ' => Blink_JsNative_DomException.callConstructor0("%s");\n\n', |
| 318 ' native "Blink_Constructor_%s";\n\n'] |
141 | 319 |
142 #(argument_count, arguments, interface_name, arguments) | 320 #(argument_count, arguments, interface_name, arguments) |
143 CONSTRUCTOR_ARGS = ' constructorCallback_%s_(%s) => new js.JsObject(Blink_JsNat
ive_DomException.getProperty(js.context, "%s"), [%s]);\n\n' | 321 CONSTRUCTOR_ARGS = [' constructorCallback_%s_(%s)', |
| 322 ' => Blink_JsNative_DomException.callConstructor("%s", [%s]);\n\n', |
| 323 ' native "Blink_Constructor_Args_%s" /* %s */;\n\n'] |
144 | 324 |
145 #(attribute_name, attribute_name) | 325 #(attribute_name, attribute_name) |
146 ATTRIBUTE_GETTER = ' %s_Getter_(mthis) => Blink_JsNative_DomException.getProper
ty(mthis, "%s");\n\n' | 326 ATTRIBUTE_GETTER = [' %s_Getter_(mthis)', |
147 ATTRIBUTE_SETTER = ' %s_Setter_(mthis, __arg_0) => mthis["%s"] = __arg_0;\n\n' | 327 ' => Blink_JsNative_DomException.getProperty(mthis /* %s */,
"%s");\n\n', |
| 328 ' native "Blink_Getter_%s_%s";\n\n' |
| 329 ] |
| 330 |
| 331 ATTRIBUTE_SETTER = [' %s_Setter_(mthis, __arg_0)', |
| 332 ' => Blink_JsNative_DomException.setProperty(mthis /* %s */,
"%s", __arg_0);\n\n', |
| 333 ' native "Blink_Setter_%s_%s";\n\n' |
| 334 ] |
148 | 335 |
149 #(operation_name, operationName) | 336 #(operation_name, operationName) |
150 OPERATION_0 = ' %s_Callback_0_(mthis) => Blink_JsNative_DomException.callMethod
(mthis, "%s", []);\n\n' | 337 OPERATION_0 = [' %s_Callback_0_(mthis)', |
| 338 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[]);\n\n', |
| 339 ' native "Blink_Operation_0_%s_%s";\n\n' |
| 340 ] |
151 | 341 |
152 # getter, setter, deleter and propertyQuery code | 342 # getter, setter, deleter and propertyQuery code |
153 OPERATION_1 = ' $%s_Callback_1_(mthis, __arg_0) => Blink_JsNative_DomException.
callMethod(mthis, "%s", [__arg_0]);\n\n' | 343 OPERATION_1 = [' $%s_Callback_1_(mthis, __arg_0)', |
154 OPERATION_2 = ' $%s_Callback_2_(mthis, __arg_0, __arg_1) => Blink_JsNative_DomE
xception.callMethod(mthis, "%s", [__arg_0, __arg_1]);\n\n' | 344 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0]);\n\n', |
155 OPERATION_PQ = ' $%s_Callback_1_(mthis, __arg_0) => mthis[__arg_0];\n\n' | 345 ' native "Blink_Operation_1_%s_%s";\n\n' |
| 346 ] |
| 347 |
| 348 OPERATION_2 = [' $%s_Callback_2_(mthis, __arg_0, __arg_1)', |
| 349 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0, __arg_1]);\n\n', |
| 350 ' native "Blink_Operation_2_%s_%s";\n\n'] |
| 351 |
| 352 OPERATION_PQ = [' $%s_Callback_1_(mthis, __arg_0)', |
| 353 ' => Blink_JsNative_DomException.propertyQuery(mthis, __arg_0);
/* %s */ \n\n', |
| 354 ' native "Blink_Operation_PQ_%s";\n\n'] |
156 | 355 |
157 #(operation_name, argument_count, arguments, operation_name, arguments) | 356 #(operation_name, argument_count, arguments, operation_name, arguments) |
158 ARGUMENT_NUM = "__arg_%s" | 357 ARGUMENT_NUM = "__arg_%s" |
159 OPERATION_ARGS = ' %s_Callback_%s_(mthis, %s) => Blink_JsNative_DomException.ca
llMethod(mthis, "%s", [%s]);\n\n' | 358 OPERATION_ARGS = [' %s_Callback_%s_(mthis, %s)', |
| 359 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%
s", [%s]);\n\n', |
| 360 ' native "Blink_Operation_%s_%s"; /* %s */\n\n'] |
| 361 |
| 362 |
160 | 363 |
161 # get class property to make static call. | 364 # get class property to make static call. |
162 CLASS_STATIC = 'Blink_JsNative_DomException.getProperty(js.context, "%s")' | 365 CLASS_STATIC = 'Blink_JsNative_DomException.getProperty(js.context, "%s")' |
163 | 366 |
164 # name, classname_getproperty, name | 367 # name, classname_getproperty, name |
165 STATIC_ATTRIBUTE_GETTER = ' %s_Getter_() => Blink_JsNative_DomException.getProp
erty(%s, "%s");\n\n' | 368 STATIC_ATTRIBUTE_GETTER = [' %s_Getter_()', |
| 369 ' => Blink_JsNative_DomException.getProperty(%s /* %s
*/, "%s");\n\n', |
| 370 ' /* %s */ native "Blink_Static_getter_%s_%s"'] |
166 | 371 |
167 # name, classname_getproperty, name | 372 # name, classname_getproperty, name |
168 STATIC_OPERATION_0 = ' %s_Callback_0_() => Blink_JsNative_DomException.callMeth
od(%s, "%s", []);\n\n' | 373 STATIC_OPERATION_0 = [' %s_Callback_0_()', |
| 374 ' => Blink_JsNative_DomException.callMethod(%s /* %s */, "
%s", []);\n\n', |
| 375 ' /* %s */ native "Blink_Static_Operation_0_%s_%s'] |
169 | 376 |
170 # name, argsCount, args, classname_getproperty, name, args | 377 # name, argsCount, args, classname_getproperty, name, args |
171 STATIC_OPERATION_ARGS = ' %s_Callback_%s_(%s) => Blink_JsNative_DomException.ca
llMethod(%s, "%s", [%s]);\n\n' | 378 STATIC_OPERATION_ARGS = [' %s_Callback_%s_(%s)', |
| 379 ' => Blink_JsNative_DomException.callMethod(%s /* %s */
, "%s", [%s]);\n\n', |
| 380 ' /* %s */ native "Blink_Static_Operations_%s_%s" /* %s
*/ \n\n'] |
172 | 381 |
173 CLASS_DEFINITION_END = """} | 382 CLASS_DEFINITION_END = """} |
174 | 383 |
175 """ | 384 """ |
176 | 385 |
177 def ConstantOutputOrder(a, b): | 386 def ConstantOutputOrder(a, b): |
178 """Canonical output ordering for constants.""" | 387 """Canonical output ordering for constants.""" |
179 return cmp(a.id, b.id) | 388 return cmp(a.id, b.id) |
180 | 389 |
181 def generate_parameter_entries(param_infos): | 390 def generate_parameter_entries(param_infos): |
182 optional_default_args = 0; | 391 optional_default_args = 0; |
183 for argument in param_infos: | 392 for argument in param_infos: |
184 if argument.is_optional: | 393 if argument.is_optional: |
185 optional_default_args += 1 | 394 optional_default_args += 1 |
186 | 395 |
187 arg_count = len(param_infos) | 396 arg_count = len(param_infos) |
188 min_arg_count = arg_count - optional_default_args | 397 min_arg_count = arg_count - optional_default_args |
189 lb = min_arg_count - 2 if min_arg_count > 2 else 0 | 398 lb = min_arg_count - 2 if min_arg_count > 2 else 0 |
190 return (lb, arg_count + 1) | 399 return (lb, arg_count + 1) |
191 | 400 |
192 constructor_renames = { | 401 constructor_renames = { |
193 'RTCPeerConnection': 'webkitRTCPeerConnection', | 402 'RTCPeerConnection': 'webkitRTCPeerConnection', |
194 'SpeechRecognition': 'webkitSpeechRecognition', | 403 'SpeechRecognition': 'webkitSpeechRecognition', |
195 } | 404 } |
196 | 405 |
197 def rename_constructor(name): | 406 def rename_constructor(name): |
198 return constructor_renames[name] if name in constructor_renames else name | 407 return constructor_renames[name] if name in constructor_renames else name |
199 | 408 |
| 409 |
| 410 def _Find_Match(interface_id, member, member_prefix, candidates): |
| 411 member_name = interface_id + '.' + member |
| 412 if member_name in candidates: |
| 413 return member_name |
| 414 member_name = interface_id + '.' + member_prefix + member |
| 415 if member_name in candidates: |
| 416 return member_name |
| 417 member_name = interface_id + '.*' |
| 418 if member_name in candidates: |
| 419 return member_name |
| 420 |
| 421 def _Is_Native(interface, member): |
| 422 return _Find_Match(interface, member, '', _js_custom_members) |
| 423 |
| 424 def Select_Stub(template, is_native): |
| 425 if is_native: |
| 426 return template[0] + template[2] |
| 427 else: |
| 428 return template[0] + template[1] |
| 429 |
200 def Generate_Blink(output_dir, database, type_registry): | 430 def Generate_Blink(output_dir, database, type_registry): |
201 blink_filename = os.path.join(output_dir, '_blink_dartium.dart') | 431 blink_filename = os.path.join(output_dir, '_blink_dartium.dart') |
202 blink_file = open(blink_filename, 'w') | 432 blink_file = open(blink_filename, 'w') |
203 | 433 |
204 blink_file.write(HEADER); | 434 blink_file.write(HEADER); |
205 | 435 |
206 interfaces = database.GetInterfaces() | 436 interfaces = database.GetInterfaces() |
207 for interface in interfaces: | 437 for interface in interfaces: |
208 name = interface.id | 438 name = interface.id |
209 resolver_entry = ' if (s == "%s") return Blink%s.instance;\n' % (name, name
) | 439 resolver_entry = ' if (s == "%s") return Blink%s.instance;\n' % (name, name
) |
210 blink_file.write(resolver_entry) | 440 blink_file.write(resolver_entry) |
211 | 441 |
212 blink_file.write(END_RESOLVER); | 442 blink_file.write(END_RESOLVER); |
213 | 443 |
214 for interface in interfaces: | 444 for interface in interfaces: |
215 name = interface.id | 445 name = interface.id |
216 | 446 |
217 if interface.parents and len(interface.parents) > 0 and interface.parents[0]
.id: | 447 if interface.parents and len(interface.parents) > 0 and interface.parents[0]
.id: |
218 extends = interface.parents[0].id | 448 extends = interface.parents[0].id |
219 class_def = CLASS_DEFINITION_EXTENDS % (name, extends, name) | 449 class_def = CLASS_DEFINITION_EXTENDS % (name, extends, name) |
220 else: | 450 else: |
221 class_def = CLASS_DEFINITION % (name, name) | 451 class_def = CLASS_DEFINITION % (name, name) |
222 blink_file.write(class_def); | 452 blink_file.write(class_def); |
223 | 453 |
224 analyzed_constructors = AnalyzeConstructor(interface) | 454 analyzed_constructors = AnalyzeConstructor(interface) |
225 if analyzed_constructors: | 455 if analyzed_constructors: |
226 _Emit_Blink_Constructors(blink_file, analyzed_constructors) | 456 _Emit_Blink_Constructors(blink_file, analyzed_constructors) |
227 elif 'Constructor' in interface.ext_attrs: | 457 elif 'Constructor' in interface.ext_attrs: |
228 # Zero parameter constructor. | 458 # Zero parameter constructor. |
229 blink_file.write(CONSTRUCTOR_0 % rename_constructor(name)) | 459 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % rename_constructor(name)) |
230 | 460 |
231 _Process_Attributes(blink_file, interface, interface.attributes) | 461 _Process_Attributes(blink_file, interface, interface.attributes) |
232 _Process_Operations(blink_file, interface, interface.operations) | 462 _Process_Operations(blink_file, interface, interface.operations) |
233 | 463 |
234 secondary_parents = database.TransitiveSecondaryParents(interface, False) | 464 secondary_parents = database.TransitiveSecondaryParents(interface, False) |
235 for secondary in secondary_parents: | 465 for secondary in secondary_parents: |
236 _Process_Attributes(blink_file, secondary, secondary.attributes) | 466 _Process_Attributes(blink_file, secondary, secondary.attributes) |
237 _Process_Operations(blink_file, secondary, secondary.operations) | 467 _Process_Operations(blink_file, secondary, secondary.operations) |
238 | 468 |
239 blink_file.write(CLASS_DEFINITION_END); | 469 blink_file.write(CLASS_DEFINITION_END); |
240 | 470 |
241 blink_file.write(BLINK_UTILS) | 471 blink_file.write(BLINK_UTILS) |
242 | 472 |
243 blink_file.close() | 473 blink_file.close() |
244 | 474 |
245 def _Emit_Blink_Constructors(blink_file, analyzed_constructors): | 475 def _Emit_Blink_Constructors(blink_file, analyzed_constructors): |
246 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct
ors.param_infos) | 476 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct
ors.param_infos) |
247 name = analyzed_constructors.js_name | 477 name = analyzed_constructors.js_name |
248 if not(name): | 478 if not(name): |
249 name = analyzed_constructors.type_name | 479 name = analyzed_constructors.type_name |
250 | 480 |
251 for callback_index in range(arg_min_count, arg_max_count): | 481 for callback_index in range(arg_min_count, arg_max_count): |
252 if callback_index == 0: | 482 if callback_index == 0: |
253 blink_file.write(CONSTRUCTOR_0 % (rename_constructor(name))) | 483 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % (rename_constructor(name))) |
254 else: | 484 else: |
255 arguments = [] | 485 arguments = [] |
256 for i in range(0, callback_index): | 486 for i in range(0, callback_index): |
257 arguments.append(ARGUMENT_NUM % i) | 487 arguments.append(ARGUMENT_NUM % i) |
258 argument_list = ', '.join(arguments) | 488 argument_list = ', '.join(arguments) |
259 blink_file.write(CONSTRUCTOR_ARGS % (callback_index, argument_list, rename
_constructor(name), argument_list)) | 489 blink_file.write( |
| 490 Select_Stub(CONSTRUCTOR_ARGS, _Is_Native(name, 'constructor')) % (callba
ck_index, argument_list, rename_constructor(name), argument_list)) |
260 | 491 |
261 def _Process_Attributes(blink_file, interface, attributes): | 492 def _Process_Attributes(blink_file, interface, attributes): |
262 # Emit an interface's attributes and operations. | 493 # Emit an interface's attributes and operations. |
263 for attribute in sorted(attributes, ConstantOutputOrder): | 494 for attribute in sorted(attributes, ConstantOutputOrder): |
264 name = attribute.id | 495 name = attribute.id |
| 496 is_native = _Is_Native(interface.id, name) |
265 if attribute.is_read_only: | 497 if attribute.is_read_only: |
266 if attribute.is_static: | 498 if attribute.is_static: |
267 class_property = CLASS_STATIC % interface.id | 499 class_property = CLASS_STATIC % interface.id |
268 blink_file.write(STATIC_ATTRIBUTE_GETTER % (name, class_property, name)) | 500 blink_file.write(Select_Stub(STATIC_ATTRIBUTE_GETTER, is_native) % (name
, class_property, interface.id, name)) |
269 else: | 501 else: |
270 blink_file.write(ATTRIBUTE_GETTER % (name, name)) | 502 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, inter
face.id, name)) |
271 else: | 503 else: |
272 blink_file.write(ATTRIBUTE_GETTER % (name, name)) | 504 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, interfa
ce.id, name)) |
273 blink_file.write(ATTRIBUTE_SETTER % (name, name)) | 505 blink_file.write(Select_Stub(ATTRIBUTE_SETTER, is_native) % (name, interfa
ce.id, name)) |
274 | 506 |
275 def _Process_Operations(blink_file, interface, operations): | 507 def _Process_Operations(blink_file, interface, operations): |
276 analyzeOperations = [] | 508 analyzeOperations = [] |
277 | 509 |
278 for operation in sorted(operations, ConstantOutputOrder): | 510 for operation in sorted(operations, ConstantOutputOrder): |
279 if len(analyzeOperations) == 0: | 511 if len(analyzeOperations) == 0: |
280 analyzeOperations.append(operation) | 512 analyzeOperations.append(operation) |
281 else: | 513 else: |
282 if analyzeOperations[0].id == operation.id: | 514 if analyzeOperations[0].id == operation.id: |
283 # Handle overloads | 515 # Handle overloads |
284 analyzeOperations.append(operation) | 516 analyzeOperations.append(operation) |
285 else: | 517 else: |
286 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) | 518 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) |
287 analyzeOperations = [operation] | 519 analyzeOperations = [operation] |
288 if len(analyzeOperations) > 0: | 520 if len(analyzeOperations) > 0: |
289 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) | 521 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) |
290 | 522 |
291 def _Emit_Blink_Operation(blink_file, interface, analyzeOperations): | 523 def _Emit_Blink_Operation(blink_file, interface, analyzeOperations): |
292 analyzed = AnalyzeOperation(interface, analyzeOperations) | 524 analyzed = AnalyzeOperation(interface, analyzeOperations) |
293 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed.param_inf
os) | 525 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed.param_inf
os) |
294 name = analyzed.js_name | 526 name = analyzed.js_name |
| 527 is_native = _Is_Native(interface.id, name) |
295 | 528 |
296 operation = analyzeOperations[0] | 529 operation = analyzeOperations[0] |
297 if (name.startswith('__') and \ | 530 if (name.startswith('__') and \ |
298 ('getter' in operation.specials or \ | 531 ('getter' in operation.specials or \ |
299 'setter' in operation.specials or \ | 532 'setter' in operation.specials or \ |
300 'deleter' in operation.specials)): | 533 'deleter' in operation.specials)): |
301 if name == '__propertyQuery__': | 534 if name == '__propertyQuery__': |
302 blink_file.write(OPERATION_PQ % (name)) | 535 blink_file.write(Select_Stub(OPERATION_PQ, is_native) % (name, interface.i
d)) |
303 else: | 536 else: |
304 arg_min_count = arg_max_count | 537 arg_min_count = arg_max_count |
305 if arg_max_count == 2: | 538 if arg_max_count == 2: |
306 blink_file.write(OPERATION_1 % (name, name)) | 539 blink_file.write(Select_Stub(OPERATION_1, is_native) % (name, interface.
id, name)) |
307 elif arg_max_count == 3: | 540 elif arg_max_count == 3: |
308 blink_file.write(OPERATION_2 % (name, name)) | 541 blink_file.write(Select_Stub(OPERATION_2, is_native) % (name, interface.
id, name)) |
309 else: | 542 else: |
310 print "FATAL ERROR: _blink emitter operator %s.%s" % (interface.id, name
) | 543 print "FATAL ERROR: _blink emitter operator %s.%s" % (interface.id, name
) |
311 exit | 544 exit |
312 | 545 |
313 return | 546 return |
314 | 547 |
315 for callback_index in range(arg_min_count, arg_max_count): | 548 for callback_index in range(arg_min_count, arg_max_count): |
316 if callback_index == 0: | 549 if callback_index == 0: |
317 if operation.is_static: | 550 if operation.is_static: |
318 class_property = CLASS_STATIC % interface.id | 551 class_property = CLASS_STATIC % interface.id |
319 blink_file.write(STATIC_OPERATION_0 % (name, class_property, name)) | 552 blink_file.write(Select_Stub(STATIC_OPERATION_0, is_native) % (name, cla
ss_property, interface.id, name)) |
320 else: | 553 else: |
321 blink_file.write(OPERATION_0 % (name, name)) | 554 blink_file.write(Select_Stub(OPERATION_0, is_native) % (name, interface.
id, name)) |
322 else: | 555 else: |
323 arguments = [] | 556 arguments = [] |
324 for i in range(0, callback_index): | 557 for i in range(0, callback_index): |
325 arguments.append(ARGUMENT_NUM % i) | 558 arguments.append(ARGUMENT_NUM % i) |
326 argument_list = ', '.join(arguments) | 559 argument_list = ', '.join(arguments) |
327 if operation.is_static: | 560 if operation.is_static: |
328 class_property = CLASS_STATIC % interface.id | 561 class_property = CLASS_STATIC % interface.id |
329 blink_file.write(STATIC_OPERATION_ARGS % (name, callback_index, argument
_list, class_property, name, argument_list)) | 562 blink_file.write(Select_Stub(STATIC_OPERATION_ARGS, is_native) % (name,
callback_index, argument_list, class_property, interface.id, name, argument_list
)) |
330 else: | 563 else: |
331 blink_file.write(OPERATION_ARGS % (name, callback_index, argument_list,
name, argument_list)) | 564 blink_file.write(Select_Stub(OPERATION_ARGS, is_native) % (name, callbac
k_index, argument_list, interface.id, name, argument_list)) |
OLD | NEW |