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
// 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";
const { core } = globalThis.__bootstrap;
const { ops } = core;
function assert(cond: boolean) {
if (!cond) throw new Error("Assertion failed");
}
@ -57,7 +58,7 @@ function setPromiseHooks() {
};
const after = (promise: Promise<unknown>) => {
popAsyncFrame();
if (!ops.op_node_is_promise_rejected(promise)) {
if (!op_node_is_promise_rejected(promise)) {
// @ts-ignore promise async context
promise[asyncContext] = undefined;
}
@ -65,7 +66,7 @@ function setPromiseHooks() {
const resolve = (promise: Promise<unknown>) => {
const currentFrame = AsyncContextFrame.current();
if (
!currentFrame.isRoot() && ops.op_node_is_promise_rejected(promise) &&
!currentFrame.isRoot() && op_node_is_promise_rejected(promise) &&
typeof promise[asyncContext] === "undefined"
) {
AsyncContextFrame.attachContext(promise);

View File

@ -7,18 +7,11 @@
/// <reference path="./lib.deno_web.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const { InterruptedPrototype, ops } = core;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
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";
const {
op_message_port_post_message,
op_message_port_recv_message,
op_message_port_create_entangled,
} = core.ensureFastOps();
const {
ArrayBufferPrototypeGetByteLength,
ArrayPrototypeFilter,
@ -31,11 +24,20 @@ const {
TypeError,
} = primordials;
const {
InterruptedPrototype,
isArrayBuffer,
} = core;
const {
op_message_port_recv_message,
} = core.ensureFastOps();
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
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 {
/** @type {MessagePort} */
@ -140,7 +142,7 @@ class MessagePort extends EventTarget {
}
const data = serializeJsMessageData(message, transfer);
if (this[_id] === null) return;
ops.op_message_port_post_message(this[_id], data);
op_message_port_post_message(this[_id], data);
}
start() {
@ -220,7 +222,7 @@ const MessagePortPrototype = MessagePort.prototype;
* @returns {[number, number]}
*/
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.
import { core, primordials } from "ext:core/mod.js";
const {
op_read_line_prompt,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
StringPrototypeCharCodeAt,
@ -9,8 +12,6 @@ const {
import { isatty } from "ext:runtime/40_tty.js";
import { stdin } from "ext:deno_io/12_io.js";
const ops = core.ops;
const LF = StringPrototypeCharCodeAt("\n", 0);
const CR = StringPrototypeCharCodeAt("\r", 0);
@ -43,7 +44,7 @@ function prompt(message = "Prompt", defaultValue) {
return null;
}
return ops.op_read_line_prompt(
return op_read_line_prompt(
`${message} `,
`${defaultValue}`,
);