OLD | NEW |
---|---|
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 // Bootstrap support for Dart scripts on the page as this script. | 5 // Bootstrap support for Dart scripts on the page as this script. |
6 if (navigator.webkitStartDart) { | 6 if (navigator.webkitStartDart) { |
7 if (!navigator.webkitStartDart()) { | 7 if (!navigator.webkitStartDart()) { |
8 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html'; | 8 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html'; |
9 } | 9 } |
10 } else { | 10 } else { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 } | 46 } |
47 | 47 |
48 (function() { | 48 (function() { |
49 function serialize(message) { | 49 function serialize(message) { |
50 if (message == null) { | 50 if (message == null) { |
51 return null; // Convert undefined to null. | 51 return null; // Convert undefined to null. |
52 } else if (typeof(message) == 'string' || | 52 } else if (typeof(message) == 'string' || |
53 typeof(message) == 'number' || | 53 typeof(message) == 'number' || |
54 typeof(message) == 'boolean') { | 54 typeof(message) == 'boolean') { |
55 return message; | 55 return message; |
56 } else if (message instanceof Array) { | |
57 return [ 'list', message.length, message ]; | |
vsm
2012/07/06 13:48:16
Hmm. The elements of message should be serialized
sammccall
2012/07/06 16:01:41
Done.
| |
56 } else if (message instanceof LocalSendPortSync) { | 58 } else if (message instanceof LocalSendPortSync) { |
57 return [ 'sendport', 'nativejs', message.receivePort.id ]; | 59 return [ 'sendport', 'nativejs', message.receivePort.id ]; |
58 } else if (message instanceof DartSendPortSync) { | 60 } else if (message instanceof DartSendPortSync) { |
59 return [ 'sendport', 'dart', message.receivePort.isolateId, | 61 return [ 'sendport', 'dart', message.receivePort.isolateId, |
60 message.receivePort.portId ]; | 62 message.receivePort.portId ]; |
61 } else { | 63 } else { |
62 var id = 0; | 64 var id = 0; |
63 var keys = Object.getOwnPropertyNames(message); | 65 var keys = Object.getOwnPropertyNames(message); |
64 var values = new Array(keys.length); | 66 var values = new Array(keys.length); |
65 for (var i = 0; i < keys.length; i++) { | 67 for (var i = 0; i < keys.length; i++) { |
(...skipping 10 matching lines...) Expand all Loading... | |
76 function deserializeHelper(x) { | 78 function deserializeHelper(x) { |
77 if (x == null || | 79 if (x == null || |
78 typeof(x) == 'string' || | 80 typeof(x) == 'string' || |
79 typeof(x) == 'number' || | 81 typeof(x) == 'number' || |
80 typeof(x) == 'boolean') { | 82 typeof(x) == 'boolean') { |
81 return x; | 83 return x; |
82 } | 84 } |
83 switch (x[0]) { | 85 switch (x[0]) { |
84 case 'map': return deserializeMap(x); | 86 case 'map': return deserializeMap(x); |
85 case 'sendport': return deserializeSendPort(x); | 87 case 'sendport': return deserializeSendPort(x); |
88 case 'list': return x[2]; | |
vsm
2012/07/06 13:48:16
I think you need to deserialized the elements of t
sammccall
2012/07/06 16:01:41
Done.
| |
86 default: throw 'unimplemented'; | 89 default: throw 'unimplemented'; |
87 } | 90 } |
88 } | 91 } |
89 | 92 |
90 function deserializeMap(x) { | 93 function deserializeMap(x) { |
91 var result = { }; | 94 var result = { }; |
92 var id = x[1]; | 95 var id = x[1]; |
93 var keys = x[2]; | 96 var keys = x[2]; |
94 var values = x[3]; | 97 var values = x[3]; |
95 for (var i = 0, length = keys.length; i < length; i++) { | 98 for (var i = 0, length = keys.length; i < length; i++) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 var result = null; | 195 var result = null; |
193 var listener = function (e) { | 196 var listener = function (e) { |
194 result = JSON.parse(e.data); | 197 result = JSON.parse(e.data); |
195 }; | 198 }; |
196 window.addEventListener(source, listener, false); | 199 window.addEventListener(source, listener, false); |
197 dispatchEvent(target, [source, serialized]); | 200 dispatchEvent(target, [source, serialized]); |
198 window.removeEventListener(source, listener, false); | 201 window.removeEventListener(source, listener, false); |
199 return deserialize(result); | 202 return deserialize(result); |
200 } | 203 } |
201 })(); | 204 })(); |
OLD | NEW |