I have the following problem when running a dart2jscompiled version of the chrome extension:
Uncaught TypeError: Object
I created a minimal example:
background.dart
import 'dart:js';
void main() {
print("main()...");
context['js_list'] = new JsObject.jsify(["aaa", "bbb"]);
}
popup.dart
import 'dart:js';
var backgroundPage = context["chrome"]["extension"].callMethod("getBackgroundPage", []);
void main() {
print("main():...");
testJsList(backgroundPage['js_list']);
}
testJsList(List<String> jsList) {
print("testJsList(): jsList = $jsList");
print("testJsList(): ['aaa', 'bbb'] = ${new JsObject.jsify(['aaa', 'bbb'])}");
jsList.where((e) => e == "bbb").forEach(print);
}
When working on Chromium (Dartium):
main():...
testJsList(): jsList = [aaa, bbb]
testJsList(): ['aaa', 'bbb'] = [aaa, bbb]
bbb
When working in Chrome (dart2js → V8):
main():...
testJsList(): jsList = aaa,bbb
testJsList(): ['aaa', 'bbb'] = [aaa, bbb]
Uncaught TypeError: Object #<JsObject> has no method 'where$1'
Obviously, the Dart VM handles JS Interop in a slightly different way than compiled javascript. jsListprinted differently, and in the second - "jsList" type "wrong".
Update:
It seems that the problem is caused by the trio {dart: js, dart2js, chrome API}, since the created adhoc JsObject works correctly in both the Dartium script and dart2js.