worker.moveMessagePortToContext(port, contextifiedSandbox)
-
port<MessagePort> 将要传输的消息端口。 -
contextifiedSandbox<Object>vm.createContext()方法返回的上下文隔离化的对象。 -
返回: <MessagePort>
将 MessagePort 传输到不同的 vm 上下文
原始的 port 对象将无法使用,返回的 MessagePort 实例将取而代之。
返回的 MessagePort 将是目标上下文中的对象,并将继承自其全局 Object 类。
传给 port.onmessage() 监听器的对象也将在目标上下文中创建并从其全局 Object 类继承。
但是,创建的 MessagePort 将不再继承 EventTarget,只能使用 port.onmessage() 来接收使用它的事件。
-
port<MessagePort> The message port which will be transferred. -
contextifiedSandbox<Object> A contextified object as returned by thevm.createContext()method. -
Returns: <MessagePort>
Transfer a MessagePort to a different vm Context. The original port
object will be rendered unusable, and the returned MessagePort instance will
take its place.
The returned MessagePort will be an object in the target context, and will
inherit from its global Object class. Objects passed to the
port.onmessage() listener will also be created in the target context
and inherit from its global Object class.
However, the created MessagePort will no longer inherit from
EventTarget, and only port.onmessage() can be used to receive
events using it.