mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: update runtime code for primordial checks for "instanceof" (#13497)
This commit is contained in:
parent
dcf8f144ab
commit
884143218f
41 changed files with 1030 additions and 660 deletions
|
@ -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,
|
||||
DataView,
|
||||
ErrorPrototypeToString,
|
||||
Set,
|
||||
Symbol,
|
||||
String,
|
||||
StringPrototypeToLowerCase,
|
||||
StringPrototypeEndsWith,
|
||||
RegExpPrototypeTest,
|
||||
ObjectDefineProperties,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypeSome,
|
||||
DataView,
|
||||
ErrorPrototypeToString,
|
||||
ObjectDefineProperties,
|
||||
ObjectPrototypeIsPrototypeOf,
|
||||
PromisePrototypeThen,
|
||||
RegExpPrototypeTest,
|
||||
Set,
|
||||
String,
|
||||
StringPrototypeEndsWith,
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue