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

Side by Side Diff: client/dart.js

Issue 10700101: First experimental steps towards a better story for JS interop. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/dom/templates/html/frog/html_frog.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 15 matching lines...) Expand all
26 if (scripts[i].src && scripts[i].src != '') { 26 if (scripts[i].src && scripts[i].src != '') {
27 var script = document.createElement('script'); 27 var script = document.createElement('script');
28 script.src = scripts[i].src + '.js'; 28 script.src = scripts[i].src + '.js';
29 var parent = scripts[i].parentNode; 29 var parent = scripts[i].parentNode;
30 parent.replaceChild(script, scripts[i]); 30 parent.replaceChild(script, scripts[i]);
31 } 31 }
32 } 32 }
33 } 33 }
34 }, false); 34 }, false);
35 } 35 }
36
37 // ---------------------------------------------------------------------------
38 // Experimental support for JS interoperability
39 // ---------------------------------------------------------------------------
40
41 function SendPortSync(receivePort) {
42 this.receivePort = receivePort;
43 }
44
45 function ReceivePortSync() {
46 this.id = ReceivePortSync.id++;
47 ReceivePortSync.map[this.id] = this;
48 }
49
50 ReceivePortSync.id = 0;
51 ReceivePortSync.map = {};
52
53 ReceivePortSync.prototype.receive = function(callback) {
54 this.callback = callback;
55 };
56
57 ReceivePortSync.prototype.toSendPort = function() {
58 return new SendPortSync(this);
59 };
60
61 ReceivePortSync.prototype.close = function() {
62 delete ReceivePortSync.map[this.id];
63 };
64
65 // TODO(kasperl): Hide these serialization methods so they
66 // do not clutter up the global scope.
67 function _serialize(message) {
68 if (message == null ||
69 typeof(message) == 'string' ||
70 typeof(message) == 'number' ||
71 typeof(message) == 'boolean') {
72 return message;
73 } else if (message instanceof SendPortSync) {
74 return [ 'sendport', message.receivePort.id ];
75 } else {
76 var id = 0;
77 var keys = Object.getOwnPropertyNames(message);
78 var values = new Array(keys.length);
79 for (var i = 0; i < keys.length; i++) {
80 values[i] = message[keys[i]];
81 }
82 return [ 'map', id, keys, values ];
83 }
84 }
85
86 function _deserialize(message) {
87 return _deserializeHelper(message);
88 }
89
90 function _deserializeHelper(x) {
91 if (x == null ||
92 typeof(x) == 'string' ||
93 typeof(x) == 'number' ||
94 typeof(x) == 'boolean') {
95 return x;
96 }
97 switch (x[0]) {
98 case 'map': return _deserializeMap(x);
99 default: throw 'unimplemented';
100 }
101 }
102
103 function _deserializeMap(x) {
104 var result = { };
105 var id = x[1];
106 var keys = x[2];
107 var values = x[3];
108 for (var i = 0, length = keys.length; i < length; i++) {
109 var key = _deserializeHelper(keys[i]);
110 var value = _deserializeHelper(values[i]);
111 result[key] = value;
112 }
113 return result;
114 }
115
116 function registerPort(name, port) {
117 var stringified = JSON.stringify(_serialize(port));
118 window.localStorage['dart-port:' + name] = stringified;
119 }
OLDNEW
« no previous file with comments | « no previous file | lib/dom/templates/html/frog/html_frog.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698