Skip to content

properly retain closures used via js-interop #25720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sigmundch opened this issue Feb 8, 2016 · 1 comment
Closed

properly retain closures used via js-interop #25720

sigmundch opened this issue Feb 8, 2016 · 1 comment

Comments

@sigmundch
Copy link
Member

We seem to have a bug in CPS IR related to passing closures through js-interop. It might be that we don't mark a closure as escaped when we pass it to a js-interop API, or that we don't recognize that all closures could be invoked via JsObject.callMethod.

This only happens if the closure signature is not seen anywhere else in the Dart code. For example, the closure in the repro below is the only closure with 11 arguments. If we change it to take 4 or less arguments, then the closure is available and the program runs correctly.

Here is simplified repro, derived from the test in tests/html/js_test/Dart_functions:

import 'dart:js';

main() {
  context['f'] =
    (a, b, c, d, e, f, g, h, i, j) => print('$a $b $c $d $e $f $g $h $i $j');
  context.callMethod('f',
      ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']);
}

This prints A B C D E F G H I J when compiled with SSA, but throws the following error with CPS IR:

Receiver: Closure 'main_closure'
Arguments: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
          throw e;
          ^
NoSuchMethodError: method not found: 'call'
Receiver: Closure 'main_closure'
Arguments: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
    at dart.wrapException (cps.js:1847:18)
    at main_closure.dart.Object.noSuchMethod$1 (cps.js:4196:17)
    at J.noSuchMethod$1$ (cps.js:5210:39)
    at dart.Primitives_functionNoSuchMethod (cps.js:1785:9)
    at dart.Primitives_applyFunctionWithPositionalArguments (cps.js:1808:20)
    at dart._callDartFunction (cps.js:4650:31)
    at cps.js:4632:18
    at JsObject.dart.JsObject.callMethod$2 (cps.js:4769:44)
    at dart.main (cps.js:5051:10)
    at _IsolateContext.dart._IsolateContext.eval$1 (cps.js:1054:27)

Inspecting the output shows that the CPS IR has tree-shaken the call method of the closure.

@rakudrama
Copy link
Member

Obsolete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants