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

Side by Side Diff: pkg/browser/lib/interop.js

Issue 23291005: add JsArray and JsObject.asJsMap() Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix dart2js and add automatic convertion of Iterables and Maps Created 7 years, 4 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 | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | sdk/lib/js/dart2js/js_dart2js.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // --------------------------------------------------------------------------- 5 // ---------------------------------------------------------------------------
6 // Support for JS interoperability 6 // Support for JS interoperability
7 // --------------------------------------------------------------------------- 7 // ---------------------------------------------------------------------------
8 function SendPortSync() { 8 function SendPortSync() {
9 } 9 }
10 10
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 function DartProxy(id, sendPort) { 329 function DartProxy(id, sendPort) {
330 this.id = id; 330 this.id = id;
331 this.port = sendPort; 331 this.port = sendPort;
332 } 332 }
333 333
334 // Serializes JS types to SendPortSync format: 334 // Serializes JS types to SendPortSync format:
335 // - primitives -> primitives 335 // - primitives -> primitives
336 // - sendport -> sendport 336 // - sendport -> sendport
337 // - Function -> [ 'funcref', function-id, sendport ] 337 // - Function -> [ 'funcref', function-id, sendport ]
338 // - Object -> [ 'objref', object-id, sendport ] 338 // - Object -> [ 'objref', object-id, sendport ]
339 // - Array -> [ 'arrayref', object-id, sendport ]
339 function serialize(message) { 340 function serialize(message) {
340 if (message == null) { 341 if (message == null) {
341 return null; // Convert undefined to null. 342 return null; // Convert undefined to null.
342 } else if (typeof(message) == 'string' || 343 } else if (typeof(message) == 'string' ||
343 typeof(message) == 'number' || 344 typeof(message) == 'number' ||
344 typeof(message) == 'boolean') { 345 typeof(message) == 'boolean') {
345 // Primitives are passed directly through. 346 // Primitives are passed directly through.
346 return message; 347 return message;
347 } else if (message instanceof SendPortSync) { 348 } else if (message instanceof SendPortSync) {
348 // Non-proxied objects are serialized. 349 // Non-proxied objects are serialized.
349 return message; 350 return message;
350 } else if (typeof(message) == 'function') { 351 } else if (typeof(message) == 'function') {
351 if ('_dart_id' in message) { 352 if ('_dart_id' in message) {
352 // Remote function proxy. 353 // Remote function proxy.
353 var remoteId = message._dart_id; 354 var remoteId = message._dart_id;
354 var remoteSendPort = message._dart_port; 355 var remoteSendPort = message._dart_port;
355 return [ 'funcref', remoteId, remoteSendPort ]; 356 return [ 'funcref', remoteId, remoteSendPort ];
356 } else { 357 } else {
357 // Local function proxy. 358 // Local function proxy.
358 return [ 'funcref', 359 return [ 'funcref',
359 proxiedObjectTable.add(message), 360 proxiedObjectTable.add(message),
360 proxiedObjectTable.sendPort ]; 361 proxiedObjectTable.sendPort ];
361 } 362 }
362 } else if (message instanceof DartProxy) { 363 } else if (message instanceof DartProxy) {
363 // Remote object proxy. 364 // Remote object proxy.
364 return [ 'objref', message.id, message.port ]; 365 return [ 'objref', message.id, message.port ];
365 } else { 366 } else {
366 // Local object proxy. 367 // Local object proxy.
367 return [ 'objref', 368 return [ message instanceof Array ? 'arrayref' : 'objref',
368 proxiedObjectTable.add(message), 369 proxiedObjectTable.add(message),
369 proxiedObjectTable.sendPort ]; 370 proxiedObjectTable.sendPort ];
370 } 371 }
371 } 372 }
372 373
373 function deserialize(message) { 374 function deserialize(message) {
374 if (message == null) { 375 if (message == null) {
375 return null; // Convert undefined to null. 376 return null; // Convert undefined to null.
376 } else if (typeof(message) == 'string' || 377 } else if (typeof(message) == 'string' ||
377 typeof(message) == 'number' || 378 typeof(message) == 'number' ||
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 port.receive(f); 531 port.receive(f);
531 window.registerPort(name, port.toSendPort()); 532 window.registerPort(name, port.toSendPort());
532 } 533 }
533 534
534 makeGlobalPort('dart-js-context', context); 535 makeGlobalPort('dart-js-context', context);
535 makeGlobalPort('dart-js-create', construct); 536 makeGlobalPort('dart-js-create', construct);
536 makeGlobalPort('dart-js-instanceof', proxyInstanceof); 537 makeGlobalPort('dart-js-instanceof', proxyInstanceof);
537 makeGlobalPort('dart-js-delete-property', proxyDeleteProperty); 538 makeGlobalPort('dart-js-delete-property', proxyDeleteProperty);
538 makeGlobalPort('dart-js-convert', proxyConvert); 539 makeGlobalPort('dart-js-convert', proxyConvert);
539 })(); 540 })();
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | sdk/lib/js/dart2js/js_dart2js.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698