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 library dart.js; | 5 library dart.js; |
6 | 6 |
7 import 'dart:_foreign_helper' show JS; | 7 import 'dart:_foreign_helper' show JS; |
8 import 'dart:_js_helper' show convertDartClosureToJS; | 8 import 'dart:_js_helper' show Primitives, convertDartClosureToJS; |
9 | 9 |
10 JsObject get context { | 10 final JsObject context = new JsObject._fromJs(Primitives.computeGlobalThis()); |
11 return new JsObject._fromJs(JS('=Object', 'window')); | |
12 } | |
13 | 11 |
14 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); | 12 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); |
15 | 13 |
16 class Callback implements Serializable<JsFunction> { | 14 class Callback implements Serializable<JsFunction> { |
17 final Function _f; // here to allow capture in closure | 15 final Function _f; // here to allow capture in closure |
18 final bool _withThis; // here to allow capture in closure | 16 final bool _withThis; // here to allow capture in closure |
19 dynamic _jsFunction; | 17 dynamic _jsFunction; |
20 | 18 |
21 Callback._(this._f, this._withThis) { | 19 Callback._(this._f, this._withThis) { |
22 _jsFunction = JS('=Object', r''' | 20 _jsFunction = JS('=Object', r''' |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 JS('bool', 'typeof # == "boolean" || # instanceof Boolean', o, o)) { | 190 JS('bool', 'typeof # == "boolean" || # instanceof Boolean', o, o)) { |
193 return o; | 191 return o; |
194 } else if (JS('bool', '# instanceof Function', o)) { | 192 } else if (JS('bool', '# instanceof Function', o)) { |
195 return new JsFunction._fromJs(JS('=Object', '#', o)); | 193 return new JsFunction._fromJs(JS('=Object', '#', o)); |
196 } else if (JS('bool', '# instanceof DartProxy', o)) { | 194 } else if (JS('bool', '# instanceof DartProxy', o)) { |
197 return JS('var', '#.o', o); | 195 return JS('var', '#.o', o); |
198 } else { | 196 } else { |
199 return new JsObject._fromJs(JS('=Object', '#', o)); | 197 return new JsObject._fromJs(JS('=Object', '#', o)); |
200 } | 198 } |
201 } | 199 } |
OLD | NEW |