diff options
Diffstat (limited to 'ext/websocket/01_websocket.js')
-rw-r--r-- | ext/websocket/01_websocket.js | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index dab34a023..f7dd516ff 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -1,12 +1,9 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file camelcase /// <reference path="../../core/internal.d.ts" /> const core = globalThis.Deno.core; -const { opAsync, opAsync2 } = core; -// deno-lint-ignore camelcase -const op_ws_check_permission_and_cancel_handle = - core.ops.op_ws_check_permission_and_cancel_handle; import { URL } from "ext:deno_url/00_url.js"; import * as webidl from "ext:deno_webidl/00_webidl.js"; import { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js"; @@ -51,6 +48,23 @@ const { TypedArrayPrototypeGetByteLength, TypedArrayPrototypeGetSymbolToStringTag, } = primordials; +const op_ws_check_permission_and_cancel_handle = + core.ops.op_ws_check_permission_and_cancel_handle; +const { + op_ws_create, + op_ws_close, + op_ws_send_binary, + op_ws_send_text, + op_ws_next_event, + op_ws_send_ping, +} = core.generateAsyncOpHandler( + "op_ws_create", + "op_ws_close", + "op_ws_send_binary", + "op_ws_send_text", + "op_ws_next_event", + "op_ws_send_ping", +); webidl.converters["sequence<DOMString> or DOMString"] = ( V, @@ -252,8 +266,7 @@ class WebSocket extends EventTarget { } PromisePrototypeThen( - opAsync( - "op_ws_create", + op_ws_create( "new WebSocket()", wsURL.href, ArrayPrototypeJoin(protocols, ", "), @@ -265,7 +278,7 @@ class WebSocket extends EventTarget { if (this[_readyState] === CLOSING) { PromisePrototypeThen( - opAsync("op_ws_close", this[_rid]), + op_ws_close(this[_rid]), () => { this[_readyState] = CLOSED; @@ -318,8 +331,7 @@ class WebSocket extends EventTarget { const sendTypedArray = (view, byteLength) => { this[_bufferedAmount] += byteLength; PromisePrototypeThen( - opAsync2( - "op_ws_send_binary", + op_ws_send_binary( this[_rid], view, ), @@ -353,8 +365,7 @@ class WebSocket extends EventTarget { const d = core.encode(string); this[_bufferedAmount] += TypedArrayPrototypeGetByteLength(d); PromisePrototypeThen( - opAsync2( - "op_ws_send_text", + op_ws_send_text( this[_rid], string, ), @@ -407,8 +418,7 @@ class WebSocket extends EventTarget { this[_readyState] = CLOSING; PromisePrototypeCatch( - opAsync( - "op_ws_close", + op_ws_close( this[_rid], code, reason, @@ -432,10 +442,7 @@ class WebSocket extends EventTarget { async [_eventLoop]() { while (this[_readyState] !== CLOSED) { - const { 0: kind, 1: value } = await opAsync2( - "op_ws_next_event", - this[_rid], - ); + const { 0: kind, 1: value } = await op_ws_next_event(this[_rid]); switch (kind) { case 0: { @@ -495,8 +502,7 @@ class WebSocket extends EventTarget { if (prevState === OPEN) { try { - await opAsync( - "op_ws_close", + await op_ws_close( this[_rid], code, value, @@ -524,17 +530,12 @@ class WebSocket extends EventTarget { clearTimeout(this[_idleTimeoutTimeout]); this[_idleTimeoutTimeout] = setTimeout(async () => { if (this[_readyState] === OPEN) { - await opAsync("op_ws_send_ping", this[_rid]); + await op_ws_send_ping(this[_rid]); this[_idleTimeoutTimeout] = setTimeout(async () => { if (this[_readyState] === OPEN) { this[_readyState] = CLOSING; const reason = "No response from ping frame."; - await opAsync( - "op_ws_close", - this[_rid], - 1001, - reason, - ); + await op_ws_close(this[_rid], 1001, reason); this[_readyState] = CLOSED; const errEvent = new ErrorEvent("error", { |