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);