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

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: optimizations Created 7 years, 3 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') | 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) 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (args.length == 1) { 293 if (args.length == 1) {
294 return [ 'return', serialize(receiver[field] = args[0]) ]; 294 return [ 'return', serialize(receiver[field] = args[0]) ];
295 } 295 }
296 } else if (kind == 'hasProperty') { 296 } else if (kind == 'hasProperty') {
297 var field = member; 297 var field = member;
298 return [ 'return', field in receiver ]; 298 return [ 'return', field in receiver ];
299 } else if (kind == 'apply') { 299 } else if (kind == 'apply') {
300 // Direct function invocation. 300 // Direct function invocation.
301 return [ 'return', 301 return [ 'return',
302 serialize(receiver.apply(args[0], args.slice(1))) ]; 302 serialize(receiver.apply(args[0], args.slice(1))) ];
303 } else if (kind == 'asMap') {
304 if (member == 'containsValue') {
305 var found = false;
306 for (var p in receiver) {
307 if (receiver[p] === args[0]) {
308 found = true;
309 break;
310 }
311 }
312 return [ 'return', serialize(found) ];
313 } else if (member == 'addAll') {
314 var map = args[0];
315 for (var p in map) {
316 receiver[p] = map[p];
317 }
318 return [ 'return', null ];
319 } else if (member == 'values') {
320 var values = [];
321 for (var p in receiver) {
322 values.push(receiver[p]);
323 }
324 return [ 'return', serialize(values) ];
325 } else if (member == 'length') {
326 return [ 'return', serialize(Object.keys(receiver).length) ];
327 } else {
328 return [ 'throws', 'unsupported operation'];
329 }
303 } else if (member == '[]' && args.length == 1) { 330 } else if (member == '[]' && args.length == 1) {
304 // Index getter. 331 // Index getter.
305 return [ 'return', serialize(receiver[args[0]]) ]; 332 return [ 'return', serialize(receiver[args[0]]) ];
306 } else if (member == '[]=' && args.length == 2) { 333 } else if (member == '[]=' && args.length == 2) {
307 // Index setter. 334 // Index setter.
308 return [ 'return', serialize(receiver[args[0]] = args[1]) ]; 335 return [ 'return', serialize(receiver[args[0]] = args[1]) ];
309 } else { 336 } else {
310 // Member function invocation. 337 // Member function invocation.
311 var f = receiver[member]; 338 var f = receiver[member];
312 if (f) { 339 if (f) {
(...skipping 16 matching lines...) Expand all
329 function DartProxy(id, sendPort) { 356 function DartProxy(id, sendPort) {
330 this.id = id; 357 this.id = id;
331 this.port = sendPort; 358 this.port = sendPort;
332 } 359 }
333 360
334 // Serializes JS types to SendPortSync format: 361 // Serializes JS types to SendPortSync format:
335 // - primitives -> primitives 362 // - primitives -> primitives
336 // - sendport -> sendport 363 // - sendport -> sendport
337 // - Function -> [ 'funcref', function-id, sendport ] 364 // - Function -> [ 'funcref', function-id, sendport ]
338 // - Object -> [ 'objref', object-id, sendport ] 365 // - Object -> [ 'objref', object-id, sendport ]
366 // - Array -> [ 'arrayref', object-id, sendport ]
339 function serialize(message) { 367 function serialize(message) {
340 if (message == null) { 368 if (message == null) {
341 return null; // Convert undefined to null. 369 return null; // Convert undefined to null.
342 } else if (typeof(message) == 'string' || 370 } else if (typeof(message) == 'string' ||
343 typeof(message) == 'number' || 371 typeof(message) == 'number' ||
344 typeof(message) == 'boolean') { 372 typeof(message) == 'boolean') {
345 // Primitives are passed directly through. 373 // Primitives are passed directly through.
346 return message; 374 return message;
347 } else if (message instanceof SendPortSync) { 375 } else if (message instanceof SendPortSync) {
348 // Non-proxied objects are serialized. 376 // Non-proxied objects are serialized.
349 return message; 377 return message;
350 } else if (typeof(message) == 'function') { 378 } else if (typeof(message) == 'function') {
351 if ('_dart_id' in message) { 379 if ('_dart_id' in message) {
352 // Remote function proxy. 380 // Remote function proxy.
353 var remoteId = message._dart_id; 381 var remoteId = message._dart_id;
354 var remoteSendPort = message._dart_port; 382 var remoteSendPort = message._dart_port;
355 return [ 'funcref', remoteId, remoteSendPort ]; 383 return [ 'funcref', remoteId, remoteSendPort ];
356 } else { 384 } else {
357 // Local function proxy. 385 // Local function proxy.
358 return [ 'funcref', 386 return [ 'funcref',
359 proxiedObjectTable.add(message), 387 proxiedObjectTable.add(message),
360 proxiedObjectTable.sendPort ]; 388 proxiedObjectTable.sendPort ];
361 } 389 }
362 } else if (message instanceof DartProxy) { 390 } else if (message instanceof DartProxy) {
363 // Remote object proxy. 391 // Remote object proxy.
364 return [ 'objref', message.id, message.port ]; 392 return [ 'objref', message.id, message.port ];
365 } else { 393 } else {
366 // Local object proxy. 394 // Local object proxy.
367 return [ 'objref', 395 return [ message instanceof Array ? 'arrayref' : 'objref',
368 proxiedObjectTable.add(message), 396 proxiedObjectTable.add(message),
369 proxiedObjectTable.sendPort ]; 397 proxiedObjectTable.sendPort ];
370 } 398 }
371 } 399 }
372 400
373 function deserialize(message) { 401 function deserialize(message) {
374 if (message == null) { 402 if (message == null) {
375 return null; // Convert undefined to null. 403 return null; // Convert undefined to null.
376 } else if (typeof(message) == 'string' || 404 } else if (typeof(message) == 'string' ||
377 typeof(message) == 'number' || 405 typeof(message) == 'number' ||
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 port.receive(f); 558 port.receive(f);
531 window.registerPort(name, port.toSendPort()); 559 window.registerPort(name, port.toSendPort());
532 } 560 }
533 561
534 makeGlobalPort('dart-js-context', context); 562 makeGlobalPort('dart-js-context', context);
535 makeGlobalPort('dart-js-create', construct); 563 makeGlobalPort('dart-js-create', construct);
536 makeGlobalPort('dart-js-instanceof', proxyInstanceof); 564 makeGlobalPort('dart-js-instanceof', proxyInstanceof);
537 makeGlobalPort('dart-js-delete-property', proxyDeleteProperty); 565 makeGlobalPort('dart-js-delete-property', proxyDeleteProperty);
538 makeGlobalPort('dart-js-convert', proxyConvert); 566 makeGlobalPort('dart-js-convert', proxyConvert);
539 })(); 567 })();
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698