OLD | NEW |
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 interoperating with JavaScript. | 6 * Support for interoperating with JavaScript. |
7 * | 7 * |
8 * This library provides access to JavaScript objects from Dart, allowing | 8 * This library provides access to JavaScript objects from Dart, allowing |
9 * Dart code to get and set properties, and call methods of JavaScript objects | 9 * Dart code to get and set properties, and call methods of JavaScript objects |
10 * and invoke JavaScript functions. The library takes care of converting | 10 * and invoke JavaScript functions. The library takes care of converting |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 * | 85 * |
86 * var jsArray = new JsObject.jsify([1, 2, 3]); | 86 * var jsArray = new JsObject.jsify([1, 2, 3]); |
87 */ | 87 */ |
88 library dart.js; | 88 library dart.js; |
89 | 89 |
90 import 'dart:collection' show ListMixin; | 90 import 'dart:collection' show ListMixin; |
91 import 'dart:nativewrappers'; | 91 import 'dart:nativewrappers'; |
92 import 'dart:math' as math; | 92 import 'dart:math' as math; |
93 import 'dart:mirrors' as mirrors; | 93 import 'dart:mirrors' as mirrors; |
94 import 'dart:html' as html; | 94 import 'dart:html' as html; |
| 95 import 'dart:html_common' as html_common; |
95 import 'dart:indexed_db' as indexed_db; | 96 import 'dart:indexed_db' as indexed_db; |
96 import 'dart:typed_data'; | 97 import 'dart:typed_data'; |
97 | 98 |
98 // Pretend we are always in checked mode as we aren't interested in users | 99 // Pretend we are always in checked mode as we aren't interested in users |
99 // running Dartium code outside of checked mode. | 100 // running Dartium code outside of checked mode. |
100 final bool CHECK_JS_INVOCATIONS = true; | 101 final bool CHECK_JS_INVOCATIONS = true; |
101 | 102 |
102 final _allowedMethods = new Map<Symbol, _DeclarationSet>(); | 103 final _allowedMethods = new Map<Symbol, _DeclarationSet>(); |
103 final _allowedGetters = new Map<Symbol, _DeclarationSet>(); | 104 final _allowedGetters = new Map<Symbol, _DeclarationSet>(); |
104 final _allowedSetters = new Map<Symbol, _DeclarationSet>(); | 105 final _allowedSetters = new Map<Symbol, _DeclarationSet>(); |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 bool get _finalized native "Js_interfacesFinalized_Callback"; | 694 bool get _finalized native "Js_interfacesFinalized_Callback"; |
694 | 695 |
695 JsObject get context { | 696 JsObject get context { |
696 if (_cachedContext == null) { | 697 if (_cachedContext == null) { |
697 _cachedContext = _context; | 698 _cachedContext = _context; |
698 } | 699 } |
699 return _cachedContext; | 700 return _cachedContext; |
700 } | 701 } |
701 | 702 |
702 _maybeWrap(o) { | 703 _maybeWrap(o) { |
703 var wrapped = html.wrap_jso_no_SerializedScriptvalue(o); | 704 var wrapped = html_common.wrap_jso_no_SerializedScriptvalue(o); |
704 if (identical(wrapped, o)) return o; | 705 if (identical(wrapped, o)) return o; |
705 return (wrapped is html.Blob | 706 return (wrapped is html.Blob |
706 || wrapped is html.Event | 707 || wrapped is html.Event |
707 || wrapped is indexed_db.KeyRange | 708 || wrapped is indexed_db.KeyRange |
708 || wrapped is html.ImageData | 709 || wrapped is html.ImageData |
709 || wrapped is html.Node | 710 || wrapped is html.Node |
710 || wrapped is TypedData | 711 || wrapped is TypedData |
711 || wrapped is html.Window) ? wrapped : o; | 712 || wrapped is html.Window) ? wrapped : o; |
712 } | 713 } |
713 | 714 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 */ | 813 */ |
813 factory JsObject.jsify(object) { | 814 factory JsObject.jsify(object) { |
814 if ((object is! Map) && (object is! Iterable)) { | 815 if ((object is! Map) && (object is! Iterable)) { |
815 throw new ArgumentError("object must be a Map or Iterable"); | 816 throw new ArgumentError("object must be a Map or Iterable"); |
816 } | 817 } |
817 return _jsify(object); | 818 return _jsify(object); |
818 } | 819 } |
819 | 820 |
820 static JsObject _jsify(object) native "JsObject_jsify"; | 821 static JsObject _jsify(object) native "JsObject_jsify"; |
821 | 822 |
822 static JsObject _fromBrowserObject(object) => html.unwrap_jso(object); | 823 static JsObject _fromBrowserObject(object) => html_common.unwrap_jso(object); |
823 | 824 |
824 /** | 825 /** |
825 * Returns the value associated with [property] from the proxied JavaScript | 826 * Returns the value associated with [property] from the proxied JavaScript |
826 * object. | 827 * object. |
827 * | 828 * |
828 * The type of [property] must be either [String] or [num]. | 829 * The type of [property] must be either [String] or [num]. |
829 */ | 830 */ |
830 operator [](property) { | 831 operator [](property) { |
831 try { | 832 try { |
832 return _maybeWrap(_operator_getter(property)); | 833 return _maybeWrap(_operator_getter(property)); |
(...skipping 18 matching lines...) Expand all Loading... |
851 throw new html.DomException.jsInterop(e); | 852 throw new html.DomException.jsInterop(e); |
852 } | 853 } |
853 } | 854 } |
854 _operator_setter(property, value) native "JsObject_[]="; | 855 _operator_setter(property, value) native "JsObject_[]="; |
855 | 856 |
856 int get hashCode native "JsObject_hashCode"; | 857 int get hashCode native "JsObject_hashCode"; |
857 | 858 |
858 operator ==(other) { | 859 operator ==(other) { |
859 var is_JsObject = other is JsObject; | 860 var is_JsObject = other is JsObject; |
860 if (!is_JsObject) { | 861 if (!is_JsObject) { |
861 other = html.unwrap_jso(other); | 862 other = html_common.unwrap_jso(other); |
862 is_JsObject = other is JsObject; | 863 is_JsObject = other is JsObject; |
863 } | 864 } |
864 return is_JsObject && _identityEquality(this, other); | 865 return is_JsObject && _identityEquality(this, other); |
865 } | 866 } |
866 | 867 |
867 static bool _identityEquality( | 868 static bool _identityEquality( |
868 JsObject a, JsObject b) native "JsObject_identityEquality"; | 869 JsObject a, JsObject b) native "JsObject_identityEquality"; |
869 | 870 |
870 /** | 871 /** |
871 * Returns `true` if the JavaScript object contains the specified property | 872 * Returns `true` if the JavaScript object contains the specified property |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 return f; | 1175 return f; |
1175 } else { | 1176 } else { |
1176 var ret = _interopCaptureThisExpando[f]; | 1177 var ret = _interopCaptureThisExpando[f]; |
1177 if (ret == null) { | 1178 if (ret == null) { |
1178 ret = new JsFunction.withThis(f); | 1179 ret = new JsFunction.withThis(f); |
1179 _interopCaptureThisExpando[f] = ret; | 1180 _interopCaptureThisExpando[f] = ret; |
1180 } | 1181 } |
1181 return ret; | 1182 return ret; |
1182 } | 1183 } |
1183 } | 1184 } |
OLD | NEW |