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

Side by Side Diff: tools/dom/src/dartium_CustomElementSupport.dart

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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart.dom.html; 5 part of dart.dom.html;
6 6
7 /// Dartium ElementUpgrader implementation. 7 /// Dartium ElementUpgrader implementation.
8 class _VMElementUpgrader implements ElementUpgrader { 8 class _VMElementUpgrader implements ElementUpgrader {
9 final Type _type; 9 final Type _type;
10 final Type _nativeType; 10 final Type _nativeType;
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 } else { 23 } else {
24 if (document.createElement(extendsTag).runtimeType != _nativeType) { 24 if (document.createElement(extendsTag).runtimeType != _nativeType) {
25 throw new UnsupportedError( 25 throw new UnsupportedError(
26 'extendsTag does not match base native class'); 26 'extendsTag does not match base native class');
27 } 27 }
28 } 28 }
29 } 29 }
30 30
31 Element upgrade(element) { 31 Element upgrade(element) {
32 var jsObject;
33 var tag; 32 var tag;
34 var isNativeElementExtension = false; 33 var isNativeElementExtension = false;
35 34
36 try { 35 try {
37 tag = _getCustomElementName(element); 36 tag = _getCustomElementName(element);
38 } catch (e) { 37 } catch (e) {
39 isNativeElementExtension = element.localName == _extendsTag; 38 isNativeElementExtension = element.localName == _extendsTag;
40 } 39 }
41 40
42 if (element.runtimeType == HtmlElement || element.runtimeType == TemplateEle ment) { 41 if (element.runtimeType == HtmlElement || element.runtimeType == TemplateEle ment) {
43 if (tag != _extendsTag) { 42 if (tag != _extendsTag) {
44 throw new UnsupportedError('$tag is not registered.'); 43 throw new UnsupportedError('$tag is not registered.');
45 } 44 }
46 jsObject = unwrap_jso(element);
47 } else if (element.runtimeType == js.JsObject) { 45 } else if (element.runtimeType == js.JsObject) {
48 // It's a Polymer core element (written in JS). 46 // It's a Polymer core element (written in JS).
49 jsObject = element;
50 } else if (isNativeElementExtension) { 47 } else if (isNativeElementExtension) {
51 // Extending a native element. 48 // Extending a native element.
52 jsObject = element.blink_jsObject; 49 // TODO(jacobr): make sure we haven't busted this case.
53 50
54 // Element to extend is the real tag. 51 // Element to extend is the real tag.
55 tag = element.localName; 52 tag = element.localName;
56 } else if (tag != null && element.localName != tag) { 53 } else if (tag != null && element.localName != tag) {
57 throw new UnsupportedError('Element is incorrect type. Got ${element.runti meType}, expected native Html or Svg element to extend.'); 54 throw new UnsupportedError('Element is incorrect type. Got ${element.runti meType}, expected native Html or Svg element to extend.');
58 } else if (tag == null) { 55 } else if (tag == null) {
59 throw new UnsupportedError('Element is incorrect type. Got ${element.runti meType}, expected HtmlElement/JsObject.'); 56 throw new UnsupportedError('Element is incorrect type. Got ${element.runti meType}, expected HtmlElement/JsObject.');
60 } 57 }
61 58
62 // Remember Dart class to tagName for any upgrading done in wrap_jso. 59 // Remember Dart class to tagName for any upgrading
63 addCustomElementType(tag, _type, _extendsTag); 60 addCustomElementType(tag, _type, _extendsTag);
64 61
65 return _createCustomUpgrader(_type, jsObject); 62 // TODO(jacobr): XXX validate that this method still works.
63 return _createCustomUpgrader(_type, element);
66 } 64 }
67 } 65 }
68 66
69 /// Validates that the custom type is properly formed- 67 /// Validates that the custom type is properly formed-
70 /// 68 ///
71 /// * Is a user-defined class. 69 /// * Is a user-defined class.
72 /// * Has a created constructor with zero args. 70 /// * Has a created constructor with zero args.
73 /// * Derives from an Element subclass. 71 /// * Derives from an Element subclass.
74 /// 72 ///
75 /// Then returns the native base class. 73 /// Then returns the native base class.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return nativeClass; 114 return nativeClass;
117 } 115 }
118 116
119 117
120 bool _isBuiltinType(ClassMirror cls) { 118 bool _isBuiltinType(ClassMirror cls) {
121 // TODO(vsm): Find a less hackish way to do this. 119 // TODO(vsm): Find a less hackish way to do this.
122 LibraryMirror lib = cls.owner; 120 LibraryMirror lib = cls.owner;
123 String libName = lib.uri.toString(); 121 String libName = lib.uri.toString();
124 return libName.startsWith('dart:'); 122 return libName.startsWith('dart:');
125 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698