Chromium Code Reviews| 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 convertDartClosureToJS, computeGlobalThis; |
| 9 | 9 |
| 10 JsObject _context; | |
|
vsm
2013/09/28 00:55:09
Can't you just do:
final JsObject context = new J
justinfagnani
2013/09/28 01:02:15
Indeed. I keep forgetting about lazy static initia
| |
| 11 | |
| 10 JsObject get context { | 12 JsObject get context { |
| 11 return new JsObject._fromJs(JS('=Object', 'window')); | 13 if (_context == null) { |
| 14 _context = new JsObject._fromJs(computeGlobalThis()); | |
| 15 } | |
| 16 return _context; | |
| 12 } | 17 } |
| 13 | 18 |
| 14 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); | 19 JsObject jsify(dynamic data) => data == null ? null : new JsObject._json(data); |
| 15 | 20 |
| 16 class Callback implements Serializable<JsFunction> { | 21 class Callback implements Serializable<JsFunction> { |
| 17 final Function _f; // here to allow capture in closure | 22 final Function _f; // here to allow capture in closure |
| 18 final bool _withThis; // here to allow capture in closure | 23 final bool _withThis; // here to allow capture in closure |
| 19 dynamic _jsFunction; | 24 dynamic _jsFunction; |
| 20 | 25 |
| 21 Callback._(this._f, this._withThis) { | 26 Callback._(this._f, this._withThis) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 JS('bool', 'typeof # == "boolean" || # instanceof Boolean', o, o)) { | 197 JS('bool', 'typeof # == "boolean" || # instanceof Boolean', o, o)) { |
| 193 return o; | 198 return o; |
| 194 } else if (JS('bool', '# instanceof Function', o)) { | 199 } else if (JS('bool', '# instanceof Function', o)) { |
| 195 return new JsFunction._fromJs(JS('=Object', '#', o)); | 200 return new JsFunction._fromJs(JS('=Object', '#', o)); |
| 196 } else if (JS('bool', '# instanceof DartProxy', o)) { | 201 } else if (JS('bool', '# instanceof DartProxy', o)) { |
| 197 return JS('var', '#.o', o); | 202 return JS('var', '#.o', o); |
| 198 } else { | 203 } else { |
| 199 return new JsObject._fromJs(JS('=Object', '#', o)); | 204 return new JsObject._fromJs(JS('=Object', '#', o)); |
| 200 } | 205 } |
| 201 } | 206 } |
| OLD | NEW |