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

Side by Side Diff: tool/input_sdk/lib/js/dart2js/js_dart2js.dart

Issue 2106613002: Change allowInterop to a generic method. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 /// using the package:js Dart-JavaScript interop. 524 /// using the package:js Dart-JavaScript interop.
525 /// 525 ///
526 /// For performance reasons in Dart2Js, by default Dart functions cannot be 526 /// For performance reasons in Dart2Js, by default Dart functions cannot be
527 /// passed directly to JavaScript unless this method is called to create 527 /// passed directly to JavaScript unless this method is called to create
528 /// a Function compatible with both Dart and JavaScript. 528 /// a Function compatible with both Dart and JavaScript.
529 /// Calling this method repeatedly on a function will return the same function. 529 /// Calling this method repeatedly on a function will return the same function.
530 /// The [Function] returned by this method can be used from both Dart and 530 /// The [Function] returned by this method can be used from both Dart and
531 /// JavaScript. We may remove the need to call this method completely in the 531 /// JavaScript. We may remove the need to call this method completely in the
532 /// future if Dart2Js is refactored so that its function calling conventions 532 /// future if Dart2Js is refactored so that its function calling conventions
533 /// are more compatible with JavaScript. 533 /// are more compatible with JavaScript.
534 Function allowInterop(Function f) => f; 534 Function /*=F*/ allowInterop/*<F extends Function>*/(Function /*=F*/ f) => f;
535 535
536 Expando<Function> _interopCaptureThisExpando = new Expando<Function>(); 536 Expando<Function> _interopCaptureThisExpando = new Expando<Function>();
537 537
538 /// Returns a [Function] that when called from JavaScript captures its 'this' 538 /// Returns a [Function] that when called from JavaScript captures its 'this'
539 /// binding and calls [f] with the value of this passed as the first argument. 539 /// binding and calls [f] with the value of this passed as the first argument.
540 /// When called from Dart, [null] will be passed as the first argument. 540 /// When called from Dart, [null] will be passed as the first argument.
541 /// 541 ///
542 /// See the documention for [allowInterop]. This method should only be used with 542 /// See the documention for [allowInterop]. This method should only be used with
543 /// package:js Dart-JavaScript interop. 543 /// package:js Dart-JavaScript interop.
544 Function allowInteropCaptureThis(Function f) { 544 Function allowInteropCaptureThis(Function f) {
545 var ret = _interopCaptureThisExpando[f]; 545 var ret = _interopCaptureThisExpando[f];
546 if (ret == null) { 546 if (ret == null) {
547 ret = JS('', 547 ret = JS('',
548 'function(/*...arguments*/) {' 548 'function(/*...arguments*/) {'
549 ' let args = [this];' 549 ' let args = [this];'
550 ' for (let arg of arguments) {' 550 ' for (let arg of arguments) {'
551 ' args.push(arg);' 551 ' args.push(arg);'
552 ' }' 552 ' }'
553 ' return #(...args);' 553 ' return #(...args);'
554 '}', 554 '}',
555 f); 555 f);
556 _interopCaptureThisExpando[f] = ret; 556 _interopCaptureThisExpando[f] = ret;
557 } 557 }
558 return ret; 558 return ret;
559 } 559 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698