diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-01-27 16:27:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 16:27:22 +0100 |
commit | f248e6f1778dc26db91d3322de2ecca5d1aa9866 (patch) | |
tree | 46b1ff59091cc8d31ff67427173d3a0148734007 /ext/web/13_message_port.js | |
parent | 382a978859a7a7a4351542be818bb2e59523429c (diff) |
Revert "refactor: update runtime code for primordial checks for "instanceof" (#13497)" (#13511)
This reverts commit 884143218fad0e18f7553aaf079d52de703f7601.
Diffstat (limited to 'ext/web/13_message_port.js')
-rw-r--r-- | ext/web/13_message_port.js | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index 8242f85f3..ef332dd7a 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -10,21 +10,19 @@ ((window) => { const core = window.Deno.core; - const { InterruptedPrototype } = core; + const { Interrupted } = core; const webidl = window.__bootstrap.webidl; const { setEventTargetData } = window.__bootstrap.eventTarget; const { defineEventHandler } = window.__bootstrap.event; const { DOMException } = window.__bootstrap.domException; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayPrototypeFilter, ArrayPrototypeIncludes, ArrayPrototypePush, - ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, Symbol, SymbolFor, - SymbolIterator, TypeError, WeakSet, WeakSetPrototypeAdd, @@ -47,12 +45,12 @@ } get port1() { - webidl.assertBranded(this, MessageChannelPrototype); + webidl.assertBranded(this, MessageChannel); return this.#port1; } get port2() { - webidl.assertBranded(this, MessageChannelPrototype); + webidl.assertBranded(this, MessageChannel); return this.#port2; } @@ -64,7 +62,6 @@ } webidl.configurePrototype(MessageChannel); - const MessageChannelPrototype = MessageChannel.prototype; const _id = Symbol("id"); const _enabled = Symbol("enabled"); @@ -75,7 +72,7 @@ */ function createMessagePort(id) { const port = core.createHostObject(); - ObjectSetPrototypeOf(port, MessagePortPrototype); + ObjectSetPrototypeOf(port, MessagePort.prototype); port[webidl.brand] = webidl.brand; setEventTargetData(port); port[_id] = id; @@ -98,7 +95,7 @@ * @param {object[] | StructuredSerializeOptions} transferOrOptions */ postMessage(message, transferOrOptions = {}) { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); const prefix = "Failed to execute 'postMessage' on 'MessagePort'"; webidl.requiredArguments(arguments.length, 1, { prefix }); message = webidl.converters.any(message); @@ -106,7 +103,7 @@ if ( webidl.type(transferOrOptions) === "Object" && transferOrOptions !== undefined && - transferOrOptions[SymbolIterator] !== undefined + transferOrOptions[Symbol.iterator] !== undefined ) { const transfer = webidl.converters["sequence<object>"]( transferOrOptions, @@ -132,7 +129,7 @@ } start() { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); if (this[_enabled]) return; (async () => { this[_enabled] = true; @@ -145,7 +142,7 @@ this[_id], ); } catch (err) { - if (ObjectPrototypeIsPrototypeOf(InterruptedPrototype, err)) break; + if (err instanceof Interrupted) break; throw err; } if (data === null) break; @@ -163,7 +160,7 @@ data: message, ports: ArrayPrototypeFilter( transferables, - (t) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, t), + (t) => t instanceof MessagePort, ), }); this.dispatchEvent(event); @@ -173,7 +170,7 @@ } close() { - webidl.assertBranded(this, MessagePortPrototype); + webidl.assertBranded(this, MessagePort); if (this[_id] !== null) { core.close(this[_id]); this[_id] = null; @@ -187,7 +184,6 @@ defineEventHandler(MessagePort.prototype, "messageerror"); webidl.configurePrototype(MessagePort); - const MessagePortPrototype = MessagePort.prototype; /** * @returns {[number, number]} @@ -249,7 +245,7 @@ function serializeJsMessageData(data, transferables) { const transferedArrayBuffers = ArrayPrototypeFilter( transferables, - (a) => ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, a), + (a) => a instanceof ArrayBuffer, ); for (const arrayBuffer of transferedArrayBuffers) { @@ -270,7 +266,7 @@ serializedData = core.serialize(data, { hostObjects: ArrayPrototypeFilter( transferables, - (a) => ObjectPrototypeIsPrototypeOf(MessagePortPrototype, a), + (a) => a instanceof MessagePort, ), transferedArrayBuffers, }); @@ -283,8 +279,8 @@ let arrayBufferI = 0; for (const transferable of transferables) { - if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) { - webidl.assertBranded(transferable, MessagePortPrototype); + if (transferable instanceof MessagePort) { + webidl.assertBranded(transferable, MessagePort); const id = transferable[_id]; if (id === null) { throw new DOMException( @@ -297,9 +293,7 @@ kind: "messagePort", data: id, }); - } else if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, transferable) - ) { + } else if (transferable instanceof ArrayBuffer) { ArrayPrototypePush(serializedTransferables, { kind: "arrayBuffer", data: transferedArrayBuffers[arrayBufferI], @@ -345,7 +339,6 @@ window.__bootstrap.messagePort = { MessageChannel, MessagePort, - MessagePortPrototype, deserializeJsMessageData, serializeJsMessageData, structuredClone, |