| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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:html_common' as html_common; |
| 96 import 'dart:indexed_db' as indexed_db; | 96 import 'dart:indexed_db' as indexed_db; |
| 97 import 'dart:typed_data'; | 97 import 'dart:typed_data'; |
| 98 | 98 |
| 99 // 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 |
| 100 // running Dartium code outside of checked mode. | 100 // running Dartium code outside of checked mode. |
| 101 @Deprecated("Internal Use Only") |
| 101 final bool CHECK_JS_INVOCATIONS = true; | 102 final bool CHECK_JS_INVOCATIONS = true; |
| 102 | 103 |
| 103 final _allowedMethods = new Map<Symbol, _DeclarationSet>(); | 104 final _allowedMethods = new Map<Symbol, _DeclarationSet>(); |
| 104 final _allowedGetters = new Map<Symbol, _DeclarationSet>(); | 105 final _allowedGetters = new Map<Symbol, _DeclarationSet>(); |
| 105 final _allowedSetters = new Map<Symbol, _DeclarationSet>(); | 106 final _allowedSetters = new Map<Symbol, _DeclarationSet>(); |
| 106 | 107 |
| 107 final _jsInterfaceTypes = new Set<mirrors.ClassMirror>(); | 108 final _jsInterfaceTypes = new Set<mirrors.ClassMirror>(); |
| 109 @Deprecated("Internal Use Only") |
| 108 Iterable<mirrors.ClassMirror> get jsInterfaceTypes => _jsInterfaceTypes; | 110 Iterable<mirrors.ClassMirror> get jsInterfaceTypes => _jsInterfaceTypes; |
| 109 | 111 |
| 110 /// A collection of methods where all methods have the same name. | 112 /// A collection of methods where all methods have the same name. |
| 111 /// This class is intended to optimize whether a specific invocation is | 113 /// This class is intended to optimize whether a specific invocation is |
| 112 /// appropritate for at least some of the methods in the collection. | 114 /// appropritate for at least some of the methods in the collection. |
| 113 class _DeclarationSet { | 115 class _DeclarationSet { |
| 114 _DeclarationSet() : _members = <mirrors.DeclarationMirror>[]; | 116 _DeclarationSet() : _members = <mirrors.DeclarationMirror>[]; |
| 115 | 117 |
| 116 static bool _checkType(obj, mirrors.TypeMirror type) { | 118 static bool _checkType(obj, mirrors.TypeMirror type) { |
| 117 if (obj == null) return true; | 119 if (obj == null) return true; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 _members.add(mirror); | 202 _members.add(mirror); |
| 201 } | 203 } |
| 202 | 204 |
| 203 final List<mirrors.DeclarationMirror> _members; | 205 final List<mirrors.DeclarationMirror> _members; |
| 204 } | 206 } |
| 205 | 207 |
| 206 /** | 208 /** |
| 207 * Temporary method that we hope to remove at some point. This method should | 209 * Temporary method that we hope to remove at some point. This method should |
| 208 * generally only be called by machine generated code. | 210 * generally only be called by machine generated code. |
| 209 */ | 211 */ |
| 212 @Deprecated("Internal Use Only") |
| 210 void registerJsInterfaces([List<Type> classes]) { | 213 void registerJsInterfaces([List<Type> classes]) { |
| 211 // This method is now obsolete in Dartium. | 214 // This method is now obsolete in Dartium. |
| 212 } | 215 } |
| 213 | 216 |
| 214 void _registerJsInterfaces(List<Type> classes) { | 217 void _registerJsInterfaces(List<Type> classes) { |
| 215 for (Type type in classes) { | 218 for (Type type in classes) { |
| 216 mirrors.ClassMirror typeMirror = mirrors.reflectType(type); | 219 mirrors.ClassMirror typeMirror = mirrors.reflectType(type); |
| 217 typeMirror.declarations.forEach((symbol, declaration) { | 220 typeMirror.declarations.forEach((symbol, declaration) { |
| 218 if (declaration is mirrors.MethodMirror || | 221 if (declaration is mirrors.MethodMirror || |
| 219 declaration is mirrors.VariableMirror && !declaration.isStatic) { | 222 declaration is mirrors.VariableMirror && !declaration.isStatic) { |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 l.sort(compare); | 821 l.sort(compare); |
| 819 return l; | 822 return l; |
| 820 } | 823 } |
| 821 // End of block of helper methods to emulate JavaScript Array methods on Dart Li
st. | 824 // End of block of helper methods to emulate JavaScript Array methods on Dart Li
st. |
| 822 | 825 |
| 823 /** | 826 /** |
| 824 * Can be called to provide a predictable point where no more JS interfaces can | 827 * Can be called to provide a predictable point where no more JS interfaces can |
| 825 * be added. Creating an instance of JsObject will also automatically trigger | 828 * be added. Creating an instance of JsObject will also automatically trigger |
| 826 * all JsObjects to be finalized. | 829 * all JsObjects to be finalized. |
| 827 */ | 830 */ |
| 831 @Deprecated("Internal Use Only") |
| 828 void finalizeJsInterfaces() { | 832 void finalizeJsInterfaces() { |
| 829 if (_finalized == true) { | 833 if (_finalized == true) { |
| 830 throw 'JSInterop class registration already finalized'; | 834 throw 'JSInterop class registration already finalized'; |
| 831 } | 835 } |
| 832 _finalizeJsInterfaces(); | 836 _finalizeJsInterfaces(); |
| 833 } | 837 } |
| 834 | 838 |
| 835 JsObject _cachedContext; | 839 JsObject _cachedContext; |
| 836 | 840 |
| 837 JsObject get _context native "Js_context_Callback"; | 841 JsObject get _context native "Js_context_Callback"; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 return f; | 1355 return f; |
| 1352 } else { | 1356 } else { |
| 1353 var ret = _interopCaptureThisExpando[f]; | 1357 var ret = _interopCaptureThisExpando[f]; |
| 1354 if (ret == null) { | 1358 if (ret == null) { |
| 1355 ret = new JsFunction.withThis(f); | 1359 ret = new JsFunction.withThis(f); |
| 1356 _interopCaptureThisExpando[f] = ret; | 1360 _interopCaptureThisExpando[f] = ret; |
| 1357 } | 1361 } |
| 1358 return ret; | 1362 return ret; |
| 1359 } | 1363 } |
| 1360 } | 1364 } |
| OLD | NEW |