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

Unified Diff: lib/dom/templates/html/dartium/html_dartium.darttemplate

Issue 10700102: Make the new JS interop test pass on Dartium. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « client/dart.js ('k') | lib/dom/templates/html/dartium/impl_Window.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dom/templates/html/dartium/html_dartium.darttemplate
===================================================================
--- lib/dom/templates/html/dartium/html_dartium.darttemplate (revision 9387)
+++ lib/dom/templates/html/dartium/html_dartium.darttemplate (working copy)
@@ -8,6 +8,7 @@
#library("html");
#import("dart:isolate");
+#import("dart:json");
#import("dart:nativewrappers");
$!GENERATED_DART_FILES
@@ -26,6 +27,7 @@
#source('$AUXILIARY_DIR/../../html/src/_Testing.dart');
#source('$AUXILIARY_DIR/_ListIterators.dart');
#source('$AUXILIARY_DIR/_Lists.dart');
+#source('$AUXILIARY_DIR/../../isolate/serialization.dart');
#source('$AUXILIARY_DIR/native_DOMPublic.dart');
#source('$AUXILIARY_DIR/native_DOMImplementation.dart');
@@ -62,3 +64,55 @@
}
final _null = const _Null();
+
+// TODO(vsm): Move this to a separate Isolates.dart file.
+_serialize(var message) {
+ // TODO(kasperl): Specialize the serializer.
+ return new _Serializer().traverse(message);
+}
+
+_deserialize(var message) {
+ return new _JsDeserializer().deserialize(message);
+}
+
+class _JsDeserializer extends _Deserializer {
+
+ deserializeSendPort(List x) {
+ num id = x[1];
+ return new _JsSendPortSync(id);
+ }
+
+}
+
+class _JsSendPortSync implements SendPortSync {
+
+ static bool initialized = false;
+ static var lastResult = null;
+
+ num _id;
+ _JsSendPortSync(this._id) {
+ if (initialized) return;
+ window.on['js-result'].add((event) {
+ lastResult = JSON.parse(event.data);
+ }, false);
+ initialized = true;
+ }
+
+ callSync(var message) {
+ var serialized = _serialize(message);
+ var result = _callUsingEvent(_id, serialized);
+ return _deserialize(result);
+ }
+
+ static _callUsingEvent(num id, var message) {
+ var data = JSON.stringify({ 'id': id, 'message': message });
+ var event = document.$dom_createEvent('TextEvent');
+ event.initTextEvent('js-sync-message', false, false, window, data);
+ assert(lastResult == null);
+ window.$dom_dispatchEvent(event);
+ var result = lastResult;
+ lastResult = null;
+ return result;
+ }
+
+}
« no previous file with comments | « client/dart.js ('k') | lib/dom/templates/html/dartium/impl_Window.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698