refactor: port more ops to ensureFastOps() (#22046)

This commit is contained in:
Asher Gomez 2024-01-23 23:04:53 +11:00 committed by GitHub
parent 01b6e38baf
commit 6238b0a457
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 25 deletions

View file

@ -7,11 +7,12 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills // TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials // deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_is_promise_rejected,
} = core.ensureFastOps();
import { validateFunction } from "ext:deno_node/internal/validators.mjs"; import { validateFunction } from "ext:deno_node/internal/validators.mjs";
const { core } = globalThis.__bootstrap;
const { ops } = core;
function assert(cond: boolean) { function assert(cond: boolean) {
if (!cond) throw new Error("Assertion failed"); if (!cond) throw new Error("Assertion failed");
} }
@ -57,7 +58,7 @@ function setPromiseHooks() {
}; };
const after = (promise: Promise<unknown>) => { const after = (promise: Promise<unknown>) => {
popAsyncFrame(); popAsyncFrame();
if (!ops.op_node_is_promise_rejected(promise)) { if (!op_node_is_promise_rejected(promise)) {
// @ts-ignore promise async context // @ts-ignore promise async context
promise[asyncContext] = undefined; promise[asyncContext] = undefined;
} }
@ -65,7 +66,7 @@ function setPromiseHooks() {
const resolve = (promise: Promise<unknown>) => { const resolve = (promise: Promise<unknown>) => {
const currentFrame = AsyncContextFrame.current(); const currentFrame = AsyncContextFrame.current();
if ( if (
!currentFrame.isRoot() && ops.op_node_is_promise_rejected(promise) && !currentFrame.isRoot() && op_node_is_promise_rejected(promise) &&
typeof promise[asyncContext] === "undefined" typeof promise[asyncContext] === "undefined"
) { ) {
AsyncContextFrame.attachContext(promise); AsyncContextFrame.attachContext(promise);

View file

@ -7,18 +7,11 @@
/// <reference path="./lib.deno_web.d.ts" /> /// <reference path="./lib.deno_web.d.ts" />
import { core, primordials } from "ext:core/mod.js"; import { core, primordials } from "ext:core/mod.js";
const { InterruptedPrototype, ops } = core; const {
import * as webidl from "ext:deno_webidl/00_webidl.js"; op_message_port_post_message,
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; op_message_port_recv_message,
import { op_message_port_create_entangled,
defineEventHandler, } = core.ensureFastOps();
EventTarget,
MessageEvent,
setEventTargetData,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { isDetachedBuffer } from "ext:deno_web/06_streams.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const { const {
ArrayBufferPrototypeGetByteLength, ArrayBufferPrototypeGetByteLength,
ArrayPrototypeFilter, ArrayPrototypeFilter,
@ -31,11 +24,20 @@ const {
TypeError, TypeError,
} = primordials; } = primordials;
const { const {
InterruptedPrototype,
isArrayBuffer, isArrayBuffer,
} = core; } = core;
const { import * as webidl from "ext:deno_webidl/00_webidl.js";
op_message_port_recv_message, import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
} = core.ensureFastOps(); import {
defineEventHandler,
EventTarget,
MessageEvent,
setEventTargetData,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { isDetachedBuffer } from "ext:deno_web/06_streams.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
class MessageChannel { class MessageChannel {
/** @type {MessagePort} */ /** @type {MessagePort} */
@ -140,7 +142,7 @@ class MessagePort extends EventTarget {
} }
const data = serializeJsMessageData(message, transfer); const data = serializeJsMessageData(message, transfer);
if (this[_id] === null) return; if (this[_id] === null) return;
ops.op_message_port_post_message(this[_id], data); op_message_port_post_message(this[_id], data);
} }
start() { start() {
@ -220,7 +222,7 @@ const MessagePortPrototype = MessagePort.prototype;
* @returns {[number, number]} * @returns {[number, number]}
*/ */
function opCreateEntangledMessagePort() { function opCreateEntangledMessagePort() {
return ops.op_message_port_create_entangled(); return op_message_port_create_entangled();
} }
/** /**

View file

@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js"; import { core, primordials } from "ext:core/mod.js";
const {
op_read_line_prompt,
} = core.ensureFastOps();
const { const {
ArrayPrototypePush, ArrayPrototypePush,
StringPrototypeCharCodeAt, StringPrototypeCharCodeAt,
@ -9,8 +12,6 @@ const {
import { isatty } from "ext:runtime/40_tty.js"; import { isatty } from "ext:runtime/40_tty.js";
import { stdin } from "ext:deno_io/12_io.js"; import { stdin } from "ext:deno_io/12_io.js";
const ops = core.ops;
const LF = StringPrototypeCharCodeAt("\n", 0); const LF = StringPrototypeCharCodeAt("\n", 0);
const CR = StringPrototypeCharCodeAt("\r", 0); const CR = StringPrototypeCharCodeAt("\r", 0);
@ -43,7 +44,7 @@ function prompt(message = "Prompt", defaultValue) {
return null; return null;
} }
return ops.op_read_line_prompt( return op_read_line_prompt(
`${message} `, `${message} `,
`${defaultValue}`, `${defaultValue}`,
); );