Difference between Dartium and dart2js when buildi

2019-06-06 21:01发布

I have the following problem when running dart2js compiled version of my chrome extension:

Uncaught TypeError: Object #<JsObject> has no method 'where$1'

I have 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 running on Chromium (Dartium):

main():...
testJsList(): jsList = [aaa, bbb]
testJsList(): ['aaa', 'bbb'] = [aaa, bbb]
bbb

When running on Chrome (dart2js -> V8):

main():...
testJsList(): jsList = aaa,bbb
testJsList(): ['aaa', 'bbb'] = [aaa, bbb]
Uncaught TypeError: Object #<JsObject> has no method 'where$1'

Obviously Dart VM is treating JS Interop slightly differently from a compiled javascript. The jsList is printed differently, and in the second case is ´jsList´ of a "wrong" type.


Update: It looks that the problem is caused by the trio {dart:js, dart2js, chrome API} since the adhoc created JsObject is working properly in both Dartium and dart2js scenario.

1条回答
淡お忘
2楼-- · 2019-06-06 21:34

Dartium and dart2js each have their own separate implementation of dart:js, but they're supposed to behave the same. In this case it looks like a bug in the dart2js implementation, because JsObject.jsify is supposed to return a JsArray which implements List, but the error states that it's returning a plain JsObject instead.

Can you file a bug at dartbug.com ?

查看更多
登录 后发表回答