Dart:在隔离中使用 JsObject 和 window API

Dart: Using JsObject and window API in an isolate

我在 Dart 中使用 isolate 时遇到了一些困难。第一个问题是我想使用 dart:js 在我的一个 isolate 中使用 javascript 库。我尝试使用以下代码:

void runCode(SendPort sendPort)
{
    print("still ok...");
    JsObject object = new JsObject(context['jsCode']);
    print("still ok?");
}

void main()
{
    ReceivePort receivePort = new ReceivePort();
    JsObject object = new JsObject(context['jsCode']);
    print("ok so far");
    Isolate.spawn(runCode, receivePort.sendPort);
}

代码在 runCode 函数中运行到 "still ok...",当我尝试使用 JsObject 时中断。

第二个问题是我想在 isolate 中使用文件系统 API。所以我尝试了以下方法:

void runCode(SendPort sendPort)
{
    window.requestFileSystem.then((FileSystem filesytem) => print('ok'));
}

void main()
{
    ReceivePort receivePort = new ReceivePort();
    Isolate.spawn(runCode, receivePort.sendPort);
}

第二个示例在我到达文件系统时中断。

我已阅读:Dart : Isolate not working when using html import 并且从这里它表明 dart:html 不能在隔离中使用。这就是文件系统 API 无法工作的原因吗? dart:js也是这样吗?还是我完全错过了什么?

感谢您的帮助!

我在某处读到只有主线程可以访问 DOM,如果不在主线程中,这将导致任何其他 JS 操作失败。