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/websocket | |
parent | 382a978859a7a7a4351542be818bb2e59523429c (diff) |
Revert "refactor: update runtime code for primordial checks for "instanceof" (#13497)" (#13511)
This reverts commit 884143218fad0e18f7553aaf079d52de703f7601.
Diffstat (limited to 'ext/websocket')
-rw-r--r-- | ext/websocket/01_websocket.js | 60 | ||||
-rw-r--r-- | ext/websocket/02_websocketstream.js | 31 |
2 files changed, 40 insertions, 51 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 2c6337eef..d04d7dab3 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -10,31 +10,29 @@ const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra; const { DOMException } = window.__bootstrap.domException; const { defineEventHandler } = window.__bootstrap.event; - const { Blob, BlobPrototype } = globalThis.__bootstrap.file; + const { Blob } = globalThis.__bootstrap.file; const { - ArrayBufferPrototype, + ArrayBuffer, ArrayBufferIsView, ArrayPrototypeJoin, - ArrayPrototypeMap, - ArrayPrototypeSome, DataView, ErrorPrototypeToString, - ObjectDefineProperties, - ObjectPrototypeIsPrototypeOf, - PromisePrototypeThen, - RegExpPrototypeTest, Set, + Symbol, String, - StringPrototypeEndsWith, StringPrototypeToLowerCase, - Symbol, - SymbolIterator, + StringPrototypeEndsWith, + RegExpPrototypeTest, + ObjectDefineProperties, + ArrayPrototypeMap, + ArrayPrototypeSome, + PromisePrototypeThen, } = window.__bootstrap.primordials; webidl.converters["sequence<DOMString> or DOMString"] = (V, opts) => { // Union for (sequence<DOMString> or DOMString) if (webidl.type(V) === "Object" && V !== null) { - if (V[SymbolIterator] !== undefined) { + if (V[Symbol.iterator] !== undefined) { return webidl.converters["sequence<DOMString>"](V, opts); } } @@ -43,15 +41,12 @@ webidl.converters["WebSocketSend"] = (V, opts) => { // Union for (Blob or ArrayBufferView or ArrayBuffer or USVString) - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, V)) { + if (V instanceof Blob) { return webidl.converters["Blob"](V, opts); } if (typeof V === "object") { // TODO(littledivy): use primordial for SharedArrayBuffer - if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) - ) { + if (V instanceof ArrayBuffer || V instanceof SharedArrayBuffer) { return webidl.converters["ArrayBuffer"](V, opts); } if (ArrayBufferIsView(V)) { @@ -84,52 +79,52 @@ [_readyState] = CONNECTING; get readyState() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_readyState]; } get CONNECTING() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CONNECTING; } get OPEN() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return OPEN; } get CLOSING() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CLOSING; } get CLOSED() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return CLOSED; } [_extensions] = ""; get extensions() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_extensions]; } [_protocol] = ""; get protocol() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_protocol]; } [_url] = ""; get url() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_url]; } [_binaryType] = "blob"; get binaryType() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_binaryType]; } set binaryType(value) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); value = webidl.converters.DOMString(value, { prefix: "Failed to set 'binaryType' on 'WebSocket'", }); @@ -140,7 +135,7 @@ [_bufferedAmount] = 0; get bufferedAmount() { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); return this[_bufferedAmount]; } @@ -272,7 +267,7 @@ } send(data) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); const prefix = "Failed to execute 'send' on 'WebSocket'"; webidl.requiredArguments(arguments.length, 1, { @@ -300,14 +295,14 @@ ); }; - if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) { + if (data instanceof Blob) { PromisePrototypeThen( data.slice().arrayBuffer(), (ab) => sendTypedArray(new DataView(ab)), ); } else if (ArrayBufferIsView(data)) { sendTypedArray(data); - } else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) { + } else if (data instanceof ArrayBuffer) { sendTypedArray(new DataView(data)); } else { const string = String(data); @@ -326,7 +321,7 @@ } close(code = undefined, reason = undefined) { - webidl.assertBranded(this, WebSocketPrototype); + webidl.assertBranded(this, WebSocket); const prefix = "Failed to execute 'close' on 'WebSocket'"; if (code !== undefined) { @@ -519,7 +514,6 @@ defineEventHandler(WebSocket.prototype, "open"); webidl.configurePrototype(WebSocket); - const WebSocketPrototype = WebSocket.prototype; window.__bootstrap.webSocket = { WebSocket, diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index 0f4cecaa5..0a14657e9 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -11,19 +11,18 @@ const { add, remove } = window.__bootstrap.abortSignal; const { - ArrayPrototypeJoin, - ArrayPrototypeMap, - Error, - ObjectPrototypeIsPrototypeOf, - PromisePrototypeCatch, - PromisePrototypeThen, - Set, StringPrototypeEndsWith, StringPrototypeToLowerCase, Symbol, SymbolFor, + Set, + ArrayPrototypeMap, + ArrayPrototypeJoin, + PromisePrototypeThen, + PromisePrototypeCatch, + Uint8Array, TypeError, - Uint8ArrayPrototype, + Error, } = window.__bootstrap.primordials; webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter( @@ -71,7 +70,7 @@ [_url]; get url() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_url]; } @@ -196,9 +195,7 @@ kind: "text", value: chunk, }); - } else if ( - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, chunk) - ) { + } else if (chunk instanceof Uint8Array) { await core.opAsync("op_ws_send", this[_rid], { kind: "binary", value: chunk, @@ -299,7 +296,7 @@ } }, (err) => { - if (ObjectPrototypeIsPrototypeOf(core.InterruptedPrototype, err)) { + if (err instanceof core.Interrupted) { // The signal was aborted. err = options.signal.reason; } else { @@ -314,19 +311,19 @@ [_connection] = new Deferred(); get connection() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_connection].promise; } [_earlyClose] = false; [_closed] = new Deferred(); get closed() { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); return this[_closed].promise; } close(closeInfo) { - webidl.assertBranded(this, WebSocketStreamPrototype); + webidl.assertBranded(this, WebSocketStream); closeInfo = webidl.converters.WebSocketCloseInfo(closeInfo, { prefix: "Failed to execute 'close' on 'WebSocketStream'", context: "Argument 1", @@ -384,7 +381,5 @@ } } - const WebSocketStreamPrototype = WebSocketStream.prototype; - window.__bootstrap.webSocket.WebSocketStream = WebSocketStream; })(this); |