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

Side by Side Diff: sdk/lib/js/dartium/js_dartium.dart

Issue 222203009: Execute callbacks from JS in the correct zone Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add _wrapToJs Created 6 years, 8 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/js/dart2js/js_dart2js.dart ('k') | tests/html/js_test.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 /** 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 * `a` and `b` defined: 80 * `a` and `b` defined:
81 * 81 *
82 * var jsMap = new JsObject.jsify({'a': 1, 'b': 2}); 82 * var jsMap = new JsObject.jsify({'a': 1, 'b': 2});
83 * 83 *
84 * This expression creates a JavaScript array: 84 * This expression creates a JavaScript array:
85 * 85 *
86 * var jsArray = new JsObject.jsify([1, 2, 3]); 86 * var jsArray = new JsObject.jsify([1, 2, 3]);
87 */ 87 */
88 library dart.js; 88 library dart.js;
89 89
90 import 'dart:async' show Zone;
90 import 'dart:collection' show ListMixin; 91 import 'dart:collection' show ListMixin;
91 import 'dart:nativewrappers'; 92 import 'dart:nativewrappers';
92 93
93 JsObject _cachedContext; 94 JsObject _cachedContext;
94 95
95 JsObject get _context native "Js_context_Callback"; 96 JsObject get _context native "Js_context_Callback";
96 97
97 JsObject get context { 98 JsObject get context {
98 if (_cachedContext == null) { 99 if (_cachedContext == null) {
99 _cachedContext = _context; 100 _cachedContext = _context;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 var args = [start, length]..addAll(iterable.skip(skipCount).take(length)); 354 var args = [start, length]..addAll(iterable.skip(skipCount).take(length));
354 callMethod('splice', args); 355 callMethod('splice', args);
355 } 356 }
356 357
357 void sort([int compare(E a, E b)]) { 358 void sort([int compare(E a, E b)]) {
358 callMethod('sort', [compare]); 359 callMethod('sort', [compare]);
359 } 360 }
360 } 361 }
361 362
362 /** 363 /**
364 * This function performs any wrapping of a Dart value before Dartium proxies
365 * it to JS.
366 */
367 _wrapToJs(value) => value is Function ? _applyZoned(value) : value;
368
369 _applyZoned(f) {
370 var call = (List arguments) => Function.apply(f, arguments);
371 if (Zone.current == Zone.ROOT) return call;
372 return Zone.current.bindUnaryCallback(call);
373 }
374
375 /**
363 * Placeholder object for cases where we need to determine exactly how many 376 * Placeholder object for cases where we need to determine exactly how many
364 * args were passed to a function. 377 * args were passed to a function.
365 */ 378 */
366 const _UNDEFINED = const Object(); 379 const _UNDEFINED = const Object();
367 380
368 // FIXME(jacobr): this method is a hack to work around the lack of proper dart 381 // FIXME(jacobr): this method is a hack to work around the lack of proper dart
369 // support for varargs methods. 382 // support for varargs methods.
370 List _stripUndefinedArgs(List args) => 383 List _stripUndefinedArgs(List args) =>
371 args.takeWhile((i) => i != _UNDEFINED).toList(); 384 args.takeWhile((i) => i != _UNDEFINED).toList();
372 385
373 /** 386 /**
374 * Returns a method that can be called with an arbitrary number (for n less 387 * Returns a method that can be called with an arbitrary number (for n less
375 * than 11) of arguments without violating Dart type checks. 388 * than 11) of arguments without violating Dart type checks.
376 */ 389 */
377 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) => 390 Function _wrapAsDebuggerVarArgsFunction(JsFunction jsFunction) =>
378 ([a1=_UNDEFINED, a2=_UNDEFINED, a3=_UNDEFINED, a4=_UNDEFINED, 391 ([a1=_UNDEFINED, a2=_UNDEFINED, a3=_UNDEFINED, a4=_UNDEFINED,
379 a5=_UNDEFINED, a6=_UNDEFINED, a7=_UNDEFINED, a8=_UNDEFINED, 392 a5=_UNDEFINED, a6=_UNDEFINED, a7=_UNDEFINED, a8=_UNDEFINED,
380 a9=_UNDEFINED, a10=_UNDEFINED]) => 393 a9=_UNDEFINED, a10=_UNDEFINED]) =>
381 jsFunction._applyDebuggerOnly(_stripUndefinedArgs( 394 jsFunction._applyDebuggerOnly(_stripUndefinedArgs(
382 [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10])); 395 [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]));
OLDNEW
« no previous file with comments | « sdk/lib/js/dart2js/js_dart2js.dart ('k') | tests/html/js_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698