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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/browser/lib/interop.js
diff --git a/pkg/browser/lib/interop.js b/pkg/browser/lib/interop.js
index 40e1700ad76d53fe7d69ec4819c10387678d1789..4f3d6c4f9d6a3ed01bfac985378e2b2237eaa36a 100644
--- a/pkg/browser/lib/interop.js
+++ b/pkg/browser/lib/interop.js
@@ -300,6 +300,33 @@ function DartProxy(o) {
// Direct function invocation.
return [ 'return',
serialize(receiver.apply(args[0], args.slice(1))) ];
+ } else if (kind == 'asMap') {
+ if (member == 'containsValue') {
+ var found = false;
+ for (var p in receiver) {
+ if (receiver[p] === args[0]) {
+ found = true;
+ break;
+ }
+ }
+ return [ 'return', serialize(found) ];
+ } else if (member == 'addAll') {
+ var map = args[0];
+ for (var p in map) {
+ receiver[p] = map[p];
+ }
+ return [ 'return', null ];
+ } else if (member == 'values') {
+ var values = [];
+ for (var p in receiver) {
+ values.push(receiver[p]);
+ }
+ return [ 'return', serialize(values) ];
+ } else if (member == 'length') {
+ return [ 'return', serialize(Object.keys(receiver).length) ];
+ } else {
+ return [ 'throws', 'unsupported operation'];
+ }
} else if (member == '[]' && args.length == 1) {
// Index getter.
return [ 'return', serialize(receiver[args[0]]) ];
@@ -336,6 +363,7 @@ function DartProxy(o) {
// - sendport -> sendport
// - Function -> [ 'funcref', function-id, sendport ]
// - Object -> [ 'objref', object-id, sendport ]
+ // - Array -> [ 'arrayref', object-id, sendport ]
function serialize(message) {
if (message == null) {
return null; // Convert undefined to null.
@@ -364,7 +392,7 @@ function DartProxy(o) {
return [ 'objref', message.id, message.port ];
} else {
// Local object proxy.
- return [ 'objref',
+ return [ message instanceof Array ? 'arrayref' : 'objref',
proxiedObjectTable.add(message),
proxiedObjectTable.sendPort ];
}
« 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