| 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;
|
| + }
|
| +
|
| +}
|
|
|