dart-lang/js-interop — pull request #83 by a14n (2013-06-03 14:45:42+00:00)
Title: support for retaining FunctionProxy

It appears that retaining a FunctionProxy instance is not supported. It is important in order to receive, retain, and later execute, callbacks from Javascript.

e.g. The dart code for a proxy that is called from javascript has a callback as an argument may look like this:

void callBackToDartCode(String query, js.FunctionProxy completionCallback) {
js.retain(completionCallback); /// THROWS "illegal type: funcref"
doSomethingAsync(query).then(
(result) {
// pass the query result back to the javascript code
completionCallback(js.map(result));
// completionCallback is no longer used
js.release(completionCallback);
});
}

The call to js.retain(completionCallback) will throw an exception "Illegal type: funcref".

Note that the following work around exists, but is an inelegant solution:

void callBackToDartCode(String query, js.FunctionProxy completionCallback) {
js.context.completionCallback = completionCallback;
doSomethingAsync(query).then(
(result) {
// pass the query result back to the javascript code
js.context.completionCallback(js.map(result));
});
}