本文介绍了构建Chrome扩展程序时,Dartium和dart2js之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我运行 dart2js 编译版本的chrome扩展时遇到以下问题: Uncaught TypeError:Object#< JsObject>没有方法'其中$ 1' 我创建了一个最小示例: 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); } 在Chromium(Da​​rtium)上运行时: main():... testJsList():jsList = [aaa,bbb] testJsList ():['aaa','bbb'] = [aaa,bbb] bbb 在Chrome上运行时(dart2js - > V8): main 。 testJsList():jsList = aaa,bbb testJsList():['aaa','bbb'] = [aaa,bbb] Uncaught TypeError:Object#< JsObject>没有方法'where $ 1' 显然,Dart VM正在处理JS Interop与编译的javascript略有不同。 jsList 以不同的方式打印,第二种情况是jsList的错误类型。 更新: 看起来这个问题是由三方组件{dart:js,dart2js,chrome API}引起的,因为adhoc创建的JsObject在两个Dartium和dart2js场景。解决方案 Dartium和dart2js都有自己单独的dart:js实现,行为相同。在这种情况下,它看起来像dart2js实现中的一个错误,因为 JsObject.jsify 应该返回一个 JsArray 实现 List ,但是错误说明它返回一个简单的 JsObject 。 您可以在dartbug.com提交错误吗? 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.dartimport 'dart:js';void main() { print("main()..."); context['js_list'] = new JsObject.jsify(["aaa", "bbb"]);}popup.dartimport '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]bbbWhen running on Chrome (dart2js -> V8):main():...testJsList(): jsList = aaa,bbbtestJsList(): ['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. 解决方案 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 ? 这篇关于构建Chrome扩展程序时,Dartium和dart2js之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 18:33