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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 import 'dart:html' show Blob, Event, ImageData, Node, Window; | 90 import 'dart:html' show Blob, Event, ImageData, Node, Window; |
91 import 'dart:collection' show HashMap, ListMixin; | 91 import 'dart:collection' show HashMap, ListMixin; |
92 import 'dart:indexed_db' show KeyRange; | 92 import 'dart:indexed_db' show KeyRange; |
93 import 'dart:typed_data' show TypedData; | 93 import 'dart:typed_data' show TypedData; |
94 | 94 |
95 import 'dart:_foreign_helper' show JS, DART_CLOSURE_TO_JS; | 95 import 'dart:_foreign_helper' show JS, DART_CLOSURE_TO_JS; |
96 import 'dart:_interceptors' show JavaScriptObject, UnknownJavaScriptObject; | 96 import 'dart:_interceptors' show JavaScriptObject, UnknownJavaScriptObject; |
97 import 'dart:_js_helper' show Primitives, convertDartClosureToJS, | 97 import 'dart:_js_helper' show Primitives, convertDartClosureToJS, |
98 getIsolateAffinityTag; | 98 getIsolateAffinityTag; |
99 | 99 |
100 final JsObject context = _wrapToDart(Primitives.computeGlobalThis()); | 100 final JsObject context = _wrapToDart(JS('', 'self')); |
101 | 101 |
102 _convertDartFunction(Function f, {bool captureThis: false}) { | 102 _convertDartFunction(Function f, {bool captureThis: false}) { |
103 return JS('', | 103 return JS('', |
104 'function(_call, f, captureThis) {' | 104 'function(_call, f, captureThis) {' |
105 'return function() {' | 105 'return function() {' |
106 'return _call(f, captureThis, this, ' | 106 'return _call(f, captureThis, this, ' |
107 'Array.prototype.slice.apply(arguments));' | 107 'Array.prototype.slice.apply(arguments));' |
108 '}' | 108 '}' |
109 '}(#, #, #)', DART_CLOSURE_TO_JS(_callDartFunction), f, captureThis); | 109 '}(#, #, #)', DART_CLOSURE_TO_JS(_callDartFunction), f, captureThis); |
110 } | 110 } |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // Dart in that context. The JS object will have a cached proxy | 573 // Dart in that context. The JS object will have a cached proxy |
574 // but it won't be a valid Dart object in this context. | 574 // but it won't be a valid Dart object in this context. |
575 // For now we throw away the cached proxy, but we should be able | 575 // For now we throw away the cached proxy, but we should be able |
576 // to cache proxies from multiple JS contexts and Dart isolates. | 576 // to cache proxies from multiple JS contexts and Dart isolates. |
577 if (dartProxy == null || !_isLocalObject(o)) { | 577 if (dartProxy == null || !_isLocalObject(o)) { |
578 dartProxy = createProxy(o); | 578 dartProxy = createProxy(o); |
579 _defineProperty(o, propertyName, dartProxy); | 579 _defineProperty(o, propertyName, dartProxy); |
580 } | 580 } |
581 return dartProxy; | 581 return dartProxy; |
582 } | 582 } |
OLD | NEW |