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