-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Moving from @staticInterop type to interop extension type leads to an extra apply
call
#54862
Comments
Is this only because we're using nodes from |
That's a good question - I can't quite get the equivalent code, but this is good enough: import 'dart:js_interop';
@JS()
external Window get window;
@JS()
@staticInterop
class Window {}
extension WindowExtension on Window {
external Node get document;
}
@JS()
@staticInterop
class Node {}
extension NodeExtension on Node {
external Node removeChild(Node child);
external Node? get parentNode;
external Node get firstChild;
}
/*
extension type Window._(JSObject _) {
external Node get document;
}
@JS()
extension type Node._(JSObject _) {
external Node removeChild(Node child);
external Node? get parentNode;
external Node get firstChild;
}
*/
void main() {
final node = window.document.firstChild;
node.parentNode?.removeChild(node);
} With main() {
var t1 = type$.JavaScriptObject,
node = t1._as(t1._as(t1._as(self.window).document).firstChild),
t2 = type$.nullable_JavaScriptObject._as(node.parentNode);
if (t2 != null)
t1._as(t2.removeChild(node));
}, With interop extension types: main() {
var t1 = type$.JSObject,
node = t1._as(t1._as(t1._as(self.window).document).firstChild),
t2 = type$.nullable_JSObject._as(node.parentNode);
if (t2 != null)
t1._as(t2.removeChild.apply(t2, [node]));
} So it seems like the answer is no, this is not because of |
dart:html
's window.document.nodes
leads to an extra apply
callapply
call
Interesting. A couple thoughts. By default external methods are lowed to Tweaking your example a bit: import 'dart:js_interop';
@JS()
external A get a;
@JS()
@staticInterop
class A {}
extension Ax on A {
external A m1(A? child);
}
@JS()
external B get b;
extension type B._(JSObject o) {
external B m2(B? child);
}
extension Bx on B {
external B m3(B? child);
}
main() {
a.m1(a);
b.m2(b);
b.m3(b);
} We generate the direct call to |
Compiling this:
leads to:
Replacing the
@staticInterop
definition with the interop extension type results in this:where the difference is that instead of directly calling
removeChild(node)
, we're now doing aremoveChild.apply(t1, [node])
. It isn't clear why this is the case - the only real functional difference that I can tell is that one is aJavaScriptObject
(the@staticInterop
type), while the other is aJSObject
. Erasing@staticInterop
types asJSObject
doesn't result in the longer call either, so there must be something else here.cc @leonsenft
The text was updated successfully, but these errors were encountered: