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 576cb23451a596c23f569eecca11f7185d2cebbb..f9d2ade91b219837494e8fe692d12cdb30ba7a06 100644 |
--- a/sdk/lib/js/dart2js/js_dart2js.dart |
+++ b/sdk/lib/js/dart2js/js_dart2js.dart |
@@ -4,7 +4,7 @@ |
/** |
* Support for interoperating with JavaScript. |
- * |
+ * |
* This library provides access to JavaScript objects from Dart, allowing |
* Dart code to get and set properties, and call methods of JavaScript objects |
* and invoke JavaScript functions. The library takes care of converting |
@@ -27,14 +27,14 @@ |
* global function `alert()`: |
* |
* import 'dart:js'; |
- * |
+ * |
* main() => context.callMethod('alert', ['Hello from Dart!']); |
* |
* This example shows how to create a [JsObject] from a JavaScript constructor |
* and access its properties: |
* |
* import 'dart:js'; |
- * |
+ * |
* main() { |
* var object = new JsObject(context['Object']); |
* object['greeting'] = 'Hello'; |
@@ -44,7 +44,7 @@ |
* } |
* |
* ## Proxying and automatic conversion |
- * |
+ * |
* When setting properties on a JsObject or passing arguments to a Javascript |
* method or function, Dart objects are automatically converted or proxied to |
* JavaScript objects. When accessing JavaScript properties, or when a Dart |
@@ -80,7 +80,7 @@ |
* `a` and `b` defined: |
* |
* var jsMap = new JsObject.jsify({'a': 1, 'b': 2}); |
- * |
+ * |
* This expression creates a JavaScript array: |
* |
* var jsArray = new JsObject.jsify([1, 2, 3]); |
@@ -165,7 +165,7 @@ class JsObject { |
* Use this constructor only if you wish to get access to JavaScript |
* properties attached to a browser host object, such as a Node or Blob, that |
* is normally automatically converted into a native Dart object. |
- * |
+ * |
* An exception will be thrown if [object] either is `null` or has the type |
* `bool`, `num`, or `String`. |
*/ |
@@ -232,7 +232,7 @@ class JsObject { |
} |
return _convertToDart(JS('', '#[#]', _jsObject, property)); |
} |
- |
+ |
/** |
* Sets the value associated with [property] on the proxied JavaScript |
* object. |
@@ -410,7 +410,7 @@ class JsArray<E> extends JsObject with ListMixin<E> { |
} |
void addAll(Iterable<E> iterable) { |
- var list = (JS('bool', '# instanceof Array', iterable)) |
+ var list = (JS('bool', '# instanceof Array', iterable)) |
? iterable |
: new List.from(iterable); |
callMethod('push', list); |
@@ -450,9 +450,28 @@ class JsArray<E> extends JsObject with ListMixin<E> { |
} |
} |
+// When multiple Dart programs are run in the same page we must make sure that |
+// they don't share their Dart wrappers. We use a global (shared) counter in |
+// the Object class to assign a unique id to every Dart program. |
+int _getAndUpdateDisambiguationId() { |
+ const DISAMBIGUATION_PROPERTY_NAME = "__DART_INTEROP_COUNTER_"; |
+ int counter = JS("int", 'Object[#]||0', DISAMBIGUATION_PROPERTY_NAME); |
+ JS("", 'Object[#]=#', DISAMBIGUATION_PROPERTY_NAME, counter + 1); |
+ return counter; |
+} |
+ |
+final int _disambiguationId = _getAndUpdateDisambiguationId(); |
+ |
+// Converts the given string to a v8 internal symbol which is faster. |
+String _intern(String str) { |
+ return JS("String", "convertToJSSymbol(#)", str); |
+} |
+ |
// 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'; |
+final String _DART_OBJECT_PROPERTY_NAME = |
+ _intern("_\$dart_dartObject$_disambiguationId"); |
+final String _DART_CLOSURE_PROPERTY_NAME = |
+ _intern("_\$dart_dartObject$_disambiguationId"); |
// property added to a JS object referencing its Dart-side JsObject proxy |
const _JS_OBJECT_PROPERTY_NAME = r'_$dart_jsObject'; |