| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0408966 commit 24debc9
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,9 @@ const { | |||
| 6 | 6 | } = internalBinding('symbols'); | |
| 7 | 7 | const { | |
| 8 | 8 | MessagePort, | |
| 9 | - MessageChannel | ||
| 9 | + MessageChannel, | ||
| 10 | + drainMessagePort, | ||
| 11 | + stopMessagePort | ||
| 10 | 12 | } = internalBinding('messaging'); | |
| 11 | 13 | const { threadId } = internalBinding('worker'); | |
| 12 | 14 | ||
@@ -33,13 +35,6 @@ const messageTypes = { | |||
| 33 | 35 | LOAD_SCRIPT: 'loadScript' | |
| 34 | 36 | }; | |
| 35 | 37 | ||
| 36 | - // Original drain from C++ | ||
| 37 | - const originalDrain = MessagePort.prototype.drain; | ||
| 38 | - | ||
| 39 | - function drainMessagePort(port) { | ||
| 40 | - return originalDrain.call(port); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | 38 | // We have to mess with the MessagePort prototype a bit, so that a) we can make | |
| 44 | 39 | // it inherit from EventEmitter, even though it is a C++ class, and b) we do | |
| 45 | 40 | // not provide methods that are not present in the Browser and not documented | |
@@ -51,9 +46,8 @@ const MessagePortPrototype = Object.create( | |||
| 51 | 46 | // Set up the new inheritance chain. | |
| 52 | 47 | Object.setPrototypeOf(MessagePort, EventEmitter); | |
| 53 | 48 | Object.setPrototypeOf(MessagePort.prototype, EventEmitter.prototype); | |
| 54 | - // Finally, purge methods we don't want to be public. | ||
| 55 | - delete MessagePort.prototype.stop; | ||
| 56 | - delete MessagePort.prototype.drain; | ||
| 49 | + // Copy methods that are inherited from HandleWrap, because | ||
| 50 | + // changing the prototype of MessagePort.prototype implicitly removed them. | ||
| 57 | 51 | MessagePort.prototype.ref = MessagePortPrototype.ref; | |
| 58 | 52 | MessagePort.prototype.unref = MessagePortPrototype.unref; | |
| 59 | 53 | ||
@@ -84,7 +78,7 @@ Object.defineProperty(MessagePort.prototype, 'onmessage', { | |||
| 84 | 78 | MessagePortPrototype.start.call(this); | |
| 85 | 79 | } else { | |
| 86 | 80 | this.unref(); | |
| 87 | - MessagePortPrototype.stop.call(this); | ||
| 81 | + stopMessagePort(this); | ||
| 88 | 82 | } | |
| 89 | 83 | } | |
| 90 | 84 | }); | |
@@ -152,7 +146,7 @@ function setupPortReferencing(port, eventEmitter, eventName) { | |||
| 152 | 146 | }); | |
| 153 | 147 | eventEmitter.on('removeListener', (name) => { | |
| 154 | 148 | if (name === eventName && eventEmitter.listenerCount(eventName) === 0) { | |
| 155 | - MessagePortPrototype.stop.call(port); | ||
| 149 | + stopMessagePort(port); | ||
| 156 | 150 | port.unref(); | |
| 157 | 151 | } | |
| 158 | 152 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -741,7 +741,8 @@ void MessagePort::Start(const FunctionCallbackInfo<Value>& args) { | |||
| 741 | 741 | void MessagePort::Stop(const FunctionCallbackInfo<Value>& args) { | |
| 742 | 742 | Environment* env = Environment::GetCurrent(args); | |
| 743 | 743 | MessagePort* port; | |
| 744 | - ASSIGN_OR_RETURN_UNWRAP(&port, args.This()); | ||
| 744 | + CHECK(args[0]->IsObject()); | ||
| 745 | + ASSIGN_OR_RETURN_UNWRAP(&port, args[0].As<Object>()); | ||
| 745 | 746 | if (!port->data_) { | |
| 746 | 747 | THROW_ERR_CLOSED_MESSAGE_PORT(env); | |
| 747 | 748 | return; | |
@@ -751,7 +752,8 @@ void MessagePort::Stop(const FunctionCallbackInfo<Value>& args) { | |||
| 751 | 752 | ||
| 752 | 753 | void MessagePort::Drain(const FunctionCallbackInfo<Value>& args) { | |
| 753 | 754 | MessagePort* port; | |
| 754 | - ASSIGN_OR_RETURN_UNWRAP(&port, args.This()); | ||
| 755 | + CHECK(args[0]->IsObject()); | ||
| 756 | + ASSIGN_OR_RETURN_UNWRAP(&port, args[0].As<Object>()); | ||
| 755 | 757 | port->OnMessage(); | |
| 756 | 758 | } | |
| 757 | 759 | ||
@@ -781,8 +783,6 @@ MaybeLocal<Function> GetMessagePortConstructor( | |||
| 781 | 783 | ||
| 782 | 784 | env->SetProtoMethod(m, "postMessage", MessagePort::PostMessage); | |
| 783 | 785 | env->SetProtoMethod(m, "start", MessagePort::Start); | |
| 784 | - env->SetProtoMethod(m, "stop", MessagePort::Stop); | ||
| 785 | - env->SetProtoMethod(m, "drain", MessagePort::Drain); | ||
| 786 | 786 | ||
| 787 | 787 | env->set_message_port_constructor_template(m); | |
| 788 | 788 | ||
@@ -848,6 +848,11 @@ static void InitMessaging(Local<Object> target, | |||
| 848 | 848 | .FromJust(); | |
| 849 | 849 | ||
| 850 | 850 | env->SetMethod(target, "registerDOMException", RegisterDOMException); | |
| 851 | + | ||
| 852 | + // These are not methods on the MessagePort prototype, because | ||
| 853 | + // the browser equivalents do not provide them. | ||
| 854 | + env->SetMethod(target, "stopMessagePort", MessagePort::Stop); | ||
| 855 | + env->SetMethod(target, "drainMessagePort", MessagePort::Drain); | ||
| 851 | 856 | } | |
| 852 | 857 | ||
| 853 | 858 | } // anonymous namespace | |
| Back | FazBrowse Home | New Git URL |
0 commit comments