| Index: sdk/lib/js/dartium/js_dartium.dart
|
| diff --git a/sdk/lib/js/dartium/js_dartium.dart b/sdk/lib/js/dartium/js_dartium.dart
|
| index 0bb53c361dcd37bde51019ab9d5a4d782b004292..b6c71981cd4590eeba8091d0df69f7d54730c200 100644
|
| --- a/sdk/lib/js/dartium/js_dartium.dart
|
| +++ b/sdk/lib/js/dartium/js_dartium.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]);
|
| @@ -91,6 +91,7 @@ import 'dart:collection' show ListMixin;
|
| import 'dart:nativewrappers';
|
| import 'dart:math' as math;
|
| import 'dart:mirrors' as mirrors;
|
| +import 'dart:html' as html;
|
|
|
| // Pretend we are always in checked mode as we aren't interested in users
|
| // running Dartium code outside of checked mode.
|
| @@ -491,8 +492,14 @@ class JsObject extends NativeFieldWrapperClass2 {
|
| * Constructs a new JavaScript object from [constructor] and returns a proxy
|
| * to it.
|
| */
|
| - factory JsObject(JsFunction constructor, [List arguments]) =>
|
| - _create(constructor, arguments);
|
| + factory JsObject(JsFunction constructor, [List arguments]) {
|
| + try {
|
| + return _create(constructor, arguments);
|
| + } catch (e) {
|
| + // Re-throw any errors (returned as a string) as a DomException.
|
| + throw new html.DomException.jsInterop(e);
|
| + }
|
| + }
|
|
|
| static JsObject _create(
|
| JsFunction constructor, arguments) native "JsObject_constructorCallback";
|
| @@ -517,7 +524,7 @@ class JsObject extends NativeFieldWrapperClass2 {
|
| * 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`.
|
| */
|
| @@ -546,8 +553,7 @@ class JsObject extends NativeFieldWrapperClass2 {
|
|
|
| static JsObject _jsify(object) native "JsObject_jsify";
|
|
|
| - static JsObject _fromBrowserObject(
|
| - object) native "JsObject_fromBrowserObject";
|
| + static JsObject _fromBrowserObject(object) => html.unwrap_jso(object);
|
|
|
| /**
|
| * Returns the value associated with [property] from the proxied JavaScript
|
| @@ -555,7 +561,15 @@ class JsObject extends NativeFieldWrapperClass2 {
|
| *
|
| * The type of [property] must be either [String] or [num].
|
| */
|
| - operator [](property) native "JsObject_[]";
|
| + operator [](property) {
|
| + try {
|
| + return _operator_getter(property);
|
| + } catch (e) {
|
| + // Re-throw any errors (returned as a string) as a DomException.
|
| + throw new html.DomException.jsInterop(e);
|
| + }
|
| + }
|
| + _operator_getter(property) native "JsObject_[]";
|
|
|
| /**
|
| * Sets the value associated with [property] on the proxied JavaScript
|
| @@ -563,11 +577,26 @@ class JsObject extends NativeFieldWrapperClass2 {
|
| *
|
| * The type of [property] must be either [String] or [num].
|
| */
|
| - operator []=(property, value) native "JsObject_[]=";
|
| + operator []=(property, value) {
|
| + try {
|
| + _operator_setter(property, value);
|
| + } catch (e) {
|
| + // Re-throw any errors (returned as a string) as a DomException.
|
| + throw new html.DomException.jsInterop(e);
|
| + }
|
| + }
|
| + _operator_setter(property, value) native "JsObject_[]=";
|
|
|
| int get hashCode native "JsObject_hashCode";
|
|
|
| - operator ==(other) => other is JsObject && _identityEquality(this, other);
|
| + operator ==(other) {
|
| + var is_JsObject = other is JsObject;
|
| + if (!is_JsObject) {
|
| + other = html.unwrap_jso(other);
|
| + is_JsObject = other is JsObject;
|
| + }
|
| + return is_JsObject && _identityEquality(this, other);
|
| + }
|
|
|
| static bool _identityEquality(
|
| JsObject a, JsObject b) native "JsObject_identityEquality";
|
| @@ -618,7 +647,8 @@ class JsObject extends NativeFieldWrapperClass2 {
|
| return _callMethod(method, args);
|
| } catch (e) {
|
| if (hasProperty(method)) {
|
| - rethrow;
|
| + // Return a DomException if DOM call returned an error.
|
| + throw new html.DomException.jsInterop(e);
|
| } else {
|
| throw new NoSuchMethodError(this, new Symbol(method), args, null);
|
| }
|
| @@ -754,7 +784,12 @@ class JsArray<E> extends JsObject with ListMixin<E> {
|
| if (index is int) {
|
| _checkIndex(index);
|
| }
|
| - return super[index];
|
| +
|
| + // Lazily create the Dart class that wraps the JS object when the object in
|
| + // a list if fetched.
|
| + var wrap_entry = html.wrap_jso(super[index]);
|
| + super[index] = wrap_entry;
|
| + return wrap_entry;
|
| }
|
|
|
| void operator []=(index, E value) {
|
| @@ -766,7 +801,7 @@ class JsArray<E> extends JsObject with ListMixin<E> {
|
|
|
| int get length native "JsArray_length";
|
|
|
| - void set length(int length) {
|
| + set length(int length) {
|
| super['length'] = length;
|
| }
|
|
|
|
|