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

Side by Side Diff: tools/dom/src/native_DOMImplementation.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: 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 part of html; 5 part of html;
6 6
7 class _Property { 7 class _Property {
8 _Property(this.name) : 8 _Property(this.name) :
9 _hasValue = false, 9 _hasValue = false,
10 writable = false, 10 writable = false,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 static DateTime doubleToDateTime(double dateTime) { 117 static DateTime doubleToDateTime(double dateTime) {
118 try { 118 try {
119 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt()); 119 return new DateTime.fromMillisecondsSinceEpoch(dateTime.toInt());
120 } catch(_) { 120 } catch(_) {
121 // TODO(antonnm): treat exceptions properly in bindings and 121 // TODO(antonnm): treat exceptions properly in bindings and
122 // find out how to treat NaNs. 122 // find out how to treat NaNs.
123 return null; 123 return null;
124 } 124 }
125 } 125 }
126 126
127 static maybeUnwrapJso(obj) => unwrap_jso(obj);
128
129 static List convertToList(List list) { 127 static List convertToList(List list) {
130 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it. 128 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is fine w/ it.
131 final length = list.length; 129 final length = list.length;
132 List result = new List(length); 130 List result = new List(length);
133 result.setRange(0, length, list); 131 result.setRange(0, length, list);
134 return result; 132 return result;
135 } 133 }
136 134
137 static List convertMapToList(Map map) { 135 static List convertMapToList(Map map) {
138 List result = []; 136 List result = [];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 180 }
183 181
184 static Element getAndValidateNativeType(Type type, String tagName) { 182 static Element getAndValidateNativeType(Type type, String tagName) {
185 var element = new Element.tag(tagName); 183 var element = new Element.tag(tagName);
186 if (!isTypeSubclassOf(type, element.runtimeType)) { 184 if (!isTypeSubclassOf(type, element.runtimeType)) {
187 return null; 185 return null;
188 } 186 }
189 return element; 187 return element;
190 } 188 }
191 189
192 static window() => wrap_jso(js.context['window']);
193
194 static forwardingPrint(String message) => _blink.Blink_Utils.forwardingPrint(m essage); 190 static forwardingPrint(String message) => _blink.Blink_Utils.forwardingPrint(m essage);
195 static void spawnDomHelper(Function f, int replyTo) => 191 static void spawnDomHelper(Function f, int replyTo) =>
196 _blink.Blink_Utils.spawnDomHelper(f, replyTo); 192 _blink.Blink_Utils.spawnDomHelper(f, replyTo);
197 193
198 // TODO(vsm): Make this API compatible with spawnUri. It should also 194 // TODO(vsm): Make this API compatible with spawnUri. It should also
199 // return a Future<Isolate>. 195 // return a Future<Isolate>.
200 static spawnDomUri(String uri) => wrap_jso(_blink.Blink_Utils.spawnDomUri(uri) ); 196 // TODO(jacobr): IS THIS RIGHT? I worry we have broken conversion from Promise to Future.
197 static spawnDomUri(String uri) => _blink.Blink_Utils.spawnDomUri(uri);
201 198
202 // The following methods were added for debugger integration to make working 199 // The following methods were added for debugger integration to make working
203 // with the Dart C mirrors API simpler. 200 // with the Dart C mirrors API simpler.
204 // TODO(jacobr): consider moving them to a separate library. 201 // TODO(jacobr): consider moving them to a separate library.
205 // If Dart supported dynamic code injection, we would only inject this code 202 // If Dart supported dynamic code injection, we would only inject this code
206 // when the debugger is invoked. 203 // when the debugger is invoked.
207 204
208 /** 205 /**
209 * Strips the private secret prefix from member names of the form 206 * Strips the private secret prefix from member names of the form
210 * someName@hash. 207 * someName@hash.
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 } 764 }
768 765
769 /** 766 /**
770 * Helper to wrap the inspect method on InjectedScriptHost to provide the 767 * Helper to wrap the inspect method on InjectedScriptHost to provide the
771 * inspect method required for the 768 * inspect method required for the
772 */ 769 */
773 static List consoleApi(host) { 770 static List consoleApi(host) {
774 return [ 771 return [
775 "inspect", 772 "inspect",
776 (o) { 773 (o) {
777 host.callMethod("_inspect", [unwrap_jso(o)]); 774 js.JsNative.callMethod(host, "_inspect", [o]);
778 return o; 775 return o;
779 }, 776 },
780 "dir", 777 "dir",
781 window().console.dir, 778 window.console.dir,
782 "dirxml", 779 "dirxml",
783 window().console.dirxml 780 window.console.dirxml
784 // FIXME: add copy method. 781 // FIXME: add copy method.
785 ]; 782 ];
786 } 783 }
787 784
788 static List getMapKeyList(Map map) => map.keys.toList(); 785 static List getMapKeyList(Map map) => map.keys.toList();
789 786
790 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; 787 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError;
791 788
792 static void register(Document document, String tag, Type type, 789 static void register(Document document, String tag, Type type,
793 String extendsTagName) { 790 String extendsTagName) {
794 var nativeClass = _validateCustomType(type); 791 var nativeClass = _validateCustomType(type);
795 792
796 if (extendsTagName == null) { 793 if (extendsTagName == null) {
797 if (nativeClass.reflectedType != HtmlElement) { 794 if (nativeClass.reflectedType != HtmlElement) {
798 throw new UnsupportedError('Class must provide extendsTag if base ' 795 throw new UnsupportedError('Class must provide extendsTag if base '
799 'native class is not HTMLElement'); 796 'native class is not HTMLElement');
800 } 797 }
801 } 798 }
802 799
803 _register(document, tag, type, extendsTagName); 800 _register(document, tag, type, extendsTagName);
804 } 801 }
805 802
806 static void _register(Document document, String tag, Type customType, 803 static void _register(Document document, String tag, Type customType,
807 String extendsTagName) => _blink.Blink_Utils.register(unwrap_jso(document), tag, customType, extendsTagName); 804 String extendsTagName) => _blink.Blink_Utils.register(document, tag, customT ype, extendsTagName);
808 805
809 static Element createElement(Document document, String tagName) => 806 static Element createElement(Document document, String tagName) =>
810 wrap_jso(_blink.Blink_Utils.createElement(unwrap_jso(document), tagName)); 807 _blink.Blink_Utils.createElement(document, tagName);
811
812 static Element changeElementWrapper(HtmlElement element, Type type) =>
813 wrap_jso(_blink.Blink_Utils.changeElementWrapper(unwrap_jso(element), type ));
814 } 808 }
815 809
810 // TODO(jacobr): this seems busted. I believe we are actually
811 // giving users real windows for opener, parent, top, etc.
812 // Or worse, we are probaly returning a raw JSObject.
816 class _DOMWindowCrossFrame extends DartHtmlDomObject implements 813 class _DOMWindowCrossFrame extends DartHtmlDomObject implements
817 WindowBase { 814 WindowBase {
818 /** Needed because KeyboardEvent is implements.
819 * TODO(terry): Consider making blink_jsObject private (add underscore) for
820 * all blink_jsObject. Then needed private wrap/unwrap_jso
821 * functions that delegate to a public wrap/unwrap_jso.
822 */
823 js.JsObject blink_jsObject;
824 815
825 _DOMWindowCrossFrame.internal(); 816 _DOMWindowCrossFrame.internal();
817
818 static _createSafe(win) => _blink.Blink_Utils.setInstanceInterceptor(win, _DOM WindowCrossFrame);
826 819
827 // Fields. 820 // Fields.
828 HistoryBase get history => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_histo ry(unwrap_jso(this))); 821 HistoryBase get history => _blink.Blink_DOMWindowCrossFrame.get_history(this);
829 LocationBase get location => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_loc ation(unwrap_jso(this))); 822 LocationBase get location => _blink.Blink_DOMWindowCrossFrame.get_location(thi s);
830 bool get closed => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_closed(unwrap _jso(this))); 823 bool get closed => _blink.Blink_DOMWindowCrossFrame.get_closed(this);
831 WindowBase get opener => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_opener( unwrap_jso(this))); 824 WindowBase get opener => _blink.Blink_DOMWindowCrossFrame.get_opener(this);
832 WindowBase get parent => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_parent( unwrap_jso(this))); 825 WindowBase get parent => _blink.Blink_DOMWindowCrossFrame.get_parent(this);
833 WindowBase get top => wrap_jso(_blink.Blink_DOMWindowCrossFrame.get_top(unwrap _jso(this))); 826 WindowBase get top => _blink.Blink_DOMWindowCrossFrame.get_top(this);
834 827
835 // Methods. 828 // Methods.
836 void close() => _blink.Blink_DOMWindowCrossFrame.close(unwrap_jso(this)); 829 void close() => _blink.Blink_DOMWindowCrossFrame.close(this);
837 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List messagePorts]) => 830 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List messagePorts]) =>
838 _blink.Blink_DOMWindowCrossFrame.postMessage(unwrap_jso(this), 831 _blink.Blink_DOMWindowCrossFrame.postMessage(this,
839 convertDartToNative_SerializedScriptValue(message), targetOrigin, messa gePorts); 832 convertDartToNative_SerializedScriptValue(message), targetOrigin, messa gePorts);
840 833
841 // Implementation support. 834 // Implementation support.
842 String get typeName => "Window"; 835 String get typeName => "Window";
843 836
844 // TODO(efortuna): Remove this method. dartbug.com/16814 837 // TODO(efortuna): Remove this method. dartbug.com/16814
845 Events get on => throw new UnsupportedError( 838 Events get on => throw new UnsupportedError(
846 'You can only attach EventListeners to your own window.'); 839 'You can only attach EventListeners to your own window.');
847 // TODO(efortuna): Remove this method. dartbug.com/16814 840 // TODO(efortuna): Remove this method. dartbug.com/16814
848 void _addEventListener([String type, EventListener listener, bool useCapture]) 841 void _addEventListener([String type, EventListener listener, bool useCapture])
(...skipping 13 matching lines...) Expand all
862 // TODO(efortuna): Remove this method. dartbug.com/16814 855 // TODO(efortuna): Remove this method. dartbug.com/16814
863 void removeEventListener(String type, EventListener listener, 856 void removeEventListener(String type, EventListener listener,
864 [bool useCapture]) => throw new UnsupportedError( 857 [bool useCapture]) => throw new UnsupportedError(
865 'You can only attach EventListeners to your own window.'); 858 'You can only attach EventListeners to your own window.');
866 } 859 }
867 860
868 class _HistoryCrossFrame extends DartHtmlDomObject implements HistoryBase { 861 class _HistoryCrossFrame extends DartHtmlDomObject implements HistoryBase {
869 _HistoryCrossFrame.internal(); 862 _HistoryCrossFrame.internal();
870 863
871 // Methods. 864 // Methods.
872 void back() => _blink.Blink_HistoryCrossFrame.back(unwrap_jso(this)); 865 void back() => _blink.Blink_HistoryCrossFrame.back(this);
873 void forward() => _blink.Blink_HistoryCrossFrame.forward(unwrap_jso(this)); 866 void forward() => _blink.Blink_HistoryCrossFrame.forward(this);
874 void go(int distance) => _blink.Blink_HistoryCrossFrame.go(unwrap_jso(this), d istance); 867 void go(int distance) => _blink.Blink_HistoryCrossFrame.go(this, distance);
875 868
876 // Implementation support. 869 // Implementation support.
877 String get typeName => "History"; 870 String get typeName => "History";
878 } 871 }
879 872
880 class _LocationCrossFrame extends DartHtmlDomObject implements LocationBase { 873 class _LocationCrossFrame extends DartHtmlDomObject implements LocationBase {
881 _LocationCrossFrame.internal(); 874 _LocationCrossFrame.internal();
882 875
883 // Fields. 876 // Fields.
884 set href(String h) => _blink.Blink_LocationCrossFrame.set_href(unwrap_jso(this ), h); 877 set href(String h) => _blink.Blink_LocationCrossFrame.set_href(this, h);
885 878
886 // Implementation support. 879 // Implementation support.
887 String get typeName => "Location"; 880 String get typeName => "Location";
888 } 881 }
889 882
890 // TODO(vsm): Remove DOM isolate code once we have Dartium isolates 883 // TODO(vsm): Remove DOM isolate code once we have Dartium isolates
891 // as workers. This is only used to support 884 // as workers. This is only used to support
892 // printing and timers in background isolates. As workers they should 885 // printing and timers in background isolates. As workers they should
893 // be able to just do those things natively. 886 // be able to just do those things natively.
894 887
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 _scheduleImmediateHelper._schedule(callback); 1085 _scheduleImmediateHelper._schedule(callback);
1093 }; 1086 };
1094 1087
1095 get _pureIsolateScheduleImmediateClosure => ((void callback()) => 1088 get _pureIsolateScheduleImmediateClosure => ((void callback()) =>
1096 throw new UnimplementedError("scheduleMicrotask in background isolates " 1089 throw new UnimplementedError("scheduleMicrotask in background isolates "
1097 "are not supported in the browser")); 1090 "are not supported in the browser"));
1098 1091
1099 // Class for unsupported native browser 'DOM' objects. 1092 // Class for unsupported native browser 'DOM' objects.
1100 class _UnsupportedBrowserObject extends DartHtmlDomObject { 1093 class _UnsupportedBrowserObject extends DartHtmlDomObject {
1101 } 1094 }
OLDNEW
« no previous file with comments | « tools/dom/src/dartium_WrappedEvent.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698