Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: sdk/lib/js/dart2js/js_dart2js.dart

Issue 25138003: Cache the context proxy. Don't use window for global 'this'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/lib/js_helper.dart ('k') | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/js_helper.dart ('k') | sdk/lib/js/dartium/js_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698