Closed
Description
I have code that ~mostly looks like this:
@JS()
library js_interop;
import 'package:js/js.dart';
@JS('self')
external MyGlobals get myGlobals;
@JS()
@anonymous
abstract class MyGlobals {
external List<String> get names;
set names(List<String> names);
}
void main() {
var names = myGlobals.names;
if (names == null) {
names = myGlobals.names = [];
}
}
This fails, mostly mysteriously, with a NoSuchMethodError
. While debugging the Dart2JS, I realized that this is going through an Interceptor. The code that is emitted looks something like this:
J.get$names$x = function(receiver) {
return J.getInterceptor$x(receiver).get$names(receiver);
}
...
JavaScriptObject: {
get$names: function(obj) {
return obj.names;
}
}
...
main: function() {
var names;
names = J.get$names$x(self.self);
}
Questions:
- In my head, this would work perfectly fine if instead Dart2JS just emitted:
main: function() {
var names;
names = self.names;
}
... but I can't tell why it doesn't try to do that. Any pointers? I can point to my internal work.
- [Low] Is there a way to avoid reading
self.self
in this case?