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

Side by Side Diff: tools/dom/templates/html/dartium/html_dartium.darttemplate

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: update cached patches Created 4 years, 8 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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // DO NOT EDIT 5 // DO NOT EDIT
6 // Auto-generated dart:html library. 6 // Auto-generated dart:html library.
7 7
8 /** 8 /**
9 * HTML elements and other resources for web-based applications that need to 9 * HTML elements and other resources for web-based applications that need to
10 * interact with the browser and the DOM (Document Object Model). 10 * interact with the browser and the DOM (Document Object Model).
(...skipping 19 matching lines...) Expand all
30 * on Github. 30 * on Github.
31 */ 31 */
32 library dart.dom.html; 32 library dart.dom.html;
33 33
34 import 'dart:async'; 34 import 'dart:async';
35 import 'dart:collection'; 35 import 'dart:collection';
36 import 'dart:_internal' hide Symbol; 36 import 'dart:_internal' hide Symbol;
37 import 'dart:html_common'; 37 import 'dart:html_common';
38 import 'dart:indexed_db'; 38 import 'dart:indexed_db';
39 import 'dart:indexed_db' show indexed_dbBlinkMap; 39 import 'dart:indexed_db' show indexed_dbBlinkMap;
40 import 'dart:indexed_db' show indexed_dbBlinkFunctionMap;
41 import 'dart:isolate'; 40 import 'dart:isolate';
42 import 'dart:js' as js; 41 import 'dart:js' as js;
43 import "dart:convert"; 42 import "dart:convert";
44 import 'dart:math'; 43 import 'dart:math';
45 // TODO(vsm): Remove this when we can do the proper checking in 44 // TODO(vsm): Remove this when we can do the proper checking in
46 // native code for custom elements. 45 // native code for custom elements.
47 import 'dart:mirrors'; 46 import 'dart:mirrors';
48 import 'dart:nativewrappers'; 47 import 'dart:nativewrappers';
49 import 'dart:typed_data'; 48 import 'dart:typed_data';
50 import 'dart:web_gl' as gl; 49 import 'dart:web_gl' as gl;
51 import 'dart:web_gl' show web_glBlinkMap; 50 import 'dart:web_gl' show web_glBlinkMap;
52 import 'dart:web_gl' show web_glBlinkFunctionMap;
53 import 'dart:web_sql'; 51 import 'dart:web_sql';
54 // Not actually used, but imported since dart:html can generate these objects. 52 // Not actually used, but imported since dart:html can generate these objects.
55 import 'dart:svg' as svg; 53 import 'dart:svg' as svg;
56 import 'dart:svg' show svgBlinkMap; 54 import 'dart:svg' show svgBlinkMap;
57 import 'dart:svg' show svgBlinkFunctionMap;
58 import 'dart:svg' show Matrix; 55 import 'dart:svg' show Matrix;
59 import 'dart:svg' show SvgSvgElement; 56 import 'dart:svg' show SvgSvgElement;
60 import 'dart:web_audio' as web_audio; 57 import 'dart:web_audio' as web_audio;
61 import 'dart:web_audio' show web_audioBlinkMap; 58 import 'dart:web_audio' show web_audioBlinkMap;
62 import 'dart:web_audio' show web_audioBlinkFunctionMap;
63 import 'dart:_blink' as _blink; 59 import 'dart:_blink' as _blink;
64 import 'dart:developer'; 60 import 'dart:developer';
65 61
66 export 'dart:math' show Rectangle, Point; 62 export 'dart:math' show Rectangle, Point;
67 63
68 $!GENERATED_DART_FILES 64 $!GENERATED_DART_FILES
69 65
70 // Issue 14721, order important for WrappedEvent. 66 // Issue 14721, order important for WrappedEvent.
71 part '$AUXILIARY_DIR/AttributeMap.dart'; 67 part '$AUXILIARY_DIR/AttributeMap.dart';
72 part '$AUXILIARY_DIR/CanvasImageSource.dart'; 68 part '$AUXILIARY_DIR/CanvasImageSource.dart';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 * See also: 107 * See also:
112 * 108 *
113 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD N. 109 * * [Window](https://developer.mozilla.org/en-US/docs/Web/API/window) from MD N.
114 */ 110 */
115 Window get window { 111 Window get window {
116 if (_window != null) { 112 if (_window != null) {
117 return _window; 113 return _window;
118 } 114 }
119 $if DARTIUM 115 $if DARTIUM
120 $if JSINTEROP 116 $if JSINTEROP
121 _window = wrap_jso(js.JsNative.getProperty(js.context, 'window')); 117 _window = js.JsNative.toTypedObject(js.context);
122 $else 118 $else
123 _window = _Utils.window(); 119 _window = _Utils.window();
124 $endif 120 $endif
125 $endif 121 $endif
126 return _window; 122 return _window;
127 } 123 }
128 124
129 HtmlDocument _document; 125 HtmlDocument _document;
130 126
131 /** 127 /**
(...skipping 22 matching lines...) Expand all
154 @Deprecated("Internal Use Only") 150 @Deprecated("Internal Use Only")
155 final htmlBlinkMap = { 151 final htmlBlinkMap = {
156 '_HistoryCrossFrame': () => _HistoryCrossFrame, 152 '_HistoryCrossFrame': () => _HistoryCrossFrame,
157 '_LocationCrossFrame': () => _LocationCrossFrame, 153 '_LocationCrossFrame': () => _LocationCrossFrame,
158 '_DOMWindowCrossFrame': () => _DOMWindowCrossFrame, 154 '_DOMWindowCrossFrame': () => _DOMWindowCrossFrame,
159 // FIXME: Move these to better locations. 155 // FIXME: Move these to better locations.
160 'DateTime': () => DateTime, 156 'DateTime': () => DateTime,
161 'JsObject': () => js.JsObject, 157 'JsObject': () => js.JsObject,
162 'JsFunction': () => js.JsFunction, 158 'JsFunction': () => js.JsFunction,
163 'JsArray': () => js.JsArray, 159 'JsArray': () => js.JsArray,
160 // We have to call .instanceRuntimeType as these classes have a private
161 // implementation class defined dynamically at runtime via a patch file.
162 'JSObject': () => js.JSObject.instanceRuntimeType,
163 'JSFunction': () => js.JSFunction.instanceRuntimeType,
164 'JSArray': () => js.JSArray.instanceRuntimeType,
164 $!TYPE_MAP 165 $!TYPE_MAP
165 }; 166 };
166 167
167 // TODO(leafp): We may want to move this elsewhere if html becomes 168 // TODO(leafp): We may want to move this elsewhere if html becomes
168 // a package to avoid dartium depending on pkg:html. 169 // a package to avoid dartium depending on pkg:html.
170 @Deprecated("Internal Use Only")
171 getHtmlCreateType(String key) => _getType(key);
172
169 Type _getType(String key) { 173 Type _getType(String key) {
170 var result; 174 var result;
171 175
172 // TODO(vsm): Add Cross Frame and JS types here as well. 176 // TODO(vsm): Add Cross Frame and JS types here as well.
173 177
174 // Check the html library. 178 // Check the html library.
175 result = _getHtmlType(key); 179 result = _getHtmlType(key);
176 if (result != null) { 180 if (result != null) {
177 return result; 181 return result;
178 } 182 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return null; 249 return null;
246 } 250 }
247 251
248 Type _getSvgType(String key) { 252 Type _getSvgType(String key) {
249 if (svgBlinkMap.containsKey(key)) { 253 if (svgBlinkMap.containsKey(key)) {
250 return svgBlinkMap[key](); 254 return svgBlinkMap[key]();
251 } 255 }
252 return null; 256 return null;
253 } 257 }
254 258
255 $if JSINTEROP 259 // TODO(jacobr): it would be nice to place this in a consistent place for dart2j s and dartium.
256 // FIXME: Can we make this private? 260 _convertNativeToDart_XHR_Response(o) {
257 @Deprecated("Internal Use Only") 261 if (o is Document) {
258 final htmlBlinkFunctionMap = { 262 return o;
259 $!TYPE_FUNCTION_MAP
260 };
261
262 // TODO(terry): We may want to move this elsewhere if html becomes
263 // a package to avoid dartium depending on pkg:html.
264 @Deprecated("Internal Use Only")
265 getHtmlCreateFunction(String key) {
266 var result;
267
268 // TODO(vsm): Add Cross Frame and JS types here as well.
269
270 // Check the html library.
271 result = _getHtmlFunction(key);
272 if (result != null) {
273 return result;
274 } 263 }
275 264 return convertNativeToDart_SerializedScriptValue(o);
276 // Check the web gl library.
277 result = _getWebGlFunction(key);
278 if (result != null) {
279 return result;
280 }
281
282 // Check the indexed db library.
283 result = _getIndexDbFunction(key);
284 if (result != null) {
285 return result;
286 }
287
288 // Check the web audio library.
289 result = _getWebAudioFunction(key);
290 if (result != null) {
291 return result;
292 }
293
294 // Check the web sql library.
295 result = _getWebSqlFunction(key);
296 if (result != null) {
297 return result;
298 }
299
300 // Check the svg library.
301 result = _getSvgFunction(key);
302 if (result != null) {
303 return result;
304 }
305
306 return null;
307 } 265 }
308 266
309 Function _getHtmlFunction(String key) { 267 $if JSINTEROP
310 if (htmlBlinkFunctionMap.containsKey(key)) {
311 return htmlBlinkFunctionMap[key]();
312 }
313 return null;
314 }
315
316 Function _getWebGlFunction(String key) {
317 if (web_glBlinkFunctionMap.containsKey(key)) {
318 return web_glBlinkFunctionMap[key]();
319 }
320 return null;
321 }
322
323 Function _getIndexDbFunction(String key) {
324 if (indexed_dbBlinkFunctionMap.containsKey(key)) {
325 return indexed_dbBlinkFunctionMap[key]();
326 }
327 return null;
328 }
329
330 Function _getWebAudioFunction(String key) {
331 if (web_audioBlinkFunctionMap.containsKey(key)) {
332 return web_audioBlinkFunctionMap[key]();
333 }
334 return null;
335 }
336
337 Function _getWebSqlFunction(String key) {
338 if (web_sqlBlinkFunctionMap.containsKey(key)) {
339 return web_sqlBlinkFunctionMap[key]();
340 }
341 return null;
342 }
343
344 Function _getSvgFunction(String key) {
345 if (svgBlinkFunctionMap.containsKey(key)) {
346 return svgBlinkFunctionMap[key]();
347 }
348 return null;
349 }
350
351 268
352 /****************************************************************************** 269 /******************************************************************************
353 ********** ********** 270 ********** **********
354 ********** JS Interop Support ********** 271 ********** JS Interop Support **********
355 ********** ********** 272 ********** **********
356 ******************************************************************************/ 273 ******************************************************************************/
357 274
358 String _getCustomElementExtends(object) { 275 String _getCustomElementExtends(object) {
359 var entry = getCustomElementEntry(object); 276 var entry = getCustomElementEntry(object);
360 if (entry != null) { 277 if (entry != null) {
361 return entry['extends']; 278 return entry['extends'];
362 } 279 }
363 return null; 280 return null;
364 } 281 }
365 282
366 // Return the tag name or is attribute of the custom element or data binding. 283 // Return the tag name or is attribute of the custom element or data binding.
367 String _getCustomElementName(element) { 284 String _getCustomElementName(element) {
368 var jsObject; 285 var jsObject;
369 var tag = ""; 286 var tag = "";
370 var runtimeType = element.runtimeType; 287 var runtimeType = element.runtimeType;
371 if (runtimeType == HtmlElement) { 288 if (runtimeType == TemplateElement) {
372 tag = element.localName;
373 } else if (runtimeType == TemplateElement) {
374 // Data binding with a Dart class. 289 // Data binding with a Dart class.
375 tag = element.attributes['is']; 290 tag = element.attributes['is'];
376 } else if (runtimeType == js.JsObject) { 291 } else if (element is HtmlElement) {
377 // It's a Polymer core element (written in JS). 292 tag = element.attributes['is'];
378 // Make sure it's an element anything else we can ignore. 293 if (tag == null) {
379 if (element.hasProperty('nodeType') && element['nodeType'] == 1) { 294 // It's a custom element we want the local name.
380 if (js.JsNative.callMethod(element, 'hasAttribute', ['is'])) { 295 tag = element.localName;
381 // It's data binding use the is attribute.
382 tag = js.JsNative.callMethod(element, 'getAttribute', ['is']);
383 } else {
384 // It's a custom element we want the local name.
385 tag = element['localName'];
386 }
387 } 296 }
388 } else { 297 } else {
389 throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, e xpected HtmlElement/HtmlTemplate/JsObject.'); 298 throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, e xpected HtmlElement/HtmlTemplate/JsObject.');
390 } 299 }
391 300
392 return tag; 301 return tag;
393 } 302 }
394 303
395 /// An abstract class for all DOM objects we wrap in dart:html and related 304 /// An abstract class for all DOM objects we wrap in dart:html and related
396 /// libraries. 305 /// libraries.
397 @Deprecated("Internal Use Only") 306 @Deprecated("Internal Use Only")
398 class DartHtmlDomObject extends js.JSObject { 307 class DartHtmlDomObject extends js.JSObject {
399 DartHtmlDomObject() : super.internal(); 308 DartHtmlDomObject() : super.internal();
400 } 309 }
401 310
402 @Deprecated("Internal Use Only") 311 @Deprecated("Internal Use Only")
403 class DebugAssertException implements Exception { 312 class DebugAssertException implements Exception {
404 String message; 313 String message;
405 DebugAssertException(this.message); 314 DebugAssertException(this.message);
406 } 315 }
407 316
408 @Deprecated("Internal Use Only") 317 @Deprecated("Internal Use Only")
409 debug_or_assert(message, expression) { 318 debug_or_assert(message, expression) {
410 if (!expression) { 319 if (!expression) {
411 throw new DebugAssertException("$message"); 320 throw new DebugAssertException("$message");
412 } 321 }
413 } 322 }
414 323
324 // TODO(jacobr): we shouldn't be generating this call in the dart:html
325 // bindings but we are.
326 _convertDartToNative_EventTarget(target) => target;
327
415 @Deprecated("Internal Use Only") 328 @Deprecated("Internal Use Only")
416 Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) { 329 Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
417 var result = new Map(); 330 var result = new Map();
418 var keys = js.JsNative.callMethod(js.JsNative.getProperty(js.context, 'Object' ), 'keys', [jsObject]); 331 var keys = js.JsNative.callMethod(js.JsNative.getProperty(js.context, 'Object' ), 'keys', [jsObject]);
419 for (var key in keys) { 332 for (var key in keys) {
420 result[key] = wrap_jso(js.JsNative.getProperty(jsObject, key)); 333 result[key] = js.JsNative.getProperty(jsObject, key);
421 } 334 }
422 return result; 335 return result;
423 } 336 }
424 337
425 /** 338 /**
426 * Upgrade the JS HTMLElement to the Dart class. Used by Dart's Polymer. 339 * Upgrade the JS HTMLElement to the Dart class. Used by Dart's Polymer.
427 */ 340 */
428 _createCustomUpgrader(Type customElementClass, $this) { 341 _createCustomUpgrader(Type customElementClass, $this) {
429 var dartClass; 342 return _blink.Blink_Utils.setInstanceInterceptor($this, customElementClass, cu stomElement: true);
430 try {
431 dartClass = _blink.Blink_Utils.constructElement(customElementClass, $this);
432 } catch (e) {
433 // Did the dartClass get allocated but the created failed? Otherwise, other
434 // components inside of this failed somewhere (could be JS custom element).
435 if (dartClass != null) {
436 // Yes, mark as didn't upgrade.
437 dartClass._badUpgrade();
438 }
439 throw e;
440 } finally {
441 // Need to remember the Dart class that was created for this custom so
442 // return it and setup the blink_jsObject to the $this that we'll be working
443 // with as we talk to blink.
444 js.setDartHtmlWrapperFor($this, dartClass);
445 }
446
447 return dartClass;
448 } 343 }
449 344
450 $else 345 $else
451 class DartHtmlDomObject extends NativeFieldWrapperClass2 {} 346 class DartHtmlDomObject extends NativeFieldWrapperClass2 {}
452 347
453 _createCustomUpgrader(Type customElementClass, $this) => $this; 348 _createCustomUpgrader(Type customElementClass, $this) => $this;
454 349
455 $endif 350 $endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698