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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/dartium/html_dartium.darttemplate
diff --git a/tools/dom/templates/html/dartium/html_dartium.darttemplate b/tools/dom/templates/html/dartium/html_dartium.darttemplate
index 66a18e0cf9d62595ba2858b43c6d61f05f0c4c7d..c92c27e268ce93dc26a95e66d73c3324cd7cf9bf 100644
--- a/tools/dom/templates/html/dartium/html_dartium.darttemplate
+++ b/tools/dom/templates/html/dartium/html_dartium.darttemplate
@@ -37,7 +37,6 @@ import 'dart:_internal' hide Symbol;
import 'dart:html_common';
import 'dart:indexed_db';
import 'dart:indexed_db' show indexed_dbBlinkMap;
-import 'dart:indexed_db' show indexed_dbBlinkFunctionMap;
import 'dart:isolate';
import 'dart:js' as js;
import "dart:convert";
@@ -49,17 +48,14 @@ import 'dart:nativewrappers';
import 'dart:typed_data';
import 'dart:web_gl' as gl;
import 'dart:web_gl' show web_glBlinkMap;
-import 'dart:web_gl' show web_glBlinkFunctionMap;
import 'dart:web_sql';
// Not actually used, but imported since dart:html can generate these objects.
import 'dart:svg' as svg;
import 'dart:svg' show svgBlinkMap;
-import 'dart:svg' show svgBlinkFunctionMap;
import 'dart:svg' show Matrix;
import 'dart:svg' show SvgSvgElement;
import 'dart:web_audio' as web_audio;
import 'dart:web_audio' show web_audioBlinkMap;
-import 'dart:web_audio' show web_audioBlinkFunctionMap;
import 'dart:_blink' as _blink;
import 'dart:developer';
@@ -118,7 +114,7 @@ Window get window {
}
$if DARTIUM
$if JSINTEROP
- _window = wrap_jso(js.JsNative.getProperty(js.context, 'window'));
+ _window = js.JsNative.toTypedObject(js.context);
$else
_window = _Utils.window();
$endif
@@ -161,11 +157,19 @@ final htmlBlinkMap = {
'JsObject': () => js.JsObject,
'JsFunction': () => js.JsFunction,
'JsArray': () => js.JsArray,
+ // We have to call .instanceRuntimeType as these classes have a private
+ // implementation class defined dynamically at runtime via a patch file.
+ 'JSObject': () => js.JSObject.instanceRuntimeType,
+ 'JSFunction': () => js.JSFunction.instanceRuntimeType,
+ 'JSArray': () => js.JSArray.instanceRuntimeType,
$!TYPE_MAP
};
// TODO(leafp): We may want to move this elsewhere if html becomes
// a package to avoid dartium depending on pkg:html.
+@Deprecated("Internal Use Only")
+getHtmlCreateType(String key) => _getType(key);
+
Type _getType(String key) {
var result;
@@ -252,102 +256,15 @@ Type _getSvgType(String key) {
return null;
}
-$if JSINTEROP
-// FIXME: Can we make this private?
-@Deprecated("Internal Use Only")
-final htmlBlinkFunctionMap = {
-$!TYPE_FUNCTION_MAP
-};
-
-// TODO(terry): We may want to move this elsewhere if html becomes
-// a package to avoid dartium depending on pkg:html.
-@Deprecated("Internal Use Only")
-getHtmlCreateFunction(String key) {
- var result;
-
- // TODO(vsm): Add Cross Frame and JS types here as well.
-
- // Check the html library.
- result = _getHtmlFunction(key);
- if (result != null) {
- return result;
+// TODO(jacobr): it would be nice to place this in a consistent place for dart2js and dartium.
+_convertNativeToDart_XHR_Response(o) {
+ if (o is Document) {
+ return o;
}
-
- // Check the web gl library.
- result = _getWebGlFunction(key);
- if (result != null) {
- return result;
- }
-
- // Check the indexed db library.
- result = _getIndexDbFunction(key);
- if (result != null) {
- return result;
- }
-
- // Check the web audio library.
- result = _getWebAudioFunction(key);
- if (result != null) {
- return result;
- }
-
- // Check the web sql library.
- result = _getWebSqlFunction(key);
- if (result != null) {
- return result;
- }
-
- // Check the svg library.
- result = _getSvgFunction(key);
- if (result != null) {
- return result;
- }
-
- return null;
-}
-
-Function _getHtmlFunction(String key) {
- if (htmlBlinkFunctionMap.containsKey(key)) {
- return htmlBlinkFunctionMap[key]();
- }
- return null;
-}
-
-Function _getWebGlFunction(String key) {
- if (web_glBlinkFunctionMap.containsKey(key)) {
- return web_glBlinkFunctionMap[key]();
- }
- return null;
-}
-
-Function _getIndexDbFunction(String key) {
- if (indexed_dbBlinkFunctionMap.containsKey(key)) {
- return indexed_dbBlinkFunctionMap[key]();
- }
- return null;
-}
-
-Function _getWebAudioFunction(String key) {
- if (web_audioBlinkFunctionMap.containsKey(key)) {
- return web_audioBlinkFunctionMap[key]();
- }
- return null;
-}
-
-Function _getWebSqlFunction(String key) {
- if (web_sqlBlinkFunctionMap.containsKey(key)) {
- return web_sqlBlinkFunctionMap[key]();
- }
- return null;
-}
-
-Function _getSvgFunction(String key) {
- if (svgBlinkFunctionMap.containsKey(key)) {
- return svgBlinkFunctionMap[key]();
- }
- return null;
+ return convertNativeToDart_SerializedScriptValue(o);
}
+$if JSINTEROP
/******************************************************************************
********** **********
@@ -368,22 +285,14 @@ String _getCustomElementName(element) {
var jsObject;
var tag = "";
var runtimeType = element.runtimeType;
- if (runtimeType == HtmlElement) {
- tag = element.localName;
- } else if (runtimeType == TemplateElement) {
+ if (runtimeType == TemplateElement) {
// Data binding with a Dart class.
tag = element.attributes['is'];
- } else if (runtimeType == js.JsObject) {
- // It's a Polymer core element (written in JS).
- // Make sure it's an element anything else we can ignore.
- if (element.hasProperty('nodeType') && element['nodeType'] == 1) {
- if (js.JsNative.callMethod(element, 'hasAttribute', ['is'])) {
- // It's data binding use the is attribute.
- tag = js.JsNative.callMethod(element, 'getAttribute', ['is']);
- } else {
- // It's a custom element we want the local name.
- tag = element['localName'];
- }
+ } else if (element is HtmlElement) {
+ tag = element.attributes['is'];
+ if (tag == null) {
+ // It's a custom element we want the local name.
+ tag = element.localName;
}
} else {
throw new UnsupportedError('Element is incorrect type. Got ${runtimeType}, expected HtmlElement/HtmlTemplate/JsObject.');
@@ -412,12 +321,16 @@ debug_or_assert(message, expression) {
}
}
+// TODO(jacobr): we shouldn't be generating this call in the dart:html
+// bindings but we are.
+_convertDartToNative_EventTarget(target) => target;
+
@Deprecated("Internal Use Only")
Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
var result = new Map();
var keys = js.JsNative.callMethod(js.JsNative.getProperty(js.context, 'Object'), 'keys', [jsObject]);
for (var key in keys) {
- result[key] = wrap_jso(js.JsNative.getProperty(jsObject, key));
+ result[key] = js.JsNative.getProperty(jsObject, key);
}
return result;
}
@@ -426,25 +339,7 @@ Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
* Upgrade the JS HTMLElement to the Dart class. Used by Dart's Polymer.
*/
_createCustomUpgrader(Type customElementClass, $this) {
- var dartClass;
- try {
- dartClass = _blink.Blink_Utils.constructElement(customElementClass, $this);
- } catch (e) {
- // Did the dartClass get allocated but the created failed? Otherwise, other
- // components inside of this failed somewhere (could be JS custom element).
- if (dartClass != null) {
- // Yes, mark as didn't upgrade.
- dartClass._badUpgrade();
- }
- throw e;
- } finally {
- // Need to remember the Dart class that was created for this custom so
- // return it and setup the blink_jsObject to the $this that we'll be working
- // with as we talk to blink.
- js.setDartHtmlWrapperFor($this, dartClass);
- }
-
- return dartClass;
+ return _blink.Blink_Utils.setInstanceInterceptor($this, customElementClass, customElement: true);
}
$else

Powered by Google App Engine
This is Rietveld 408576698