diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-05-01 17:40:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 17:40:00 +0200 |
commit | dcf391ffed3850f9026d88b146e156375c4619d4 (patch) | |
tree | 2134755e8abbecaba1d42703fe727ae701ee390c /ext/node/polyfills/internal | |
parent | 6728ad4203d731e555dabf89ec6157f113454ce6 (diff) |
refactor: migrate async ops to generated wrappers (#18937)
Migrates some of existing async ops to generated wrappers introduced in
https://github.com/denoland/deno/pull/18887. As a result "core.opAsync2"
was removed.
I will follow up with more PRs that migrate all the async ops to
generated wrappers.
Diffstat (limited to 'ext/node/polyfills/internal')
-rw-r--r-- | ext/node/polyfills/internal/crypto/random.ts | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/random.ts b/ext/node/polyfills/internal/crypto/random.ts index 32256b13b..4890e158a 100644 --- a/ext/node/polyfills/internal/crypto/random.ts +++ b/ext/node/polyfills/internal/crypto/random.ts @@ -1,6 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license. +// deno-lint-ignore-file camelcase + import { notImplemented } from "ext:deno_node/_utils.ts"; import randomBytes from "ext:deno_node/internal/crypto/_randomBytes.ts"; import randomFill, { @@ -31,6 +33,15 @@ export { default as randomInt } from "ext:deno_node/internal/crypto/_randomInt.t const { core } = globalThis.__bootstrap; const { ops } = core; +const { + op_node_gen_prime_async, + op_node_check_prime_bytes_async, + op_node_check_prime_async, +} = Deno.core.generateAsyncOpHandler( + "op_node_gen_prime_async", + "op_node_check_prime_bytes_async", + "op_node_check_prime_async", +); export type LargeNumberLike = | ArrayBufferView @@ -79,9 +90,9 @@ export function checkPrime( validateInt32(checks, "options.checks", 0); - let op = "op_node_check_prime_bytes_async"; + let op = op_node_check_prime_bytes_async; if (typeof candidate === "bigint") { - op = "op_node_check_prime_async"; + op = op_node_check_prime_async; } else if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { throw new ERR_INVALID_ARG_TYPE( "candidate", @@ -96,7 +107,7 @@ export function checkPrime( ); } - core.opAsync2(op, candidate, checks).then( + op(candidate, checks).then( (result) => { callback?.(null, result); }, @@ -160,7 +171,7 @@ export function generatePrime( const { bigint, } = validateRandomPrimeJob(size, options); - core.opAsync2("op_node_gen_prime_async", size).then((prime: Uint8Array) => + op_node_gen_prime_async(size).then((prime: Uint8Array) => bigint ? arrayBufferToUnsignedBigInt(prime.buffer) : prime.buffer ).then((prime: ArrayBuffer | bigint) => { callback?.(null, prime); |