worker.moveMessagePortToContext(port, contextifiedSandbox)


MessagePort 传输到不同的 vm 上下文原始的 port 对象变得不可用,返回的 MessagePort 实例取而代之。

¥Transfer a MessagePort to a different vm Context. The original port object is rendered unusable, and the returned MessagePort instance takes its place.

返回的 MessagePort 是目标上下文中的对象,并且继承自其全局的 Object 类。传给 port.onmessage() 监听器的对象也在目标上下文中创建并且从其全局的 Object 类继承。

¥The returned MessagePort is an object in the target context and inherits from its global Object class. Objects passed to the port.onmessage() listener are also created in the target context and inherit from its global Object class.

但是,创建的 MessagePort 不再继承 <EventTarget>,只有 port.onmessage() 可以使用它来接收事件。

¥However, the created MessagePort no longer inherits from <EventTarget>, and only port.onmessage() can be used to receive events using it.