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

Unified Diff: sdk/lib/js/dart2js/js_dart2js.dart

Issue 26092003: Maintain referential integrity of proxy instances in dart:js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « pkg/browser/lib/interop.js ('k') | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/js/dart2js/js_dart2js.dart
diff --git a/sdk/lib/js/dart2js/js_dart2js.dart b/sdk/lib/js/dart2js/js_dart2js.dart
index 64b4af0b4771972ac4ac9b773480ece956d914b8..4ee6c2966bfb6fe963b677bfd0556c9a772711f8 100644
--- a/sdk/lib/js/dart2js/js_dart2js.dart
+++ b/sdk/lib/js/dart2js/js_dart2js.dart
@@ -166,6 +166,14 @@ abstract class Serializable<T> {
T toJs();
}
+// property added to a Dart object referencing its JS-side DartObject proxy
+const _DART_OBJECT_PROPERTY_NAME = r'_$dart_dartObject';
+const _DART_CLOSURE_PROPERTY_NAME = r'_$dart_dartClosure';
+
+// property added to a JS object referencing its Dart-side JsObject proxy
+const _JS_OBJECT_PROPERTY_NAME = r'_$dart_jsObject';
+const _JS_FUNCTION_PROPERTY_NAME = r'$dart_jsFunction';
+
dynamic _convertToJS(dynamic o) {
if (o == null) {
return null;
@@ -178,10 +186,12 @@ dynamic _convertToJS(dynamic o) {
} else if (o is Function) {
return _convertToJS(new Callback(o));
} else {
- return JS('=Object', 'new DartProxy(#)', o);
+ return JS('=Object', 'new DartObject(#)', o);
}
}
+// converts a Dart object to a reference to a native JS object
+// which might be a DartObject JS->Dart proxy
dynamic _convertToDart(dynamic o) {
if (JS('bool', '# == null', o)) {
return null;
@@ -190,10 +200,22 @@ dynamic _convertToDart(dynamic o) {
JS('bool', 'typeof # == "boolean" || # instanceof Boolean', o, o)) {
return o;
} else if (JS('bool', '# instanceof Function', o)) {
- return new JsFunction._fromJs(JS('=Object', '#', o));
- } else if (JS('bool', '# instanceof DartProxy', o)) {
+ return _getDartProxy(o, _DART_CLOSURE_PROPERTY_NAME,
+ (o) => JsFunction._fromJs(o));
alexandre.ardhuin 2013/10/07 19:41:30 "new" is missing.
justinfagnani 2013/10/07 20:17:51 Done.
+ } else if (JS('bool', '# instanceof DartObject', o)) {
return JS('var', '#.o', o);
} else {
- return new JsObject._fromJs(JS('=Object', '#', o));
+ return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME,
+ (o) => JsObject._fromJs(o));
alexandre.ardhuin 2013/10/07 19:41:30 "new" is missing.
justinfagnani 2013/10/07 20:17:51 Done.
}
-}
+}
+
+dynamic _getDartProxy(o, String propertyName, createProxy(o)) {
+ var dartProxy = JS('', '#[#]', o, propertyName);
alexandre.ardhuin 2013/10/07 19:41:30 Indentation size.
justinfagnani 2013/10/07 20:17:51 Done.
+ if (dartProxy == null) {
+ dartProxy = createProxy(JS('=Object', '#', o));
+ JS('void', 'Object.defineProperty(#, #, { value: #})', o, propertyName,
+ dartProxy);
+ }
+ return dartProxy;
+}
« no previous file with comments | « pkg/browser/lib/interop.js ('k') | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698