worker_threads.moveMessagePortToContext(port, contextifiedSandbox)
port<MessagePort> 要传输的消息端口。contextifiedSandbox<Object> 一个 情境化 对象,由vm.createContext()方法返回。- 返回:<MessagePort>
将 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.】