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

Side by Side Diff: tools/dom/scripts/generate_blink_file.py

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

Powered by Google App Engine
This is Rietveld 408576698