1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor: use core.ensureFastOps() (#21888)

This commit is contained in:
Kenta Moriuchi 2024-01-11 07:37:25 +09:00 committed by GitHub
parent d4893eb51a
commit 515a34b4de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
107 changed files with 1653 additions and 1147 deletions

View file

@ -1,14 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file
import { core, internals, primordials } from "ext:core/mod.js";
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import { setExitHandler } from "ext:runtime/30_os.js";
import { Console } from "ext:deno_console/01_console.js";
import { serializePermissions } from "ext:runtime/10_permissions.js";
import { setTimeout } from "ext:deno_web/02_timers.js";
const {
ArrayPrototypeFilter,
ArrayPrototypeJoin,
@ -30,6 +24,11 @@ const {
TypeError,
} = primordials;
import { setExitHandler } from "ext:runtime/30_os.js";
import { Console } from "ext:deno_console/01_console.js";
import { serializePermissions } from "ext:runtime/10_permissions.js";
import { setTimeout } from "ext:deno_web/02_timers.js";
const opSanitizerDelayResolveQueue = [];
let hasSetOpSanitizerDelayMacrotask = false;
@ -158,7 +157,7 @@ let opIdHostRecvCtrl = -1;
let opNames = null;
function populateOpNames() {
opNames = core.ops.op_op_names();
opNames = ops.op_op_names();
opIdHostRecvMessage = opNames.indexOf("op_host_recv_message");
opIdHostRecvCtrl = opNames.indexOf("op_host_recv_ctrl");
}
@ -172,7 +171,7 @@ function assertOps(fn) {
/** @param desc {TestDescription | TestStepDescription} */
return async function asyncOpSanitizer(desc) {
if (opNames === null) populateOpNames();
const res = core.ops.op_test_op_sanitizer_collect(
const res = ops.op_test_op_sanitizer_collect(
desc.id,
false,
opIdHostRecvMessage,
@ -180,7 +179,7 @@ function assertOps(fn) {
);
if (res !== 0) {
await opSanitizerDelay(res === 2);
core.ops.op_test_op_sanitizer_collect(
ops.op_test_op_sanitizer_collect(
desc.id,
true,
opIdHostRecvMessage,
@ -195,7 +194,7 @@ function assertOps(fn) {
const innerResult = await fn(desc);
if (innerResult) return innerResult;
} finally {
let res = core.ops.op_test_op_sanitizer_finish(
let res = ops.op_test_op_sanitizer_finish(
desc.id,
false,
opIdHostRecvMessage,
@ -203,7 +202,7 @@ function assertOps(fn) {
);
if (res === 1 || res === 2) {
await opSanitizerDelay(res === 2);
res = core.ops.op_test_op_sanitizer_finish(
res = ops.op_test_op_sanitizer_finish(
desc.id,
true,
opIdHostRecvMessage,
@ -212,7 +211,7 @@ function assertOps(fn) {
}
postTraces = new Map(core.opCallTraces);
if (res === 3) {
report = core.ops.op_test_op_sanitizer_report(desc.id);
report = ops.op_test_op_sanitizer_report(desc.id);
}
}

View file

@ -3,20 +3,11 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import {
defineEventHandler,
EventTarget,
setIsTrusted,
setTarget,
} from "ext:deno_web/02_event.js";
import { defer } from "ext:deno_web/02_timers.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
op_broadcast_recv,
op_broadcast_send,
op_broadcast_subscribe,
op_broadcast_unsubscribe,
} = core.ensureFastOps();
const {
ArrayPrototypeIndexOf,
@ -28,6 +19,17 @@ const {
Uint8Array,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import {
defineEventHandler,
EventTarget,
setIsTrusted,
setTarget,
} from "ext:deno_web/02_event.js";
import { defer } from "ext:deno_web/02_timers.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const _name = Symbol("[[name]]");
const _closed = Symbol("[[closed]]");
@ -95,7 +97,7 @@ class BroadcastChannel extends EventTarget {
if (rid === null) {
// Create the rid immediately, otherwise there is a time window (and a
// race condition) where messages can get lost, because recv() is async.
rid = ops.op_broadcast_subscribe();
rid = op_broadcast_subscribe();
recv();
}
}
@ -136,7 +138,7 @@ class BroadcastChannel extends EventTarget {
ArrayPrototypeSplice(channels, index, 1);
if (channels.length === 0) {
ops.op_broadcast_unsubscribe(rid);
op_broadcast_unsubscribe(rid);
}
}

40
ext/cache/01_cache.js vendored
View file

@ -1,24 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
const {
ArrayPrototypePush,
ObjectPrototypeIsPrototypeOf,
StringPrototypeSplit,
StringPrototypeTrim,
Symbol,
SymbolFor,
TypeError,
} = primordials;
import {
Request,
RequestPrototype,
toInnerRequest,
} from "ext:deno_fetch/23_request.js";
import { toInnerResponse } from "ext:deno_fetch/23_response.js";
import { URLPrototype } from "ext:deno_url/00_url.js";
import { getHeader } from "ext:deno_fetch/20_headers.js";
import { readableStreamForRid } from "ext:deno_web/06_streams.js";
const {
op_cache_delete,
op_cache_match,
@ -28,6 +9,27 @@ const {
op_cache_storage_has,
op_cache_storage_open,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
ObjectPrototypeIsPrototypeOf,
StringPrototypeSplit,
StringPrototypeTrim,
Symbol,
SymbolFor,
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import {
Request,
RequestPrototype,
toInnerRequest,
} from "ext:deno_fetch/23_request.js";
import { toInnerResponse } from "ext:deno_fetch/23_response.js";
import { URLPrototype } from "ext:deno_url/00_url.js";
import { getHeader } from "ext:deno_fetch/20_headers.js";
import { readableStreamForRid } from "ext:deno_web/06_streams.js";
class CacheStorage {
constructor() {
webidl.illegalConstructor();

View file

@ -3,6 +3,36 @@
/// <reference path="../../core/internal.d.ts" />
import { core, internals, primordials } from "ext:core/mod.js";
const {
isAnyArrayBuffer,
isArgumentsObject,
isArrayBuffer,
isAsyncFunction,
isBigIntObject,
isBooleanObject,
isBoxedPrimitive,
isDataView,
isDate,
isGeneratorFunction,
isMap,
isMapIterator,
isModuleNamespaceObject,
isNativeError,
isNumberObject,
isPromise,
isRegExp,
isSet,
isSetIterator,
isStringObject,
isTypedArray,
isWeakMap,
isWeakSet,
} = core;
const {
op_get_constructor_name,
op_get_non_index_property_names,
op_preview_entries,
} = core.ensureFastOps(true);
const {
Array,
ArrayBufferPrototypeGetByteLength,
@ -30,13 +60,12 @@ const {
DatePrototypeGetTime,
DatePrototypeToISOString,
Error,
ErrorPrototype,
ErrorCaptureStackTrace,
ErrorPrototype,
ErrorPrototypeToString,
FunctionPrototypeBind,
FunctionPrototypeCall,
FunctionPrototypeToString,
NumberIsNaN,
MapPrototypeDelete,
MapPrototypeEntries,
MapPrototypeForEach,
@ -52,6 +81,7 @@ const {
MathSqrt,
Number,
NumberIsInteger,
NumberIsNaN,
NumberParseInt,
NumberPrototypeToString,
NumberPrototypeValueOf,
@ -90,8 +120,8 @@ const {
SafeSetIterator,
SafeStringIterator,
SetPrototypeAdd,
SetPrototypeHas,
SetPrototypeGetSize,
SetPrototypeHas,
SetPrototypeValues,
String,
StringPrototypeCharCodeAt,
@ -125,36 +155,6 @@ const {
TypedArrayPrototypeGetLength,
Uint8Array,
} = primordials;
const {
isAnyArrayBuffer,
isArgumentsObject,
isArrayBuffer,
isAsyncFunction,
isBigIntObject,
isBooleanObject,
isBoxedPrimitive,
isDataView,
isDate,
isGeneratorFunction,
isMap,
isMapIterator,
isModuleNamespaceObject,
isNativeError,
isNumberObject,
isPromise,
isRegExp,
isSet,
isSetIterator,
isStringObject,
isTypedArray,
isWeakSet,
isWeakMap,
} = core;
const {
op_get_non_index_property_names,
op_get_constructor_name,
op_preview_entries,
} = core.ensureFastOps(true);
let noColor = () => false;

View file

@ -1,11 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals, primordials } from "ext:core/mod.js";
const {
ArrayPrototypeJoin,
NumberPrototypeToString,
TypeError,
} = primordials;
const {
isPromise,
} = core;
@ -13,6 +8,11 @@ const {
op_cron_create,
op_cron_next,
} = core.ensureFastOps();
const {
ArrayPrototypeJoin,
NumberPrototypeToString,
TypeError,
} = primordials;
export function formatToCronSchedule(
value?: number | { exact: number | number[] } | {

View file

@ -7,20 +7,42 @@
/// <reference path="../web/lib.deno_web.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
isArrayBuffer,
isTypedArray,
isDataView,
} = core;
const {
op_crypto_base64url_decode,
op_crypto_base64url_encode,
op_crypto_decrypt,
op_crypto_derive_bits,
op_crypto_derive_bits_x25519,
op_crypto_encrypt,
op_crypto_export_key,
op_crypto_export_pkcs8_ed25519,
op_crypto_export_pkcs8_x25519,
op_crypto_export_spki_ed25519,
op_crypto_export_spki_x25519,
op_crypto_generate_ed25519_keypair,
op_crypto_generate_key,
op_crypto_generate_x25519_keypair,
op_crypto_get_random_values,
op_crypto_import_key,
op_crypto_import_pkcs8_ed25519,
op_crypto_import_pkcs8_x25519,
op_crypto_import_spki_ed25519,
op_crypto_import_spki_x25519,
op_crypto_jwk_x_ed25519,
op_crypto_random_uuid,
op_crypto_sign_ed25519,
op_crypto_sign_key,
op_crypto_subtle_digest,
op_crypto_unwrap_key,
op_crypto_verify_ed25519,
op_crypto_verify_key,
op_crypto_wrap_key,
} = core.ensureFastOps();
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
ArrayBufferIsView,
ArrayBufferPrototypeGetByteLength,
@ -57,11 +79,10 @@ const {
WeakMapPrototypeGet,
WeakMapPrototypeSet,
} = primordials;
const {
isArrayBuffer,
isTypedArray,
isDataView,
} = core;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const supportedNamedCurves = ["P-256", "P-384", "P-521"];
const recognisedUsages = [
@ -897,7 +918,7 @@ class SubtleCrypto {
// https://briansmith.org/rustdoc/src/ring/ec/curve25519/ed25519/signing.rs.html#260
const SIGNATURE_LEN = 32 * 2; // ELEM_LEN + SCALAR_LEN
const signature = new Uint8Array(SIGNATURE_LEN);
if (!ops.op_crypto_sign_ed25519(keyData, data, signature)) {
if (!op_crypto_sign_ed25519(keyData, data, signature)) {
throw new DOMException(
"Failed to sign",
"OperationError",
@ -1371,7 +1392,7 @@ class SubtleCrypto {
);
}
return ops.op_crypto_verify_ed25519(keyData, data, signature);
return op_crypto_verify_ed25519(keyData, data, signature);
}
}
@ -1461,7 +1482,7 @@ class SubtleCrypto {
switch (normalizedAlgorithm.name) {
case "AES-KW": {
const cipherText = await ops.op_crypto_wrap_key({
const cipherText = await op_crypto_wrap_key({
key: keyData,
algorithm: normalizedAlgorithm.name,
}, bytes);
@ -1593,7 +1614,7 @@ class SubtleCrypto {
switch (normalizedAlgorithm.name) {
case "AES-KW": {
const plainText = await ops.op_crypto_unwrap_key({
const plainText = await op_crypto_unwrap_key({
key: keyData,
algorithm: normalizedAlgorithm.name,
}, wrappedKey);
@ -2007,7 +2028,7 @@ async function generateKey(normalizedAlgorithm, extractable, usages) {
}
const privateKeyData = new Uint8Array(32);
const publicKeyData = new Uint8Array(32);
ops.op_crypto_generate_x25519_keypair(privateKeyData, publicKeyData);
op_crypto_generate_x25519_keypair(privateKeyData, publicKeyData);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, privateKeyData);
@ -2052,7 +2073,7 @@ async function generateKey(normalizedAlgorithm, extractable, usages) {
const privateKeyData = new Uint8Array(ED25519_SEED_LEN);
const publicKeyData = new Uint8Array(ED25519_PUBLIC_KEY_LEN);
if (
!ops.op_crypto_generate_ed25519_keypair(privateKeyData, publicKeyData)
!op_crypto_generate_ed25519_keypair(privateKeyData, publicKeyData)
) {
throw new DOMException("Failed to generate key", "OperationError");
}
@ -2189,7 +2210,7 @@ function importKeyEd25519(
}
const publicKeyData = new Uint8Array(32);
if (!ops.op_crypto_import_spki_ed25519(keyData, publicKeyData)) {
if (!op_crypto_import_spki_ed25519(keyData, publicKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2220,7 +2241,7 @@ function importKeyEd25519(
}
const privateKeyData = new Uint8Array(32);
if (!ops.op_crypto_import_pkcs8_ed25519(keyData, privateKeyData)) {
if (!op_crypto_import_pkcs8_ed25519(keyData, privateKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2326,7 +2347,7 @@ function importKeyEd25519(
// https://www.rfc-editor.org/rfc/rfc8037#section-2
let privateKeyData;
try {
privateKeyData = ops.op_crypto_base64url_decode(jwk.d);
privateKeyData = op_crypto_base64url_decode(jwk.d);
} catch (_) {
throw new DOMException("invalid private key data", "DataError");
}
@ -2349,7 +2370,7 @@ function importKeyEd25519(
// https://www.rfc-editor.org/rfc/rfc8037#section-2
let publicKeyData;
try {
publicKeyData = ops.op_crypto_base64url_decode(jwk.x);
publicKeyData = op_crypto_base64url_decode(jwk.x);
} catch (_) {
throw new DOMException("invalid public key data", "DataError");
}
@ -2412,7 +2433,7 @@ function importKeyX25519(
}
const publicKeyData = new Uint8Array(32);
if (!ops.op_crypto_import_spki_x25519(keyData, publicKeyData)) {
if (!op_crypto_import_spki_x25519(keyData, publicKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2443,7 +2464,7 @@ function importKeyX25519(
}
const privateKeyData = new Uint8Array(32);
if (!ops.op_crypto_import_pkcs8_x25519(keyData, privateKeyData)) {
if (!op_crypto_import_pkcs8_x25519(keyData, privateKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2539,7 +2560,7 @@ function importKeyX25519(
// 9.
if (jwk.d !== undefined) {
// https://www.rfc-editor.org/rfc/rfc8037#section-2
const privateKeyData = ops.op_crypto_base64url_decode(jwk.d);
const privateKeyData = op_crypto_base64url_decode(jwk.d);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, privateKeyData);
@ -2557,7 +2578,7 @@ function importKeyX25519(
);
} else {
// https://www.rfc-editor.org/rfc/rfc8037#section-2
const publicKeyData = ops.op_crypto_base64url_decode(jwk.x);
const publicKeyData = op_crypto_base64url_decode(jwk.x);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, publicKeyData);
@ -2600,7 +2621,7 @@ function exportKeyAES(
};
// 3.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
format: "jwksecret",
algorithm: "AES",
}, innerKey);
@ -2697,7 +2718,7 @@ function importKeyAES(
}
// 4.
const { rawData } = ops.op_crypto_import_key(
const { rawData } = op_crypto_import_key(
{ algorithm: "AES" },
{ jwkSecret: jwk },
);
@ -2857,7 +2878,7 @@ function importKeyHMAC(
}
// 4.
const { rawData } = ops.op_crypto_import_key(
const { rawData } = op_crypto_import_key(
{ algorithm: "HMAC" },
{ jwkSecret: jwk },
);
@ -3042,7 +3063,7 @@ function importKeyEC(
}
// 3.
const { rawData } = ops.op_crypto_import_key({
const { rawData } = op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { raw: keyData });
@ -3083,7 +3104,7 @@ function importKeyEC(
}
// 2-9.
const { rawData } = ops.op_crypto_import_key({
const { rawData } = op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { pkcs8: keyData });
@ -3126,7 +3147,7 @@ function importKeyEC(
}
// 2-12
const { rawData } = ops.op_crypto_import_key({
const { rawData } = op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { spki: keyData });
@ -3270,7 +3291,7 @@ function importKeyEC(
if (jwk.d !== undefined) {
// it's also a Private key
const { rawData } = ops.op_crypto_import_key({
const { rawData } = op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { jwkPrivateEc: jwk });
@ -3293,7 +3314,7 @@ function importKeyEC(
return key;
} else {
const { rawData } = ops.op_crypto_import_key({
const { rawData } = op_crypto_import_key({
algorithm: normalizedAlgorithm.name,
namedCurve: normalizedAlgorithm.namedCurve,
}, { jwkPublicEc: jwk });
@ -3374,8 +3395,7 @@ function importKeyRSA(
}
// 2-9.
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
const { modulusLength, publicExponent, rawData } = op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
@ -3420,8 +3440,7 @@ function importKeyRSA(
}
// 2-9.
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
const { modulusLength, publicExponent, rawData } = op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
// Needed to perform step 7 without normalization.
@ -3670,8 +3689,7 @@ function importKeyRSA(
);
}
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
const { modulusLength, publicExponent, rawData } = op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
@ -3713,8 +3731,7 @@ function importKeyRSA(
);
}
const { modulusLength, publicExponent, rawData } = ops
.op_crypto_import_key(
const { modulusLength, publicExponent, rawData } = op_crypto_import_key(
{
algorithm: normalizedAlgorithm.name,
hash: normalizedAlgorithm.hash.name,
@ -3875,7 +3892,7 @@ function exportKeyHMAC(format, key, innerKey) {
};
// 3.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
format: "jwksecret",
algorithm: key[_algorithm].name,
}, innerKey);
@ -3929,7 +3946,7 @@ function exportKeyRSA(format, key, innerKey) {
}
// 2.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
algorithm: key[_algorithm].name,
format: "pkcs8",
}, innerKey);
@ -3947,7 +3964,7 @@ function exportKeyRSA(format, key, innerKey) {
}
// 2.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
algorithm: key[_algorithm].name,
format: "spki",
}, innerKey);
@ -4028,7 +4045,7 @@ function exportKeyRSA(format, key, innerKey) {
}
// 5-6.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
}, innerKey);
@ -4070,7 +4087,7 @@ function exportKeyEd25519(format, key, innerKey) {
);
}
const spkiDer = ops.op_crypto_export_spki_ed25519(innerKey);
const spkiDer = op_crypto_export_spki_ed25519(innerKey);
return TypedArrayPrototypeGetBuffer(spkiDer);
}
case "pkcs8": {
@ -4082,7 +4099,7 @@ function exportKeyEd25519(format, key, innerKey) {
);
}
const pkcs8Der = ops.op_crypto_export_pkcs8_ed25519(
const pkcs8Der = op_crypto_export_pkcs8_ed25519(
new Uint8Array([0x04, 0x22, ...new SafeArrayIterator(innerKey)]),
);
pkcs8Der[15] = 0x20;
@ -4090,8 +4107,8 @@ function exportKeyEd25519(format, key, innerKey) {
}
case "jwk": {
const x = key[_type] === "private"
? ops.op_crypto_jwk_x_ed25519(innerKey)
: ops.op_crypto_base64url_encode(innerKey);
? op_crypto_jwk_x_ed25519(innerKey)
: op_crypto_base64url_encode(innerKey);
const jwk = {
kty: "OKP",
crv: "Ed25519",
@ -4100,7 +4117,7 @@ function exportKeyEd25519(format, key, innerKey) {
ext: key[_extractable],
};
if (key[_type] === "private") {
jwk.d = ops.op_crypto_base64url_encode(innerKey);
jwk.d = op_crypto_base64url_encode(innerKey);
}
return jwk;
}
@ -4132,7 +4149,7 @@ function exportKeyX25519(format, key, innerKey) {
);
}
const spkiDer = ops.op_crypto_export_spki_x25519(innerKey);
const spkiDer = op_crypto_export_spki_x25519(innerKey);
return TypedArrayPrototypeGetBuffer(spkiDer);
}
case "pkcs8": {
@ -4144,7 +4161,7 @@ function exportKeyX25519(format, key, innerKey) {
);
}
const pkcs8Der = ops.op_crypto_export_pkcs8_x25519(
const pkcs8Der = op_crypto_export_pkcs8_x25519(
new Uint8Array([0x04, 0x22, ...new SafeArrayIterator(innerKey)]),
);
pkcs8Der[15] = 0x20;
@ -4154,7 +4171,7 @@ function exportKeyX25519(format, key, innerKey) {
if (key[_type] === "private") {
throw new DOMException("Not implemented", "NotSupportedError");
}
const x = ops.op_crypto_base64url_encode(innerKey);
const x = op_crypto_base64url_encode(innerKey);
const jwk = {
kty: "OKP",
crv: "X25519",
@ -4181,7 +4198,7 @@ function exportKeyEC(format, key, innerKey) {
}
// 2.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "raw",
@ -4199,7 +4216,7 @@ function exportKeyEC(format, key, innerKey) {
}
// 2.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "pkcs8",
@ -4217,7 +4234,7 @@ function exportKeyEC(format, key, innerKey) {
}
// 2.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
format: "spki",
@ -4261,7 +4278,7 @@ function exportKeyEC(format, key, innerKey) {
jwk.alg = algNamedCurve;
// 3.2 - 3.4.
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
@ -4288,7 +4305,7 @@ function exportKeyEC(format, key, innerKey) {
jwk.crv = key[_algorithm].namedCurve;
// 3.2 - 3.4
const data = ops.op_crypto_export_key({
const data = op_crypto_export_key({
format: key[_type] === "private" ? "jwkprivate" : "jwkpublic",
algorithm: key[_algorithm].name,
namedCurve: key[_algorithm].namedCurve,
@ -4490,7 +4507,7 @@ async function deriveBits(normalizedAlgorithm, baseKey, length) {
const u = WeakMapPrototypeGet(KEY_STORE, uHandle);
const secret = new Uint8Array(32);
const isIdentity = ops.op_crypto_derive_bits_x25519(k, u, secret);
const isIdentity = op_crypto_derive_bits_x25519(k, u, secret);
// 6.
if (isIdentity) {
@ -4696,7 +4713,7 @@ class Crypto {
// Fast path for Uint8Array
const tag = TypedArrayPrototypeGetSymbolToStringTag(typedArray);
if (tag === "Uint8Array") {
ops.op_crypto_get_random_values(typedArray);
op_crypto_get_random_values(typedArray);
return typedArray;
}
typedArray = webidl.converters.ArrayBufferView(
@ -4725,13 +4742,13 @@ class Crypto {
TypedArrayPrototypeGetByteOffset(typedArray),
TypedArrayPrototypeGetByteLength(typedArray),
);
ops.op_crypto_get_random_values(ui8);
op_crypto_get_random_values(ui8);
return typedArray;
}
randomUUID() {
webidl.assertBranded(this, CryptoPrototype);
return ops.op_crypto_random_uuid();
return op_crypto_random_uuid();
}
get subtle() {

View file

@ -9,16 +9,6 @@
/// <reference path="./lib.deno_fetch.d.ts" />
/// <reference lib="esnext" />
import * as webidl from "ext:deno_webidl/00_webidl.js";
import {
byteLowerCase,
collectHttpQuotedString,
collectSequenceOfCodepoints,
HTTP_TAB_OR_SPACE_PREFIX_RE,
HTTP_TAB_OR_SPACE_SUFFIX_RE,
HTTP_TOKEN_CODE_POINT_RE,
httpTrim,
} from "ext:deno_web/00_infra.js";
import { primordials } from "ext:core/mod.js";
const {
ArrayIsArray,
@ -38,6 +28,17 @@ const {
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import {
byteLowerCase,
collectHttpQuotedString,
collectSequenceOfCodepoints,
HTTP_TAB_OR_SPACE_PREFIX_RE,
HTTP_TAB_OR_SPACE_SUFFIX_RE,
HTTP_TOKEN_CODE_POINT_RE,
httpTrim,
} from "ext:deno_web/00_infra.js";
const _headerList = Symbol("header list");
const _iterableHeaders = Symbol("iterable headers");
const _iterableHeadersCache = Symbol("iterable headers cache");

View file

@ -12,6 +12,28 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const {
isAnyArrayBuffer,
isArrayBuffer,
} = core;
const {
ArrayBufferIsView,
ArrayPrototypeMap,
DataViewPrototypeGetBuffer,
DataViewPrototypeGetByteLength,
DataViewPrototypeGetByteOffset,
JSONParse,
ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetByteLength,
TypedArrayPrototypeGetByteOffset,
TypedArrayPrototypeGetSymbolToStringTag,
TypedArrayPrototypeSlice,
TypeError,
Uint8Array,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import {
parseUrlEncoded,
@ -36,27 +58,6 @@ import {
readableStreamTee,
readableStreamThrowIfErrored,
} from "ext:deno_web/06_streams.js";
const {
ArrayBufferIsView,
ArrayPrototypeMap,
DataViewPrototypeGetBuffer,
DataViewPrototypeGetByteLength,
DataViewPrototypeGetByteOffset,
JSONParse,
ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetByteLength,
TypedArrayPrototypeGetByteOffset,
TypedArrayPrototypeGetSymbolToStringTag,
TypedArrayPrototypeSlice,
TypeError,
Uint8Array,
} = primordials;
const {
isAnyArrayBuffer,
isArrayBuffer,
} = core;
/**
* @param {Uint8Array | string} chunk

View file

@ -11,8 +11,11 @@
/// <reference lib="esnext" />
import { core } from "ext:core/mod.js";
const ops = core.ops;
import { SymbolDispose } from "ext:deno_web/00_infra.js";
const {
op_fetch_custom_client,
} = core.ensureFastOps();
/**
* @param {Deno.CreateHttpClientOptions} options
@ -21,7 +24,7 @@ import { SymbolDispose } from "ext:deno_web/00_infra.js";
function createHttpClient(options) {
options.caCerts ??= [];
return new HttpClient(
ops.op_fetch_custom_client(
op_fetch_custom_client(
options,
),
);

View file

@ -9,6 +9,20 @@
/// <reference path="./lib.deno_fetch.d.ts" />
/// <reference lib="esnext" />
import { primordials } from "ext:core/mod.js";
const {
ArrayPrototypeMap,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ObjectKeys,
ObjectPrototypeIsPrototypeOf,
RegExpPrototypeExec,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { assert } from "ext:deno_web/00_infra.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
@ -30,19 +44,6 @@ import {
} from "ext:deno_fetch/20_headers.js";
import { HttpClientPrototype } from "ext:deno_fetch/22_http_client.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import { primordials } from "ext:core/mod.js";
const {
ArrayPrototypeMap,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ObjectKeys,
ObjectPrototypeIsPrototypeOf,
RegExpPrototypeExec,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
TypeError,
} = primordials;
const _request = Symbol("request");
const _headers = Symbol("headers");

View file

@ -11,10 +11,29 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_fetch,
op_fetch_send,
op_wasm_streaming_feed,
op_wasm_streaming_set_url,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
ArrayPrototypeSplice,
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
Error,
ObjectPrototypeIsPrototypeOf,
Promise,
PromisePrototypeThen,
PromisePrototypeCatch,
SafeArrayIterator,
String,
StringPrototypeStartsWith,
StringPrototypeToLowerCase,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { byteLowerCase } from "ext:deno_web/00_infra.js";
@ -36,23 +55,6 @@ import {
toInnerResponse,
} from "ext:deno_fetch/23_response.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
const {
ArrayPrototypePush,
ArrayPrototypeSplice,
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
Error,
ObjectPrototypeIsPrototypeOf,
Promise,
PromisePrototypeThen,
PromisePrototypeCatch,
SafeArrayIterator,
String,
StringPrototypeStartsWith,
StringPrototypeToLowerCase,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
} = primordials;
const REQUEST_BODY_HEADER_NAMES = [
"content-encoding",
@ -147,7 +149,7 @@ async function mainFetch(req, recursive, terminator) {
}
}
const { requestRid, cancelHandleRid } = ops.op_fetch(
const { requestRid, cancelHandleRid } = op_fetch(
req.method,
req.currentUrl(),
req.headerList,
@ -448,7 +450,7 @@ function handleWasmStreaming(source, rid) {
}
// Pass the resolved URL to v8.
ops.op_wasm_streaming_set_url(rid, res.url);
op_wasm_streaming_set_url(rid, res.url);
if (res.body !== null) {
// 2.6.
@ -460,7 +462,7 @@ function handleWasmStreaming(source, rid) {
while (true) {
const { value: chunk, done } = await reader.read();
if (done) break;
ops.op_wasm_streaming_feed(rid, chunk);
op_wasm_streaming_feed(rid, chunk);
}
})(),
// 2.7

View file

@ -3,22 +3,9 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { URL } from "ext:deno_url/00_url.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import {
defineEventHandler,
EventTarget,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { TransformStream } from "ext:deno_web/06_streams.js";
import { TextDecoderStream } from "ext:deno_web/08_text_encoding.js";
import { getLocationHref } from "ext:deno_web/12_location.js";
import { newInnerRequest } from "ext:deno_fetch/23_request.js";
import { mainFetch } from "ext:deno_fetch/26_fetch.js";
const {
op_utf8_to_byte_string,
} = core.ensureFastOps();
const {
ArrayPrototypeFind,
Number,
@ -38,6 +25,21 @@ const {
SymbolFor,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { URL } from "ext:deno_url/00_url.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import {
defineEventHandler,
EventTarget,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { TransformStream } from "ext:deno_web/06_streams.js";
import { TextDecoderStream } from "ext:deno_web/08_text_encoding.js";
import { getLocationHref } from "ext:deno_web/12_location.js";
import { newInnerRequest } from "ext:deno_fetch/23_request.js";
import { mainFetch } from "ext:deno_fetch/26_fetch.js";
// Copied from https://github.com/denoland/deno_std/blob/e0753abe0c8602552862a568348c046996709521/streams/text_line_stream.ts#L20-L74
export class TextLineStream extends TransformStream {
#allowCR;
@ -205,7 +207,7 @@ class EventSource extends EventTarget {
["accept", "text/event-stream"],
[
"Last-Event-Id",
core.ops.op_utf8_to_byte_string(lastEventIDValueCopy),
op_utf8_to_byte_string(lastEventIDValueCopy),
],
],
null,

View file

@ -1,7 +1,42 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
isArrayBuffer,
isDataView,
isTypedArray,
} = core;
const {
op_ffi_buf_copy_into,
op_ffi_call_nonblocking,
op_ffi_call_ptr,
op_ffi_call_ptr_nonblocking,
op_ffi_cstr_read,
op_ffi_get_buf,
op_ffi_get_static,
op_ffi_load,
op_ffi_ptr_create,
op_ffi_ptr_equals,
op_ffi_ptr_of,
op_ffi_ptr_of_exact,
op_ffi_ptr_offset,
op_ffi_ptr_value,
op_ffi_read_bool,
op_ffi_read_f32,
op_ffi_read_f64,
op_ffi_read_i16,
op_ffi_read_i32,
op_ffi_read_i64,
op_ffi_read_i8,
op_ffi_read_ptr,
op_ffi_read_u16,
op_ffi_read_u32,
op_ffi_read_u64,
op_ffi_read_u8,
op_ffi_unsafe_callback_close,
op_ffi_unsafe_callback_create,
op_ffi_unsafe_callback_ref,
} = core.ensureFastOps(true);
const {
ArrayBufferIsView,
ArrayBufferPrototypeGetByteLength,
@ -30,19 +65,8 @@ const {
SafeArrayIterator,
SafeWeakMap,
} = primordials;
const {
isArrayBuffer,
isDataView,
isTypedArray,
} = core;
import { pathFromURL } from "ext:deno_web/00_infra.js";
const {
op_ffi_call_nonblocking,
op_ffi_unsafe_callback_ref,
} = core.ensureFastOps();
const {
op_ffi_call_ptr_nonblocking,
} = core.ensureFastOps(true);
/**
* @param {BufferSource} source
@ -67,56 +91,56 @@ class UnsafePointerView {
}
getBool(offset = 0) {
return ops.op_ffi_read_bool(
return op_ffi_read_bool(
this.pointer,
offset,
);
}
getUint8(offset = 0) {
return ops.op_ffi_read_u8(
return op_ffi_read_u8(
this.pointer,
offset,
);
}
getInt8(offset = 0) {
return ops.op_ffi_read_i8(
return op_ffi_read_i8(
this.pointer,
offset,
);
}
getUint16(offset = 0) {
return ops.op_ffi_read_u16(
return op_ffi_read_u16(
this.pointer,
offset,
);
}
getInt16(offset = 0) {
return ops.op_ffi_read_i16(
return op_ffi_read_i16(
this.pointer,
offset,
);
}
getUint32(offset = 0) {
return ops.op_ffi_read_u32(
return op_ffi_read_u32(
this.pointer,
offset,
);
}
getInt32(offset = 0) {
return ops.op_ffi_read_i32(
return op_ffi_read_i32(
this.pointer,
offset,
);
}
getBigUint64(offset = 0) {
ops.op_ffi_read_u64(
op_ffi_read_u64(
this.pointer,
offset,
U32_BUFFER,
@ -125,7 +149,7 @@ class UnsafePointerView {
}
getBigInt64(offset = 0) {
ops.op_ffi_read_i64(
op_ffi_read_i64(
this.pointer,
offset,
U32_BUFFER,
@ -134,42 +158,42 @@ class UnsafePointerView {
}
getFloat32(offset = 0) {
return ops.op_ffi_read_f32(
return op_ffi_read_f32(
this.pointer,
offset,
);
}
getFloat64(offset = 0) {
return ops.op_ffi_read_f64(
return op_ffi_read_f64(
this.pointer,
offset,
);
}
getPointer(offset = 0) {
return ops.op_ffi_read_ptr(
return op_ffi_read_ptr(
this.pointer,
offset,
);
}
getCString(offset = 0) {
return ops.op_ffi_cstr_read(
return op_ffi_cstr_read(
this.pointer,
offset,
);
}
static getCString(pointer, offset = 0) {
return ops.op_ffi_cstr_read(
return op_ffi_cstr_read(
pointer,
offset,
);
}
getArrayBuffer(byteLength, offset = 0) {
return ops.op_ffi_get_buf(
return op_ffi_get_buf(
this.pointer,
offset,
byteLength,
@ -177,7 +201,7 @@ class UnsafePointerView {
}
static getArrayBuffer(pointer, byteLength, offset = 0) {
return ops.op_ffi_get_buf(
return op_ffi_get_buf(
pointer,
offset,
byteLength,
@ -185,7 +209,7 @@ class UnsafePointerView {
}
copyInto(destination, offset = 0) {
ops.op_ffi_buf_copy_into(
op_ffi_buf_copy_into(
this.pointer,
offset,
destination,
@ -194,7 +218,7 @@ class UnsafePointerView {
}
static copyInto(pointer, destination, offset = 0) {
ops.op_ffi_buf_copy_into(
op_ffi_buf_copy_into(
pointer,
offset,
destination,
@ -210,14 +234,14 @@ const OUT_BUFFER_64 = new BigInt64Array(
const POINTER_TO_BUFFER_WEAK_MAP = new SafeWeakMap();
class UnsafePointer {
static create(value) {
return ops.op_ffi_ptr_create(value);
return op_ffi_ptr_create(value);
}
static equals(a, b) {
if (a === null || b === null) {
return a === b;
}
return ops.op_ffi_ptr_equals(a, b);
return op_ffi_ptr_equals(a, b);
}
static of(value) {
@ -227,15 +251,15 @@ class UnsafePointer {
let pointer;
if (ArrayBufferIsView(value)) {
if (value.length === 0) {
pointer = ops.op_ffi_ptr_of_exact(value);
pointer = op_ffi_ptr_of_exact(value);
} else {
pointer = ops.op_ffi_ptr_of(value);
pointer = op_ffi_ptr_of(value);
}
} else if (isArrayBuffer(value)) {
if (value.length === 0) {
pointer = ops.op_ffi_ptr_of_exact(new Uint8Array(value));
pointer = op_ffi_ptr_of_exact(new Uint8Array(value));
} else {
pointer = ops.op_ffi_ptr_of(new Uint8Array(value));
pointer = op_ffi_ptr_of(new Uint8Array(value));
}
} else {
throw new TypeError(
@ -249,14 +273,14 @@ class UnsafePointer {
}
static offset(value, offset) {
return ops.op_ffi_ptr_offset(value, offset);
return op_ffi_ptr_offset(value, offset);
}
static value(value) {
if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) {
value = value.pointer;
}
ops.op_ffi_ptr_value(value, OUT_BUFFER);
op_ffi_ptr_value(value, OUT_BUFFER);
const result = OUT_BUFFER[0] + 2 ** 32 * OUT_BUFFER[1];
if (NumberIsSafeInteger(result)) {
return result;
@ -300,14 +324,14 @@ class UnsafeFnPointer {
}
} else {
if (this.#structSize === null) {
return ops.op_ffi_call_ptr(
return op_ffi_call_ptr(
this.pointer,
this.definition,
parameters,
);
} else {
const buffer = new Uint8Array(this.#structSize);
ops.op_ffi_call_ptr(
op_ffi_call_ptr(
this.pointer,
this.definition,
parameters,
@ -401,7 +425,7 @@ class UnsafeCallback {
"Invalid UnsafeCallback, cannot be nonblocking",
);
}
const { 0: rid, 1: pointer } = ops.op_ffi_unsafe_callback_create(
const { 0: rid, 1: pointer } = op_ffi_unsafe_callback_create(
definition,
callback,
);
@ -443,7 +467,7 @@ class UnsafeCallback {
close() {
this.#refcount = 0;
ops.op_ffi_unsafe_callback_close(this.#rid);
op_ffi_unsafe_callback_close(this.#rid);
}
}
@ -454,7 +478,7 @@ class DynamicLibrary {
symbols = {};
constructor(path, symbols) {
({ 0: this.#rid, 1: this.symbols } = ops.op_ffi_load({ path, symbols }));
({ 0: this.#rid, 1: this.symbols } = op_ffi_load({ path, symbols }));
for (const symbol in symbols) {
if (!ObjectHasOwn(symbols, symbol)) {
continue;
@ -475,7 +499,7 @@ class DynamicLibrary {
}
const name = symbols[symbol].name || symbol;
const value = ops.op_ffi_get_static(
const value = op_ffi_get_static(
this.#rid,
name,
type,

View file

@ -1,39 +1,75 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
isDate,
} = core;
const {
op_fs_chdir,
op_fs_chmod_async,
op_fs_ftruncate_async,
op_fs_truncate_async,
op_fs_link_async,
op_fs_flock_async,
op_fs_chmod_sync,
op_fs_chown_async,
op_fs_chown_sync,
op_fs_copy_file_async,
op_fs_copy_file_sync,
op_fs_cwd,
op_fs_fdatasync_async,
op_fs_fdatasync_sync,
op_fs_flock_async,
op_fs_flock_sync,
op_fs_fstat_async,
op_fs_fstat_sync,
op_fs_fsync_async,
op_fs_fsync_sync,
op_fs_ftruncate_async,
op_fs_ftruncate_sync,
op_fs_funlock_async,
op_fs_funlock_sync,
op_fs_futime_async,
op_fs_futime_sync,
op_fs_link_async,
op_fs_link_sync,
op_fs_lstat_async,
op_fs_lstat_sync,
op_fs_make_temp_dir_async,
op_fs_make_temp_dir_sync,
op_fs_make_temp_file_async,
op_fs_make_temp_file_sync,
op_fs_mkdir_async,
op_fs_mkdir_sync,
op_fs_open_async,
op_fs_open_sync,
op_fs_read_dir_async,
op_fs_read_dir_sync,
op_fs_read_file_async,
op_fs_read_file_sync,
op_fs_read_file_text_async,
op_fs_read_file_text_sync,
op_fs_read_link_async,
op_fs_read_link_sync,
op_fs_realpath_async,
op_fs_realpath_sync,
op_fs_remove_async,
op_fs_remove_sync,
op_fs_rename_async,
op_fs_rename_sync,
op_fs_seek_async,
op_fs_seek_sync,
op_fs_stat_async,
op_fs_stat_sync,
op_fs_symlink_async,
op_fs_symlink_sync,
op_fs_truncate_async,
op_fs_truncate_sync,
op_fs_umask,
op_fs_utime_async,
op_fs_utime_sync,
op_fs_write_file_async,
op_fs_write_file_sync,
} = core.ensureFastOps();
const {
op_cancel_handle,
} = core.ensureFastOps(true);
const {
ArrayPrototypeFilter,
Date,
@ -50,9 +86,7 @@ const {
SymbolIterator,
Uint32Array,
} = primordials;
const {
isDate,
} = core;
import { read, readSync, write, writeSync } from "ext:deno_io/12_io.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import {
@ -63,7 +97,7 @@ import {
import { pathFromURL, SymbolDispose } from "ext:deno_web/00_infra.js";
function chmodSync(path, mode) {
ops.op_fs_chmod_sync(pathFromURL(path), mode);
op_fs_chmod_sync(pathFromURL(path), mode);
}
async function chmod(path, mode) {
@ -75,7 +109,7 @@ function chownSync(
uid,
gid,
) {
ops.op_fs_chown_sync(pathFromURL(path), uid, gid);
op_fs_chown_sync(pathFromURL(path), uid, gid);
}
async function chown(
@ -94,7 +128,7 @@ function copyFileSync(
fromPath,
toPath,
) {
ops.op_fs_copy_file_sync(
op_fs_copy_file_sync(
pathFromURL(fromPath),
pathFromURL(toPath),
);
@ -111,15 +145,15 @@ async function copyFile(
}
function cwd() {
return ops.op_fs_cwd();
return op_fs_cwd();
}
function chdir(directory) {
ops.op_fs_chdir(pathFromURL(directory));
op_fs_chdir(pathFromURL(directory));
}
function makeTempDirSync(options = {}) {
return ops.op_fs_make_temp_dir_sync(
return op_fs_make_temp_dir_sync(
options.dir,
options.prefix,
options.suffix,
@ -135,7 +169,7 @@ function makeTempDir(options = {}) {
}
function makeTempFileSync(options = {}) {
return ops.op_fs_make_temp_file_sync(
return op_fs_make_temp_file_sync(
options.dir,
options.prefix,
options.suffix,
@ -151,7 +185,7 @@ function makeTempFile(options = {}) {
}
function mkdirSync(path, options) {
ops.op_fs_mkdir_sync(
op_fs_mkdir_sync(
pathFromURL(path),
options?.recursive ?? false,
options?.mode,
@ -167,7 +201,7 @@ async function mkdir(path, options) {
}
function readDirSync(path) {
return ops.op_fs_read_dir_sync(pathFromURL(path))[
return op_fs_read_dir_sync(pathFromURL(path))[
SymbolIterator
]();
}
@ -187,7 +221,7 @@ function readDir(path) {
}
function readLinkSync(path) {
return ops.op_fs_read_link_sync(pathFromURL(path));
return op_fs_read_link_sync(pathFromURL(path));
}
function readLink(path) {
@ -195,7 +229,7 @@ function readLink(path) {
}
function realPathSync(path) {
return ops.op_fs_realpath_sync(pathFromURL(path));
return op_fs_realpath_sync(pathFromURL(path));
}
function realPath(path) {
@ -206,7 +240,7 @@ function removeSync(
path,
options = {},
) {
ops.op_fs_remove_sync(
op_fs_remove_sync(
pathFromURL(path),
!!options.recursive,
);
@ -223,7 +257,7 @@ async function remove(
}
function renameSync(oldpath, newpath) {
ops.op_fs_rename_sync(
op_fs_rename_sync(
pathFromURL(oldpath),
pathFromURL(newpath),
);
@ -357,7 +391,7 @@ function parseFileInfo(response) {
}
function fstatSync(rid) {
ops.op_fs_fstat_sync(rid, statBuf);
op_fs_fstat_sync(rid, statBuf);
return statStruct(statBuf);
}
@ -371,7 +405,7 @@ async function lstat(path) {
}
function lstatSync(path) {
ops.op_fs_lstat_sync(pathFromURL(path), statBuf);
op_fs_lstat_sync(pathFromURL(path), statBuf);
return statStruct(statBuf);
}
@ -381,7 +415,7 @@ async function stat(path) {
}
function statSync(path) {
ops.op_fs_stat_sync(pathFromURL(path), statBuf);
op_fs_stat_sync(pathFromURL(path), statBuf);
return statStruct(statBuf);
}
@ -393,7 +427,7 @@ function coerceLen(len) {
}
function ftruncateSync(rid, len) {
ops.op_fs_ftruncate_sync(rid, coerceLen(len));
op_fs_ftruncate_sync(rid, coerceLen(len));
}
async function ftruncate(rid, len) {
@ -401,7 +435,7 @@ async function ftruncate(rid, len) {
}
function truncateSync(path, len) {
ops.op_fs_truncate_sync(path, coerceLen(len));
op_fs_truncate_sync(path, coerceLen(len));
}
async function truncate(path, len) {
@ -409,11 +443,11 @@ async function truncate(path, len) {
}
function umask(mask) {
return ops.op_fs_umask(mask);
return op_fs_umask(mask);
}
function linkSync(oldpath, newpath) {
ops.op_fs_link_sync(oldpath, newpath);
op_fs_link_sync(oldpath, newpath);
}
async function link(oldpath, newpath) {
@ -448,7 +482,7 @@ function futimeSync(
) {
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
ops.op_fs_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec);
op_fs_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec);
}
async function futime(
@ -474,7 +508,7 @@ function utimeSync(
) {
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
ops.op_fs_utime_sync(
op_fs_utime_sync(
pathFromURL(path),
atimeSec,
atimeNsec,
@ -504,7 +538,7 @@ function symlinkSync(
newpath,
options,
) {
ops.op_fs_symlink_sync(
op_fs_symlink_sync(
pathFromURL(oldpath),
pathFromURL(newpath),
options?.type,
@ -524,7 +558,7 @@ async function symlink(
}
function fdatasyncSync(rid) {
ops.op_fs_fdatasync_sync(rid);
op_fs_fdatasync_sync(rid);
}
async function fdatasync(rid) {
@ -532,7 +566,7 @@ async function fdatasync(rid) {
}
function fsyncSync(rid) {
ops.op_fs_fsync_sync(rid);
op_fs_fsync_sync(rid);
}
async function fsync(rid) {
@ -540,7 +574,7 @@ async function fsync(rid) {
}
function flockSync(rid, exclusive) {
ops.op_fs_flock_sync(rid, exclusive === true);
op_fs_flock_sync(rid, exclusive === true);
}
async function flock(rid, exclusive) {
@ -548,7 +582,7 @@ async function flock(rid, exclusive) {
}
function funlockSync(rid) {
ops.op_fs_funlock_sync(rid);
op_fs_funlock_sync(rid);
}
async function funlock(rid) {
@ -560,7 +594,7 @@ function seekSync(
offset,
whence,
) {
return ops.op_fs_seek_sync(rid, offset, whence);
return op_fs_seek_sync(rid, offset, whence);
}
function seek(
@ -576,7 +610,7 @@ function openSync(
options,
) {
if (options) checkOpenOptions(options);
const rid = ops.op_fs_open_sync(
const rid = op_fs_open_sync(
pathFromURL(path),
options,
);
@ -720,7 +754,7 @@ function checkOpenOptions(options) {
const File = FsFile;
function readFileSync(path) {
return ops.op_fs_read_file_sync(pathFromURL(path));
return op_fs_read_file_sync(pathFromURL(path));
}
async function readFile(path, options) {
@ -728,7 +762,7 @@ async function readFile(path, options) {
let abortHandler;
if (options?.signal) {
options.signal.throwIfAborted();
cancelRid = ops.op_cancel_handle();
cancelRid = op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}
@ -750,7 +784,7 @@ async function readFile(path, options) {
}
function readTextFileSync(path) {
return ops.op_fs_read_file_text_sync(pathFromURL(path));
return op_fs_read_file_text_sync(pathFromURL(path));
}
async function readTextFile(path, options) {
@ -758,7 +792,7 @@ async function readTextFile(path, options) {
let abortHandler;
if (options?.signal) {
options.signal.throwIfAborted();
cancelRid = ops.op_cancel_handle();
cancelRid = op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}
@ -785,7 +819,7 @@ function writeFileSync(
options = {},
) {
options.signal?.throwIfAborted();
ops.op_fs_write_file_sync(
op_fs_write_file_sync(
pathFromURL(path),
options.mode,
options.append ?? false,
@ -804,7 +838,7 @@ async function writeFile(
let abortHandler;
if (options.signal) {
options.signal.throwIfAborted();
cancelRid = ops.op_cancel_handle();
cancelRid = op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}

View file

@ -1,8 +1,43 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals, primordials } from "ext:core/mod.js";
const {
BadResourcePrototype,
InterruptedPrototype,
} = core;
const {
op_http_close_after_finish,
op_http_get_request_headers,
op_http_get_request_method_and_url,
op_http_read_request_body,
op_http_serve,
op_http_serve_on,
op_http_set_promise_complete,
op_http_set_response_body_bytes,
op_http_set_response_body_resource,
op_http_set_response_body_text,
op_http_set_response_header,
op_http_set_response_headers,
op_http_set_response_trailers,
op_http_upgrade_raw,
op_http_upgrade_websocket_next,
op_http_try_wait,
op_http_wait,
op_http_cancel,
op_http_close,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
PromisePrototypeCatch,
PromisePrototypeThen,
Symbol,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
Uint8Array,
} = primordials;
const { BadResourcePrototype, InterruptedPrototype } = core;
import { InnerBody } from "ext:deno_fetch/22_body.js";
import { Event } from "ext:deno_web/02_event.js";
import {
@ -36,39 +71,7 @@ import {
import { listen, listenOptionApiName, TcpConn } from "ext:deno_net/01_net.js";
import { listenTls } from "ext:deno_net/02_tls.js";
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js";
const {
ArrayPrototypePush,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
PromisePrototypeCatch,
PromisePrototypeThen,
Symbol,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
Uint8Array,
} = primordials;
const {
op_http_close_after_finish,
op_http_get_request_headers,
op_http_get_request_method_and_url,
op_http_read_request_body,
op_http_serve,
op_http_serve_on,
op_http_set_promise_complete,
op_http_set_response_body_bytes,
op_http_set_response_body_resource,
op_http_set_response_body_text,
op_http_set_response_header,
op_http_set_response_headers,
op_http_set_response_trailers,
op_http_upgrade_raw,
op_http_upgrade_websocket_next,
op_http_try_wait,
op_http_wait,
op_http_cancel,
op_http_close,
} = core.ensureFastOps();
const _upgraded = Symbol("_upgraded");
function internalServerError() {

View file

@ -1,7 +1,43 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals, primordials } from "ext:core/mod.js";
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
const {
BadResourcePrototype,
InterruptedPrototype,
} = core;
const {
op_http_accept,
op_http_headers,
op_http_shutdown,
op_http_upgrade,
op_http_upgrade_websocket,
op_http_websocket_accept_header,
op_http_write,
op_http_write_headers,
op_http_write_resource,
} = core.ensureFastOps();
const {
ArrayPrototypeIncludes,
ArrayPrototypeMap,
ArrayPrototypePush,
Error,
ObjectPrototypeIsPrototypeOf,
SafeSet,
SafeSetIterator,
SetPrototypeAdd,
SetPrototypeDelete,
StringPrototypeCharCodeAt,
StringPrototypeIncludes,
StringPrototypeSplit,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
Symbol,
SymbolAsyncIterator,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
Uint8Array,
} = primordials;
import { InnerBody } from "ext:deno_fetch/22_body.js";
import { Event, setEventTargetData } from "ext:deno_web/02_event.js";
import { BlobPrototype } from "ext:deno_web/09_file.js";
@ -42,36 +78,6 @@ import {
} from "ext:deno_web/06_streams.js";
import { serve } from "ext:deno_http/00_serve.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js";
const {
ArrayPrototypeIncludes,
ArrayPrototypeMap,
ArrayPrototypePush,
Error,
ObjectPrototypeIsPrototypeOf,
SafeSet,
SafeSetIterator,
SetPrototypeAdd,
SetPrototypeDelete,
StringPrototypeCharCodeAt,
StringPrototypeIncludes,
StringPrototypeSplit,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
Symbol,
SymbolAsyncIterator,
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
Uint8Array,
} = primordials;
const {
op_http_accept,
op_http_shutdown,
op_http_upgrade,
op_http_write,
op_http_upgrade_websocket,
op_http_write_headers,
op_http_write_resource,
} = core.ensureFastOps();
const connErrorSymbol = Symbol("connError");
const _deferred = Symbol("upgradeHttpDeferred");
@ -152,7 +158,7 @@ class HttpConn {
const innerRequest = newInnerRequest(
method,
url,
() => ops.op_http_headers(streamRid),
() => op_http_headers(streamRid),
body !== null ? new InnerBody(body) : null,
false,
);
@ -455,7 +461,7 @@ function upgradeWebSocket(request, options = {}) {
);
}
const accept = ops.op_http_websocket_accept_header(websocketKey);
const accept = op_http_websocket_accept_header(websocketKey);
const r = newInnerResponse(101);
r.headerList = [

View file

@ -5,11 +5,9 @@
// Thank you! We love Go! <3
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import {
readableStreamForRid,
writableStreamForRid,
} from "ext:deno_web/06_streams.js";
const {
op_stdin_set_raw,
} = core.ensureFastOps(true);
const {
Uint8Array,
ArrayPrototypePush,
@ -18,6 +16,11 @@ const {
TypedArrayPrototypeGetByteLength,
} = primordials;
import {
readableStreamForRid,
writableStreamForRid,
} from "ext:deno_web/06_streams.js";
const DEFAULT_BUFFER_SIZE = 32 * 1024;
// Seek whence values.
// https://golang.org/pkg/io/#pkg-constants
@ -192,7 +195,7 @@ class Stdin {
setRaw(mode, options = {}) {
const cbreak = !!(options.cbreak ?? false);
ops.op_stdin_set_raw(mode, cbreak);
op_stdin_set_raw(mode, cbreak);
}
}

View file

@ -1,8 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js";
import { ReadableStream } from "ext:deno_web/06_streams.js";
const {
isPromise,
} = core;
const {
op_kv_atomic_write,
op_kv_database_open,
op_kv_dequeue_next_message,
op_kv_encode_cursor,
op_kv_finish_dequeued_message,
op_kv_snapshot_read,
op_kv_watch,
op_kv_watch_next,
} = core.ensureFastOps();
const {
ArrayFrom,
ArrayPrototypeMap,
@ -30,19 +41,9 @@ const {
TypeError,
TypedArrayPrototypeGetSymbolToStringTag,
} = primordials;
const {
isPromise,
} = core;
const {
op_kv_atomic_write,
op_kv_database_open,
op_kv_dequeue_next_message,
op_kv_encode_cursor,
op_kv_finish_dequeued_message,
op_kv_snapshot_read,
op_kv_watch,
op_kv_watch_next,
} = core.ensureFastOps();
import { SymbolDispose } from "ext:deno_web/00_infra.js";
import { ReadableStream } from "ext:deno_web/06_streams.js";
const encodeCursor: (
selector: [Deno.KvKey | null, Deno.KvKey | null, Deno.KvKey | null],

View file

@ -1,33 +1,34 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
import {
readableStreamForRidUnrefable,
readableStreamForRidUnrefableRef,
readableStreamForRidUnrefableUnref,
writableStreamForRid,
} from "ext:deno_web/06_streams.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js";
const {
BadResourcePrototype,
InterruptedPrototype,
} = core;
const {
op_dns_resolve,
op_net_accept_tcp,
op_net_accept_unix,
op_net_connect_tcp,
op_net_connect_unix,
op_net_join_multi_v4_udp,
op_net_join_multi_v6_udp,
op_net_leave_multi_v4_udp,
op_net_leave_multi_v6_udp,
op_net_listen_tcp,
op_net_listen_unix,
op_net_recv_udp,
op_net_recv_unixpacket,
op_net_send_udp,
op_net_send_unixpacket,
op_net_set_multi_loopback_udp,
op_net_set_multi_ttl_udp,
op_net_join_multi_v4_udp,
op_net_join_multi_v6_udp,
op_net_leave_multi_v4_udp,
op_net_leave_multi_v6_udp,
op_set_keepalive,
op_set_nodelay,
} = core.ensureFastOps();
const {
op_cancel_handle,
} = core.ensureFastOps(true);
const {
Error,
Number,
@ -44,6 +45,15 @@ const {
Uint8Array,
} = primordials;
import {
readableStreamForRidUnrefable,
readableStreamForRidUnrefableRef,
readableStreamForRidUnrefableUnref,
writableStreamForRid,
} from "ext:deno_web/06_streams.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js";
async function write(rid, data) {
return await core.write(rid, data);
}
@ -57,7 +67,7 @@ async function resolveDns(query, recordType, options) {
let abortHandler;
if (options?.signal) {
options.signal.throwIfAborted();
cancelRid = ops.op_cancel_handle();
cancelRid = op_cancel_handle();
abortHandler = () => core.tryClose(cancelRid);
options.signal[abortSignal.add](abortHandler);
}
@ -184,11 +194,11 @@ class Conn {
class TcpConn extends Conn {
setNoDelay(noDelay = true) {
return ops.op_set_nodelay(this.rid, noDelay);
return op_set_nodelay(this.rid, noDelay);
}
setKeepAlive(keepAlive = true) {
return ops.op_set_keepalive(this.rid, keepAlive);
return op_set_keepalive(this.rid, keepAlive);
}
}
@ -453,7 +463,7 @@ const listenOptionApiName = Symbol("listenOptionApiName");
function listen(args) {
switch (args.transport ?? "tcp") {
case "tcp": {
const { 0: rid, 1: addr } = ops.op_net_listen_tcp({
const { 0: rid, 1: addr } = op_net_listen_tcp({
hostname: args.hostname ?? "0.0.0.0",
port: Number(args.port),
}, args.reusePort);
@ -461,7 +471,7 @@ function listen(args) {
return new Listener(rid, addr);
}
case "unix": {
const { 0: rid, 1: path } = ops.op_net_listen_unix(
const { 0: rid, 1: path } = op_net_listen_unix(
args.path,
args[listenOptionApiName] ?? "Deno.listen",
);

View file

@ -1,15 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import { Conn, Listener } from "ext:deno_net/01_net.js";
const { Number, TypeError } = primordials;
const {
op_tls_handshake,
op_tls_start,
op_net_accept_tls,
op_net_connect_tls,
op_net_listen_tls,
op_tls_handshake,
op_tls_start,
} = core.ensureFastOps();
const {
Number,
TypeError,
} = primordials;
import { Conn, Listener } from "ext:deno_net/01_net.js";
function opStartTls(args) {
return op_tls_start(args);
@ -72,7 +76,7 @@ function listenTls({
if (transport !== "tcp") {
throw new TypeError(`Unsupported transport: '${transport}'`);
}
const { 0: rid, 1: localAddr } = ops.op_net_listen_tls(
const { 0: rid, 1: localAddr } = op_net_listen_tls(
{ hostname, port: Number(port) },
{ cert, certFile, key, keyFile, alpnProtocols, reusePort },
);

View file

@ -3,7 +3,33 @@
// deno-lint-ignore-file
import { core, internals, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_require_as_file_path,
op_require_break_on_next_statement,
op_require_init_paths,
op_require_is_deno_dir_package,
op_require_is_request_relative,
op_require_node_module_paths,
op_require_package_imports_resolve,
op_require_path_basename,
op_require_path_dirname,
op_require_path_is_absolute,
op_require_path_resolve,
op_require_proxy_path,
op_require_read_file,
op_require_read_package_scope,
op_require_real_path,
op_require_resolve_deno_dir,
op_require_resolve_exports,
op_require_resolve_lookup_paths,
op_require_stat,
op_require_try_self,
op_require_try_self_parent_path,
} = core.ensureFastOps();
const {
op_napi_open,
op_require_read_closest_package_json,
} = core.ensureFastOps(true);
const {
ArrayIsArray,
ArrayPrototypeIncludes,
@ -12,32 +38,33 @@ const {
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
Error,
JSONParse,
ObjectCreate,
ObjectEntries,
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
ObjectHasOwn,
ObjectSetPrototypeOf,
ObjectKeys,
ObjectEntries,
ObjectPrototype,
ObjectCreate,
ObjectSetPrototypeOf,
Proxy,
RegExpPrototypeTest,
SafeArrayIterator,
SafeMap,
SafeWeakMap,
SafeArrayIterator,
JSONParse,
String,
StringPrototypeCharCodeAt,
StringPrototypeEndsWith,
StringPrototypeIndexOf,
StringPrototypeIncludes,
StringPrototypeIndexOf,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeSplit,
StringPrototypeStartsWith,
StringPrototypeCharCodeAt,
RegExpPrototypeTest,
Error,
TypeError,
} = primordials;
import { nodeGlobals } from "ext:deno_node/00_globals.js";
import _httpAgent from "ext:deno_node/_http_agent.mjs";
@ -248,11 +275,11 @@ function pathDirname(filepath) {
} else if (filepath === "") {
return ".";
}
return ops.op_require_path_dirname(filepath);
return op_require_path_dirname(filepath);
}
function pathResolve(...args) {
return ops.op_require_path_resolve(args);
return op_require_path_resolve(args);
}
const nativeModulePolyfill = new SafeMap();
@ -276,7 +303,7 @@ function stat(filename) {
return result;
}
}
const result = ops.op_require_stat(filename);
const result = op_require_stat(filename);
if (statCache !== null && result >= 0) {
statCache.set(filename, result);
}
@ -306,7 +333,7 @@ function tryPackage(requestPath, exts, isMain, originalPath) {
requestPath,
"package.json",
);
const pkg = ops.op_require_read_package_scope(packageJsonPath)?.main;
const pkg = op_require_read_package_scope(packageJsonPath)?.main;
if (!pkg) {
return tryExtensions(
pathResolve(requestPath, "index"),
@ -360,7 +387,7 @@ function toRealPath(requestPath) {
if (maybeCached) {
return maybeCached;
}
const rp = ops.op_require_real_path(requestPath);
const rp = op_require_real_path(requestPath);
realpathCache.set(requestPath, rp);
return rp;
}
@ -379,7 +406,7 @@ function tryExtensions(p, exts, isMain) {
// Find the longest (possibly multi-dot) extension registered in
// Module._extensions
function findLongestRegisteredExtension(filename) {
const name = ops.op_require_path_basename(filename);
const name = op_require_path_basename(filename);
let currentExtension;
let index;
let startIndex = 0;
@ -513,7 +540,7 @@ function resolveExports(
return false;
}
return ops.op_require_resolve_exports(
return op_require_resolve_exports(
usesLocalNodeModulesDir,
modulesPath,
request,
@ -524,7 +551,7 @@ function resolveExports(
}
Module._findPath = function (request, paths, isMain, parentPath) {
const absoluteRequest = ops.op_require_path_is_absolute(request);
const absoluteRequest = op_require_path_is_absolute(request);
if (absoluteRequest) {
paths = [""];
} else if (!paths || paths.length === 0) {
@ -568,10 +595,10 @@ Module._findPath = function (request, paths, isMain, parentPath) {
if (usesLocalNodeModulesDir) {
basePath = pathResolve(curPath, request);
} else {
const isDenoDirPackage = ops.op_require_is_deno_dir_package(
const isDenoDirPackage = op_require_is_deno_dir_package(
curPath,
);
const isRelative = ops.op_require_is_request_relative(
const isRelative = op_require_is_request_relative(
request,
);
basePath = (isDenoDirPackage && !isRelative)
@ -618,16 +645,16 @@ Module._findPath = function (request, paths, isMain, parentPath) {
* @returns {string[]} List of module directories
*/
Module._nodeModulePaths = function (fromPath) {
return ops.op_require_node_module_paths(fromPath);
return op_require_node_module_paths(fromPath);
};
Module._resolveLookupPaths = function (request, parent) {
const paths = [];
if (ops.op_require_is_request_relative(request)) {
if (op_require_is_request_relative(request)) {
ArrayPrototypePush(
paths,
parent?.filename ? ops.op_require_path_dirname(parent.filename) : ".",
parent?.filename ? op_require_path_dirname(parent.filename) : ".",
);
return paths;
}
@ -635,7 +662,7 @@ Module._resolveLookupPaths = function (request, parent) {
if (
!usesLocalNodeModulesDir && parent?.filename && parent.filename.length > 0
) {
const denoDirPath = ops.op_require_resolve_deno_dir(
const denoDirPath = op_require_resolve_deno_dir(
request,
parent.filename,
);
@ -643,7 +670,7 @@ Module._resolveLookupPaths = function (request, parent) {
ArrayPrototypePush(paths, denoDirPath);
}
}
const lookupPathsResult = ops.op_require_resolve_lookup_paths(
const lookupPathsResult = op_require_resolve_lookup_paths(
request,
parent?.paths,
parent?.filename ?? "",
@ -765,7 +792,7 @@ Module._resolveFilename = function (
if (typeof options === "object" && options !== null) {
if (ArrayIsArray(options.paths)) {
const isRelative = ops.op_require_is_request_relative(
const isRelative = op_require_is_request_relative(
request,
);
@ -800,7 +827,7 @@ Module._resolveFilename = function (
if (parent?.filename) {
if (request[0] === "#") {
const maybeResolved = ops.op_require_package_imports_resolve(
const maybeResolved = op_require_package_imports_resolve(
parent.filename,
request,
);
@ -811,12 +838,12 @@ Module._resolveFilename = function (
}
// Try module self resolution first
const parentPath = ops.op_require_try_self_parent_path(
const parentPath = op_require_try_self_parent_path(
!!parent,
parent?.filename,
parent?.id,
);
const selfResolved = ops.op_require_try_self(parentPath, request);
const selfResolved = op_require_try_self(parentPath, request);
if (selfResolved) {
const cacheKey = request + "\x00" +
(paths.length === 1 ? paths[0] : ArrayPrototypeJoin(paths, "\x00"));
@ -832,7 +859,7 @@ Module._resolveFilename = function (
parentPath,
);
if (filename) {
return ops.op_require_real_path(filename);
return op_require_real_path(filename);
}
const requireStack = [];
for (let cursor = parent; cursor; cursor = moduleParentCache.get(cursor)) {
@ -876,7 +903,7 @@ Module.prototype.load = function (filename) {
// Canonicalize the path so it's not pointing to the symlinked directory
// in `node_modules` directory of the referrer.
this.filename = ops.op_require_real_path(filename);
this.filename = op_require_real_path(filename);
this.paths = Module._nodeModulePaths(
pathDirname(this.filename),
);
@ -989,7 +1016,7 @@ Module.prototype._compile = function (content, filename) {
if (hasInspectBrk && !hasBrokenOnInspectBrk) {
hasBrokenOnInspectBrk = true;
ops.op_require_break_on_next_statement();
op_require_break_on_next_statement();
}
const {
@ -1032,10 +1059,10 @@ Module.prototype._compile = function (content, filename) {
};
Module._extensions[".js"] = function (module, filename) {
const content = ops.op_require_read_file(filename);
const content = op_require_read_file(filename);
if (StringPrototypeEndsWith(filename, ".js")) {
const pkg = ops.op_require_read_closest_package_json(filename);
const pkg = op_require_read_closest_package_json(filename);
if (pkg && pkg.exists && pkg.typ === "module") {
throw createRequireEsmError(
filename,
@ -1070,7 +1097,7 @@ function stripBOM(content) {
// Native extension for .json
Module._extensions[".json"] = function (module, filename) {
const content = ops.op_require_read_file(filename);
const content = op_require_read_file(filename);
try {
module.exports = JSONParse(stripBOM(content));
@ -1085,11 +1112,11 @@ Module._extensions[".node"] = function (module, filename) {
if (filename.endsWith("fsevents.node")) {
throw new Error("Using fsevents module is currently not supported");
}
module.exports = ops.op_napi_open(filename, globalThis);
module.exports = op_napi_open(filename, globalThis);
};
function createRequireFromPath(filename) {
const proxyPath = ops.op_require_proxy_path(filename);
const proxyPath = op_require_proxy_path(filename);
const mod = new Module(proxyPath);
mod.filename = proxyPath;
mod.paths = Module._nodeModulePaths(mod.path);
@ -1152,14 +1179,14 @@ function createRequire(filenameOrUrl) {
`The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ${filenameOrUrl}`,
);
}
const filename = ops.op_require_as_file_path(fileUrlStr);
const filename = op_require_as_file_path(fileUrlStr);
return createRequireFromPath(filename);
}
Module.createRequire = createRequire;
Module._initPaths = function () {
const paths = ops.op_require_init_paths();
const paths = op_require_init_paths();
modulePaths = paths;
Module.globalPaths = ArrayPrototypeSlice(modulePaths);
};

View file

@ -2,8 +2,9 @@
// deno-lint-ignore-file
const internals = globalThis.__bootstrap.internals;
import { internals } from "ext:core/mod.js";
const requireImpl = internals.requireImpl;
import { nodeGlobals } from "ext:deno_node/00_globals.js";
import "node:module";

View file

@ -3,15 +3,23 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_brotli_compress,
op_brotli_compress_async,
op_brotli_compress_stream,
op_brotli_compress_stream_end,
op_brotli_decompress,
op_brotli_decompress_async,
op_brotli_decompress_stream,
op_create_brotli_compress,
op_create_brotli_decompress,
} = core.ensureFastOps();
import { zlib as constants } from "ext:deno_node/internal_binding/constants.ts";
import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { Transform } from "node:stream";
import { Buffer } from "node:buffer";
const { core } = globalThis.__bootstrap;
const { ops } = core;
const {
op_brotli_compress_async,
} = core.ensureFastOps();
const enc = new TextEncoder();
const toU8 = (input) => {
@ -44,7 +52,7 @@ export class BrotliDecompress extends Transform {
transform(chunk, _encoding, callback) {
const input = toU8(chunk);
const output = new Uint8Array(1024);
const avail = ops.op_brotli_decompress_stream(context, input, output);
const avail = op_brotli_decompress_stream(context, input, output);
this.push(output.slice(0, avail));
callback();
},
@ -54,7 +62,7 @@ export class BrotliDecompress extends Transform {
},
});
this.#context = ops.op_create_brotli_decompress();
this.#context = op_create_brotli_decompress();
const context = this.#context;
}
}
@ -68,20 +76,20 @@ export class BrotliCompress extends Transform {
transform(chunk, _encoding, callback) {
const input = toU8(chunk);
const output = new Uint8Array(brotliMaxCompressedSize(input.length));
const avail = ops.op_brotli_compress_stream(context, input, output);
const avail = op_brotli_compress_stream(context, input, output);
this.push(output.slice(0, avail));
callback();
},
flush(callback) {
const output = new Uint8Array(1024);
const avail = ops.op_brotli_compress_stream_end(context, output);
const avail = op_brotli_compress_stream_end(context, output);
this.push(output.slice(0, avail));
callback();
},
});
const params = Object.values(options?.params ?? {});
this.#context = ops.op_create_brotli_compress(params);
this.#context = op_create_brotli_compress(params);
const context = this.#context;
}
}
@ -138,17 +146,17 @@ export function brotliCompressSync(
const output = new Uint8Array(brotliMaxCompressedSize(buf.length));
const { quality, lgwin, mode } = oneOffCompressOptions(options);
const len = ops.op_brotli_compress(buf, output, quality, lgwin, mode);
const len = op_brotli_compress(buf, output, quality, lgwin, mode);
return Buffer.from(output.subarray(0, len));
}
export function brotliDecompress(input) {
const buf = toU8(input);
return ops.op_brotli_decompress_async(buf)
return op_brotli_decompress_async(buf)
.then((result) => callback(null, Buffer.from(result)))
.catch((err) => callback(err));
}
export function brotliDecompressSync(input) {
return Buffer.from(ops.op_brotli_decompress(toU8(input)));
return Buffer.from(op_brotli_decompress(toU8(input)));
}

View file

@ -2,22 +2,24 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_cp,
op_node_cp_sync,
} = core.ensureFastOps();
import {
getValidatedPath,
validateCpOptions,
} from "ext:deno_node/internal/fs/utils.mjs";
import { promisify } from "ext:deno_node/internal/util.mjs";
const core = globalThis.__bootstrap.core;
const ops = core.ops;
const { op_node_cp } = core.ensureFastOps();
export function cpSync(src, dest, options) {
validateCpOptions(options);
const srcPath = getValidatedPath(src, "src");
const destPath = getValidatedPath(dest, "dest");
ops.op_node_cp_sync(srcPath, destPath);
op_node_cp_sync(srcPath, destPath);
}
export function cp(src, dest, options, callback) {

View file

@ -2,7 +2,12 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
const core = globalThis.__bootstrap.core;
import { core } from "ext:core/mod.js";
const {
op_node_fs_exists_sync,
} = core.ensureFastOps();
import { pathFromURL } from "ext:deno_web/00_infra.js";
type ExistsCallback = (exists: boolean) => void;
@ -35,5 +40,5 @@ Object.defineProperty(exists, kCustomPromisifiedSymbol, {
*/
export function existsSync(path: string | URL): boolean {
path = path instanceof URL ? pathFromURL(path) : path;
return core.ops.op_node_fs_exists_sync(path);
return op_node_fs_exists_sync(path);
}

View file

@ -4,12 +4,12 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
import { validateFunction } from "ext:deno_node/internal/validators.mjs";
import { _exiting } from "ext:deno_node/_process/exiting.ts";
import { FixedQueue } from "ext:deno_node/internal/fixed_queue.ts";
const { core } = globalThis.__bootstrap;
interface Tock {
callback: (...args: Array<unknown>) => void;
args: Array<unknown>;

View file

@ -8,6 +8,7 @@
// They have to be split this way to prevent a circular dependency
import { core } from "ext:core/mod.js";
import { nextTick as _nextTick } from "ext:deno_node/_next_tick.ts";
import { _exiting } from "ext:deno_node/_process/exiting.ts";
import * as fs from "ext:deno_fs/30_fs.js";

View file

@ -24,7 +24,6 @@
// These are simplified versions of the "real" errors in Node.
import { primordials } from "ext:core/mod.js";
import { nextTick } from "ext:deno_node/_next_tick.ts";
const {
ArrayPrototypePop,
Error,
@ -36,6 +35,8 @@ const {
TypeError,
} = primordials;
import { nextTick } from "ext:deno_node/_next_tick.ts";
class NodeFalsyValueRejectionError extends Error {
public reason: unknown;
public code = "ERR_FALSY_VALUE_REJECTION";

View file

@ -3,12 +3,13 @@
// (with some modifications)
import { primordials } from "ext:core/mod.js";
import { clearTimeout, setTimeout } from "ext:deno_web/02_timers.js";
const {
Promise,
PromiseReject,
} = primordials;
import { clearTimeout, setTimeout } from "ext:deno_web/02_timers.js";
/** Resolve a Promise after a given amount of milliseconds. */
export function delay(
ms: number,

View file

@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_node_build_os,
} = core.ensureFastOps(true);
export type OSType =
| "windows"
@ -11,7 +13,7 @@ export type OSType =
| "freebsd"
| "openbsd";
export const osType: OSType = ops.op_node_build_os();
export const osType: OSType = op_node_build_os();
export const isWindows = osType === "windows";
export const isLinux = osType === "linux" || osType === "android";

View file

@ -2,13 +2,6 @@
// vendored from std/assert/mod.ts
import { primordials } from "ext:core/mod.js";
import { URLPrototype } from "ext:deno_url/00_url.js";
import { red } from "ext:deno_node/_util/std_fmt_colors.ts";
import {
buildMessage,
diff,
diffstr,
} from "ext:deno_node/_util/std_testing_diff.ts";
const {
DatePrototype,
ArrayPrototypeJoin,
@ -37,6 +30,14 @@ const {
WeakRefPrototypeDeref,
} = primordials;
import { URLPrototype } from "ext:deno_url/00_url.js";
import { red } from "ext:deno_node/_util/std_fmt_colors.ts";
import {
buildMessage,
diff,
diffstr,
} from "ext:deno_node/_util/std_testing_diff.ts";
const FORMAT_PATTERN = new SafeRegExp(/(?=["\\])/g);
/** Converts the input into a string. Objects, Sets and Maps are sorted so as to

View file

@ -2,15 +2,6 @@
// This file was vendored from std/testing/_diff.ts
import { primordials } from "ext:core/mod.js";
import {
bgGreen,
bgRed,
bold,
gray,
green,
red,
white,
} from "ext:deno_node/_util/std_fmt_colors.ts";
const {
ArrayFrom,
ArrayPrototypeFilter,
@ -23,19 +14,29 @@ const {
ArrayPrototypeReverse,
ArrayPrototypeShift,
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ArrayPrototypeSome,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
SafeArrayIterator,
SafeRegExp,
StringPrototypeSplit,
StringPrototypeReplace,
StringPrototypeTrim,
MathMin,
ObjectFreeze,
SafeArrayIterator,
SafeRegExp,
StringPrototypeReplace,
StringPrototypeSplit,
StringPrototypeTrim,
Uint32Array,
} = primordials;
import {
bgGreen,
bgRed,
bold,
gray,
green,
red,
white,
} from "ext:deno_node/_util/std_fmt_colors.ts";
interface FarthestPoint {
y: number;
id: number;

View file

@ -43,9 +43,14 @@ export const DEFLATERAW = 5;
export const INFLATERAW = 6;
export const UNZIP = 7;
const { core } = globalThis.__bootstrap;
const { ops } = core;
import { core } from "ext:core/mod.js";
const {
op_zlib_close,
op_zlib_close_if_pending,
op_zlib_init,
op_zlib_new,
op_zlib_reset,
op_zlib_write,
op_zlib_write_async,
} = core.ensureFastOps();
@ -55,11 +60,11 @@ class Zlib {
#handle;
constructor(mode) {
this.#handle = ops.op_zlib_new(mode);
this.#handle = op_zlib_new(mode);
}
close() {
ops.op_zlib_close(this.#handle);
op_zlib_close(this.#handle);
}
writeSync(
@ -71,7 +76,7 @@ class Zlib {
out_off,
out_len,
) {
const err = ops.op_zlib_write(
const err = op_zlib_write(
this.#handle,
flush,
input,
@ -145,7 +150,7 @@ class Zlib {
strategy,
dictionary,
) {
const err = ops.op_zlib_init(
const err = op_zlib_init(
this.#handle,
level,
windowBits,
@ -164,7 +169,7 @@ class Zlib {
}
reset() {
const err = ops.op_zlib_reset(this.#handle);
const err = op_zlib_reset(this.#handle);
if (err != Z_OK) {
this.#error("Failed to reset stream", err);
}
@ -172,7 +177,7 @@ class Zlib {
#error(message, err) {
this.onerror(message, err);
ops.op_zlib_close_if_pending(this.#handle);
op_zlib_close_if_pending(this.#handle);
}
}

View file

@ -6,6 +6,14 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core, internals } from "ext:core/mod.js";
const {
op_node_child_ipc_pipe,
} = core.ensureFastOps();
const {
op_npm_process_state,
} = core.ensureFastOps(true);
import {
ChildProcess,
ChildProcessOptions,
@ -48,9 +56,6 @@ import {
kEmptyObject,
} from "ext:deno_node/internal/util.mjs";
const { core } = globalThis.__bootstrap;
const ops = core.ops;
const MAX_BUFFER = 1024 * 1024;
type ForkOptions = ChildProcessOptions;
@ -151,8 +156,7 @@ export function fork(
options.shell = false;
Object.assign(options.env ??= {}, {
DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE: core.ops
.op_npm_process_state(),
DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE: op_npm_process_state(),
});
return spawn(options.execPath, args, options);
@ -824,13 +828,12 @@ export function execFileSync(
}
function setupChildProcessIpcChannel() {
const fd = ops.op_node_child_ipc_pipe();
const fd = op_node_child_ipc_pipe();
if (typeof fd != "number" || fd < 0) return;
setupChannel(process, fd);
}
globalThis.__bootstrap.internals.__setupChildProcessIpcChannel =
setupChildProcessIpcChannel;
internals.__setupChildProcessIpcChannel = setupChildProcessIpcChannel;
export default {
fork,

View file

@ -3,9 +3,13 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
// import { ReadableStreamPrototype } from "ext:deno_web/06_streams.js";
import { core } from "ext:core/mod.js";
const {
op_fetch_response_upgrade,
op_fetch_send,
op_node_http_request,
} = core.ensureFastOps();
const core = globalThis.__bootstrap.core;
import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { setTimeout } from "ext:deno_web/02_timers.js";
import {
@ -60,10 +64,6 @@ import { timerId } from "ext:deno_web/03_abort_signal.js";
import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js";
import { resourceForReadableStream } from "ext:deno_web/06_streams.js";
import { TcpConn } from "ext:deno_net/01_net.js";
const {
op_fetch_response_upgrade,
op_fetch_send,
} = core.ensureFastOps();
enum STATUS_CODES {
/** RFC 7231, 6.2.1 */
@ -606,7 +606,7 @@ class ClientRequest extends OutgoingMessage {
this._bodyWriteRid = resourceForReadableStream(readable);
}
this._req = core.ops.op_node_http_request(
this._req = op_node_http_request(
this.method,
url,
headers,

View file

@ -5,6 +5,18 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_http2_connect,
op_http2_client_get_response,
op_http2_client_get_response_body_chunk,
op_http2_client_get_response_trailers,
op_http2_client_request,
op_http2_client_reset_stream,
op_http2_client_send_data,
op_http2_client_send_trailers,
op_http2_poll_client_connection,
} = core.ensureFastOps();
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
import { EventEmitter } from "node:events";
import { Buffer } from "node:buffer";
@ -43,18 +55,6 @@ import {
} from "ext:deno_node/internal/errors.ts";
import { _checkIsHttpToken } from "ext:deno_node/_http_common.ts";
const {
op_http2_connect,
op_http2_client_get_response,
op_http2_client_get_response_body_chunk,
op_http2_client_get_response_trailers,
op_http2_client_request,
op_http2_client_reset_stream,
op_http2_client_send_data,
op_http2_client_send_trailers,
op_http2_poll_client_connection,
} = core.ensureFastOps();
const kSession = Symbol("session");
const kAlpnProtocol = Symbol("alpnProtocol");
const kAuthority = Symbol("authority");

View file

@ -5,6 +5,8 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
import { TextDecoder, TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { codes } from "ext:deno_node/internal/error_codes.ts";
import { encodings } from "ext:deno_node/internal_binding/string_decoder.ts";
@ -35,8 +37,6 @@ import {
import { atob, btoa } from "ext:deno_web/05_base64.js";
import { Blob } from "ext:deno_web/09_file.js";
const { core } = globalThis.__bootstrap;
export { atob, Blob, btoa };
const utf8Encoder = new TextEncoder();

View file

@ -7,6 +7,22 @@
// deno-lint-ignore-file prefer-primordials
import { core, internals } from "ext:core/mod.js";
const {
op_node_ipc_read,
op_node_ipc_write,
} = core.ensureFastOps();
import {
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeJoin,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSort,
ArrayPrototypeUnshift,
ObjectHasOwn,
StringPrototypeToUpperCase,
} from "ext:deno_node/internal/primordials.mjs";
import { assert } from "ext:deno_node/_util/asserts.ts";
import { EventEmitter } from "node:events";
import { os } from "ext:deno_node/internal_binding/constants.ts";
@ -30,27 +46,10 @@ import {
validateObject,
validateString,
} from "ext:deno_node/internal/validators.mjs";
import {
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeJoin,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSort,
ArrayPrototypeUnshift,
ObjectHasOwn,
StringPrototypeToUpperCase,
} from "ext:deno_node/internal/primordials.mjs";
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs";
import process from "node:process";
const core = globalThis.__bootstrap.core;
const {
op_node_ipc_read,
op_node_ipc_write,
} = core.ensureFastOps();
export function mapValues<T, O>(
record: Readonly<Record<string, T>>,
transformer: (value: T) => O,

View file

@ -1,8 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
const { ops } = globalThis.__bootstrap.core;
const isWindows = ops.op_node_build_os() === "windows";
import { isWindows } from "ext:deno_node/_util/os.ts";
// Alphabet chars.
export const CHAR_UPPERCASE_A = 65; /* A */

View file

@ -3,17 +3,18 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_generate_secret,
op_node_generate_secret_async,
} = core.ensureFastOps(true);
import {
MAX_SIZE as kMaxUint32,
} from "ext:deno_node/internal/crypto/_randomBytes.ts";
import { Buffer } from "node:buffer";
import { isAnyArrayBuffer, isArrayBufferView } from "node:util/types";
import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
const {
op_node_generate_secret_async,
} = core.ensureFastOps();
const kBufferMaxLength = 0x7fffffff;
@ -87,7 +88,7 @@ export function randomFillSync(buf, offset = 0, size) {
}
const bytes = new Uint8Array(buf.buffer ? buf.buffer : buf, offset, size);
ops.op_node_generate_secret(bytes);
op_node_generate_secret(bytes);
return buf;
}

View file

@ -4,7 +4,9 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_node_random_int,
} = core.ensureFastOps();
export default function randomInt(max: number): number;
export default function randomInt(min: number, max: number): number;
@ -49,7 +51,7 @@ export default function randomInt(
min = Math.ceil(min);
max = Math.floor(max);
const result = ops.op_node_random_int(min, max);
const result = op_node_random_int(min, max);
if (cb) {
cb(null, result);

View file

@ -4,6 +4,24 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
encode,
} = core;
const {
op_node_cipheriv_encrypt,
op_node_cipheriv_final,
op_node_cipheriv_set_aad,
op_node_create_cipheriv,
op_node_create_decipheriv,
op_node_decipheriv_decrypt,
op_node_decipheriv_final,
op_node_decipheriv_set_aad,
op_node_private_decrypt,
op_node_private_encrypt,
op_node_public_encrypt,
} = core.ensureFastOps();
import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts";
import {
validateInt32,
@ -35,8 +53,6 @@ export function isStringOrBuffer(val) {
Buffer.isBuffer(val);
}
const { ops, encode } = globalThis.__bootstrap.core;
const NO_TAG = new Uint8Array();
export type CipherCCMTypes =
@ -168,7 +184,7 @@ export class Cipheriv extends Transform implements Cipher {
...options,
});
this.#cache = new BlockModeCache(false);
this.#context = ops.op_node_create_cipheriv(cipher, toU8(key), toU8(iv));
this.#context = op_node_create_cipheriv(cipher, toU8(key), toU8(iv));
this.#needsBlockCache =
!(cipher == "aes-128-gcm" || cipher == "aes-256-gcm");
if (this.#context == 0) {
@ -178,7 +194,7 @@ export class Cipheriv extends Transform implements Cipher {
final(encoding: string = getDefaultEncoding()): Buffer | string {
const buf = new Buffer(16);
const maybeTag = ops.op_node_cipheriv_final(
const maybeTag = op_node_cipheriv_final(
this.#context,
this.#cache.cache,
buf,
@ -200,7 +216,7 @@ export class Cipheriv extends Transform implements Cipher {
plaintextLength: number;
},
): this {
ops.op_node_cipheriv_set_aad(this.#context, buffer);
op_node_cipheriv_set_aad(this.#context, buffer);
return this;
}
@ -223,7 +239,7 @@ export class Cipheriv extends Transform implements Cipher {
let output;
if (!this.#needsBlockCache) {
output = Buffer.allocUnsafe(buf.length);
ops.op_node_cipheriv_encrypt(this.#context, buf, output);
op_node_cipheriv_encrypt(this.#context, buf, output);
return outputEncoding === "buffer"
? output
: output.toString(outputEncoding);
@ -236,7 +252,7 @@ export class Cipheriv extends Transform implements Cipher {
output = Buffer.alloc(0);
} else {
output = Buffer.allocUnsafe(input.length);
ops.op_node_cipheriv_encrypt(this.#context, input, output);
op_node_cipheriv_encrypt(this.#context, input, output);
}
return outputEncoding === "buffer"
? output
@ -311,7 +327,7 @@ export class Decipheriv extends Transform implements Cipher {
...options,
});
this.#cache = new BlockModeCache(true);
this.#context = ops.op_node_create_decipheriv(cipher, toU8(key), toU8(iv));
this.#context = op_node_create_decipheriv(cipher, toU8(key), toU8(iv));
this.#needsBlockCache =
!(cipher == "aes-128-gcm" || cipher == "aes-256-gcm");
if (this.#context == 0) {
@ -321,7 +337,7 @@ export class Decipheriv extends Transform implements Cipher {
final(encoding: string = getDefaultEncoding()): Buffer | string {
let buf = new Buffer(16);
ops.op_node_decipheriv_final(
op_node_decipheriv_final(
this.#context,
this.#cache.cache,
buf,
@ -342,7 +358,7 @@ export class Decipheriv extends Transform implements Cipher {
plaintextLength: number;
},
): this {
ops.op_node_decipheriv_set_aad(this.#context, buffer);
op_node_decipheriv_set_aad(this.#context, buffer);
return this;
}
@ -369,7 +385,7 @@ export class Decipheriv extends Transform implements Cipher {
let output;
if (!this.#needsBlockCache) {
output = Buffer.allocUnsafe(buf.length);
ops.op_node_decipheriv_decrypt(this.#context, buf, output);
op_node_decipheriv_decrypt(this.#context, buf, output);
return outputEncoding === "buffer"
? output
: output.toString(outputEncoding);
@ -381,7 +397,7 @@ export class Decipheriv extends Transform implements Cipher {
output = Buffer.alloc(0);
} else {
output = new Buffer(input.length);
ops.op_node_decipheriv_decrypt(this.#context, input, output);
op_node_decipheriv_decrypt(this.#context, input, output);
}
return outputEncoding === "buffer"
? output
@ -432,7 +448,7 @@ export function privateEncrypt(
const padding = privateKey.padding || 1;
buffer = getArrayBufferOrView(buffer, "buffer");
return ops.op_node_private_encrypt(data, buffer, padding);
return op_node_private_encrypt(data, buffer, padding);
}
export function privateDecrypt(
@ -443,7 +459,7 @@ export function privateDecrypt(
const padding = privateKey.padding || 1;
buffer = getArrayBufferOrView(buffer, "buffer");
return ops.op_node_private_decrypt(data, buffer, padding);
return op_node_private_decrypt(data, buffer, padding);
}
export function publicEncrypt(
@ -454,7 +470,7 @@ export function publicEncrypt(
const padding = publicKey.padding || 1;
buffer = getArrayBufferOrView(buffer, "buffer");
return ops.op_node_public_encrypt(data, buffer, padding);
return op_node_public_encrypt(data, buffer, padding);
}
export function prepareKey(key) {

View file

@ -4,6 +4,18 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_dh_compute_secret,
op_node_dh_generate2,
op_node_ecdh_compute_secret,
op_node_ecdh_generate_keys,
op_node_ecdh_compute_public_key,
} = core.ensureFastOps();
const {
op_node_gen_prime,
} = core.ensureFastOps(true);
import { notImplemented } from "ext:deno_node/_utils.ts";
import {
isAnyArrayBuffer,
@ -33,8 +45,6 @@ import type {
import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts";
import type { BufferEncoding } from "ext:deno_node/_global.d.ts";
const { ops } = Deno.core;
const DH_GENERATOR = 2;
export class DiffieHellman {
@ -92,7 +102,7 @@ export class DiffieHellman {
}
this.#prime = Buffer.from(
ops.op_node_gen_prime(this.#primeLength).buffer,
op_node_gen_prime(this.#primeLength).buffer,
);
}
@ -173,7 +183,7 @@ export class DiffieHellman {
buf = Buffer.from(otherPublicKey.buffer);
}
const sharedSecret = ops.op_node_dh_compute_secret(
const sharedSecret = op_node_dh_compute_secret(
this.#prime,
this.#privateKey,
buf,
@ -190,7 +200,7 @@ export class DiffieHellman {
generateKeys(encoding: BinaryToTextEncoding): string;
generateKeys(_encoding?: BinaryToTextEncoding): Buffer | string {
const generator = this.#checkGenerator();
const [privateKey, publicKey] = ops.op_node_dh_generate2(
const [privateKey, publicKey] = op_node_dh_generate2(
this.#prime,
this.#primeLength ?? 0,
generator,
@ -1215,7 +1225,7 @@ export class ECDH {
): Buffer | string {
const secretBuf = Buffer.alloc(this.#curve.sharedSecretSize);
ops.op_node_ecdh_compute_secret(
op_node_ecdh_compute_secret(
this.#curve.name,
this.#privbuf,
otherPublicKey,
@ -1231,7 +1241,7 @@ export class ECDH {
encoding?: BinaryToTextEncoding,
_format?: ECDHKeyFormat,
): Buffer | string {
ops.op_node_ecdh_generate_keys(
op_node_ecdh_generate_keys(
this.#curve.name,
this.#pubbuf,
this.#privbuf,
@ -1273,7 +1283,7 @@ export class ECDH {
this.#privbuf = privateKey;
this.#pubbuf = Buffer.alloc(this.#curve.publicKeySize);
ops.op_node_ecdh_compute_public_key(
op_node_ecdh_compute_public_key(
this.#curve.name,
this.#privbuf,
this.#pubbuf,

View file

@ -4,6 +4,17 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_create_hash,
op_node_get_hashes,
op_node_hash_clone,
op_node_hash_digest_hex,
op_node_hash_digest,
op_node_hash_update_str,
op_node_hash_update,
} = core.ensureFastOps();
import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { Buffer } from "node:buffer";
import { Transform } from "node:stream";
@ -23,8 +34,6 @@ import {
prepareSecretKey,
} from "ext:deno_node/internal/crypto/keys.ts";
const { ops } = globalThis.__bootstrap.core;
// TODO(@littledivy): Use Result<T, E> instead of boolean when
// https://bugs.chromium.org/p/v8/issues/detail?id=13600 is fixed.
function unwrapErr(ok: boolean) {
@ -65,7 +74,7 @@ export class Hash extends Transform {
) {
super({
transform(chunk: string, _encoding: string, callback: () => void) {
ops.op_node_hash_update(context, coerceToBytes(chunk));
op_node_hash_update(context, coerceToBytes(chunk));
callback();
},
flush(callback: () => void) {
@ -75,7 +84,7 @@ export class Hash extends Transform {
});
if (typeof algorithm === "string") {
this.#context = ops.op_node_create_hash(
this.#context = op_node_create_hash(
algorithm.toLowerCase(),
);
if (this.#context === 0) {
@ -89,7 +98,7 @@ export class Hash extends Transform {
}
copy(): Hash {
return new Hash(ops.op_node_clone_hash(this.#context));
return new Hash(op_node_hash_clone(this.#context));
}
/**
@ -97,9 +106,9 @@ export class Hash extends Transform {
*/
update(data: string | ArrayBuffer, _encoding?: string): this {
if (typeof data === "string") {
unwrapErr(ops.op_node_hash_update_str(this.#context, data));
unwrapErr(op_node_hash_update_str(this.#context, data));
} else {
unwrapErr(ops.op_node_hash_update(this.#context, coerceToBytes(data)));
unwrapErr(op_node_hash_update(this.#context, coerceToBytes(data)));
}
return this;
@ -114,10 +123,10 @@ export class Hash extends Transform {
*/
digest(encoding?: string): Buffer | string {
if (encoding === "hex") {
return ops.op_node_hash_digest_hex(this.#context);
return op_node_hash_digest_hex(this.#context);
}
const digest = ops.op_node_hash_digest(this.#context);
const digest = op_node_hash_digest(this.#context);
if (encoding === undefined) {
return Buffer.from(digest);
}
@ -237,7 +246,7 @@ export function createHash(algorithm: string, opts?: TransformOptions) {
* @returns Array of hash algorithm names.
*/
export function getHashes() {
return ops.op_node_get_hashes();
return op_node_get_hashes();
}
export default {

View file

@ -4,6 +4,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_hkdf,
op_node_hkdf_async,
} = core.ensureFastOps();
import {
validateFunction,
validateInteger,
@ -31,12 +37,6 @@ import {
isArrayBufferView,
} from "ext:deno_node/internal/util/types.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
const {
op_node_hkdf_async,
} = core.ensureFastOps();
const validateParameters = hideStackFrames((hash, key, salt, info, length) => {
validateString(hash, "digest");
key = new Uint8Array(prepareKey(key));
@ -134,7 +134,7 @@ export function hkdfSync(
const okm = new Uint8Array(length);
try {
ops.op_node_hkdf(hash, key, salt, info, okm);
op_node_hkdf(hash, key, salt, info, okm);
} catch (e) {
throw new ERR_CRYPTO_INVALID_DIGEST(e);
}

View file

@ -29,18 +29,27 @@ import {
import { Buffer } from "node:buffer";
import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
import { core } from "ext:core/mod.js";
const {
op_node_dh_generate,
op_node_dh_generate_async,
op_node_dh_generate_group,
op_node_dh_generate_group_async,
op_node_dsa_generate,
op_node_dsa_generate_async,
op_node_ec_generate,
op_node_ec_generate_async,
op_node_generate_rsa_async,
op_node_generate_secret_async,
op_node_ed25519_generate,
op_node_ed25519_generate_async,
op_node_generate_rsa,
op_node_generate_rsa_async,
op_node_x25519_generate,
op_node_x25519_generate_async,
} = core.ensureFastOps();
const {
op_node_generate_secret,
op_node_generate_secret_async,
} = core.ensureFastOps(true);
function validateGenerateKey(
type: "hmac" | "aes",
@ -75,7 +84,7 @@ export function generateKeySync(
const { length } = options;
const key = new Uint8Array(Math.floor(length / 8));
ops.op_node_generate_secret(key);
op_node_generate_secret(key);
return new SecretKeyObject(setOwnedKey(key));
}
@ -804,7 +813,7 @@ function createJob(mode, type, options) {
if (type === "rsa") {
if (mode === kSync) {
return ops.op_node_generate_rsa(
return op_node_generate_rsa(
modulusLength,
publicExponent,
);
@ -859,7 +868,7 @@ function createJob(mode, type, options) {
}
if (mode === kSync) {
return ops.op_node_generate_rsa(
return op_node_generate_rsa(
modulusLength,
publicExponent,
);
@ -883,7 +892,7 @@ function createJob(mode, type, options) {
}
if (mode === kSync) {
return ops.op_node_dsa_generate(modulusLength, divisorLength);
return op_node_dsa_generate(modulusLength, divisorLength);
}
return op_node_dsa_generate_async(
modulusLength,
@ -905,20 +914,20 @@ function createJob(mode, type, options) {
}
if (mode === kSync) {
return ops.op_node_ec_generate(namedCurve);
return op_node_ec_generate(namedCurve);
} else {
return op_node_ec_generate_async(namedCurve);
}
}
case "ed25519": {
if (mode === kSync) {
return ops.op_node_ed25519_generate();
return op_node_ed25519_generate();
}
return op_node_ed25519_generate_async();
}
case "x25519": {
if (mode === kSync) {
return ops.op_node_x25519_generate();
return op_node_x25519_generate();
}
return op_node_x25519_generate_async();
}
@ -944,7 +953,7 @@ function createJob(mode, type, options) {
validateString(group, "options.group");
if (mode === kSync) {
return ops.op_node_dh_generate_group(group);
return op_node_dh_generate_group(group);
} else {
return op_node_dh_generate_group_async(group);
}
@ -971,7 +980,7 @@ function createJob(mode, type, options) {
const g = generator == null ? 2 : generator;
if (mode === kSync) {
return ops.op_node_dh_generate(prime, primeLength ?? 0, g);
return op_node_dh_generate(prime, primeLength ?? 0, g);
} else {
return op_node_dh_generate_async(
prime,

View file

@ -4,6 +4,11 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_create_private_key,
} = core.ensureFastOps();
import {
kHandle,
kKeyObject,
@ -39,9 +44,6 @@ import {
forgivingBase64UrlEncode as encodeToBase64Url,
} from "ext:deno_web/00_infra.js";
const { core } = globalThis.__bootstrap;
const { ops } = core;
export const getArrayBufferOrView = hideStackFrames(
(
buffer,
@ -234,7 +236,7 @@ export function createPrivateKey(
key: PrivateKeyInput | string | Buffer | JsonWebKeyInput,
): PrivateKeyObject {
const { data, format, type } = prepareAsymmetricKey(key);
const details = ops.op_node_create_private_key(data, format, type);
const details = op_node_create_private_key(data, format, type);
const handle = setOwnedKey(copyBuffer(data));
return new PrivateKeyObject(handle, details);
}

View file

@ -3,13 +3,15 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_pbkdf2,
op_node_pbkdf2_async,
} = core.ensureFastOps();
import { Buffer } from "node:buffer";
import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
const { op_node_pbkdf2_async } = core.ensureFastOps();
export const MAX_ALLOC = Math.pow(2, 30) - 1;
export type NormalizedAlgorithms =
@ -51,7 +53,7 @@ export function pbkdf2Sync(
}
const DK = new Uint8Array(keylen);
if (!ops.op_node_pbkdf2(password, salt, iterations, digest, DK)) {
if (!op_node_pbkdf2(password, salt, iterations, digest, DK)) {
throw new Error("Invalid digest");
}

View file

@ -4,6 +4,22 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core, primordials } from "ext:core/mod.js";
const {
op_node_check_prime,
op_node_check_prime_async,
op_node_check_prime_bytes,
op_node_check_prime_bytes_async,
op_node_gen_prime_async,
} = core.ensureFastOps();
const {
op_node_gen_prime,
} = core.ensureFastOps(true);
const {
StringPrototypePadStart,
StringPrototypeToString,
} = primordials;
import { notImplemented } from "ext:deno_node/_utils.ts";
import randomBytes from "ext:deno_node/internal/crypto/_randomBytes.ts";
import randomFill, {
@ -32,17 +48,6 @@ export {
} from "ext:deno_node/internal/crypto/_randomFill.mjs";
export { default as randomInt } from "ext:deno_node/internal/crypto/_randomInt.ts";
import { primordials } from "ext:core/mod.js";
const { StringPrototypePadStart, StringPrototypeToString } = primordials;
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.ensureFastOps();
export type LargeNumberLike =
| ArrayBufferView
| SharedArrayBuffer
@ -129,7 +134,7 @@ export function checkPrimeSync(
validateInt32(checks, "options.checks", 0);
if (typeof candidate === "bigint") {
return ops.op_node_check_prime(candidate, checks);
return op_node_check_prime(candidate, checks);
} else if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) {
throw new ERR_INVALID_ARG_TYPE(
"candidate",
@ -144,7 +149,7 @@ export function checkPrimeSync(
);
}
return ops.op_node_check_prime_bytes(candidate, checks);
return op_node_check_prime_bytes(candidate, checks);
}
export interface GeneratePrimeOptions {
@ -186,7 +191,7 @@ export function generatePrimeSync(
bigint,
} = validateRandomPrimeJob(size, options);
const prime = ops.op_node_gen_prime(size);
const prime = op_node_gen_prime(size);
if (bigint) return arrayBufferToUnsignedBigInt(prime.buffer);
return prime.buffer;
}

View file

@ -29,9 +29,9 @@ SOFTWARE.
import { Buffer } from "node:buffer";
import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
import { core } from "ext:core/mod.js";
const {
op_node_scrypt_sync,
op_node_scrypt_async,
} = core.ensureFastOps();
@ -78,7 +78,7 @@ export function scryptSync(
}
const buf = Buffer.alloc(keylen);
ops.op_node_scrypt_sync(
op_node_scrypt_sync(
password,
salt,
keylen,

View file

@ -4,6 +4,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_sign,
op_node_verify,
} = core.ensureFastOps();
import { notImplemented } from "ext:deno_node/_utils.ts";
import {
validateFunction,
@ -28,9 +34,6 @@ import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { ERR_CRYPTO_SIGN_KEY_REQUIRED } from "ext:deno_node/internal/errors.ts";
const { core } = globalThis.__bootstrap;
const { ops } = core;
export type DSAEncoding = "der" | "ieee-p1363";
export interface SigningOptions {
@ -81,7 +84,7 @@ export class SignImpl extends Writable {
encoding?: BinaryToTextEncoding,
): Buffer | string {
const { data, format, type } = prepareAsymmetricKey(privateKey);
const ret = Buffer.from(ops.op_node_sign(
const ret = Buffer.from(op_node_sign(
this.hash.digest(),
this.#digestType,
data!,
@ -157,7 +160,7 @@ export class VerifyImpl extends Writable {
"crypto.Verify.prototype.verify with non BinaryLike input",
);
}
return ops.op_node_verify(
return op_node_verify(
this.hash.digest(),
this.#digestType,
keyData!,

View file

@ -4,6 +4,22 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_node_x509_ca,
op_node_x509_check_email,
op_node_x509_fingerprint,
op_node_x509_fingerprint256,
op_node_x509_fingerprint512,
op_node_x509_get_issuer,
op_node_x509_get_serial_number,
op_node_x509_get_subject,
op_node_x509_get_valid_from,
op_node_x509_get_valid_to,
op_node_x509_key_usage,
op_node_x509_parse,
} = core.ensureFastOps();
import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts";
import { Buffer } from "node:buffer";
import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts";
@ -12,8 +28,6 @@ import { validateString } from "ext:deno_node/internal/validators.mjs";
import { notImplemented } from "ext:deno_node/_utils.ts";
import { BinaryLike } from "ext:deno_node/internal/crypto/types.ts";
const { ops } = globalThis.__bootstrap.core;
// deno-lint-ignore no-explicit-any
export type PeerCertificate = any;
@ -56,11 +70,11 @@ export class X509Certificate {
);
}
this.#handle = ops.op_node_x509_parse(buffer);
this.#handle = op_node_x509_parse(buffer);
}
get ca(): boolean {
return ops.op_node_x509_ca(this.#handle);
return op_node_x509_ca(this.#handle);
}
checkEmail(
@ -68,7 +82,7 @@ export class X509Certificate {
_options?: Pick<X509CheckOptions, "subject">,
): string | undefined {
validateString(email, "email");
if (ops.op_node_x509_check_email(this.#handle, email)) {
if (op_node_x509_check_email(this.#handle, email)) {
return email;
}
}
@ -90,15 +104,15 @@ export class X509Certificate {
}
get fingerprint(): string {
return ops.op_node_x509_fingerprint(this.#handle);
return op_node_x509_fingerprint(this.#handle);
}
get fingerprint256(): string {
return ops.op_node_x509_fingerprint256(this.#handle);
return op_node_x509_fingerprint256(this.#handle);
}
get fingerprint512(): string {
return ops.op_node_x509_fingerprint512(this.#handle);
return op_node_x509_fingerprint512(this.#handle);
}
get infoAccess(): string | undefined {
@ -108,7 +122,7 @@ export class X509Certificate {
}
get issuer(): string {
return ops.op_node_x509_get_issuer(this.#handle);
return op_node_x509_get_issuer(this.#handle);
}
get issuerCertificate(): X509Certificate | undefined {
@ -116,7 +130,7 @@ export class X509Certificate {
}
get keyUsage(): string[] | undefined {
const flags = ops.op_node_x509_key_usage(this.#handle);
const flags = op_node_x509_key_usage(this.#handle);
if (flags === 0) return undefined;
const result: string[] = [];
if (flags & 0x01) result.push("DigitalSignature");
@ -144,11 +158,11 @@ export class X509Certificate {
}
get serialNumber(): string {
return ops.op_node_x509_get_serial_number(this.#handle);
return op_node_x509_get_serial_number(this.#handle);
}
get subject(): string {
return ops.op_node_x509_get_subject(this.#handle);
return op_node_x509_get_subject(this.#handle);
}
get subjectAltName(): string | undefined {
@ -168,11 +182,11 @@ export class X509Certificate {
}
get validFrom(): string {
return ops.op_node_x509_get_valid_from(this.#handle);
return op_node_x509_get_valid_from(this.#handle);
}
get validTo(): string {
return ops.op_node_x509_get_valid_to(this.#handle);
return op_node_x509_get_valid_to(this.#handle);
}
verify(_publicKey: KeyObject): boolean {

View file

@ -1,8 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { arch, versions } from "ext:deno_node/_process/process.ts";
import { cpus, hostname, networkInterfaces } from "node:os";
import { primordials } from "ext:core/mod.js";
const {
Error,
@ -13,6 +10,9 @@ const {
DatePrototypeGetTime,
} = primordials;
import { arch, versions } from "ext:deno_node/_process/process.ts";
import { cpus, hostname, networkInterfaces } from "node:os";
function writeReport(_filename: string, _err: typeof Error) {
return "";
}

View file

@ -4,17 +4,17 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { codes } from "ext:deno_node/internal/error_codes.ts";
import { hideStackFrames } from "ext:deno_node/internal/hide_stack_frames.ts";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { normalizeEncoding } from "ext:deno_node/internal/normalize_encoding.mjs";
import { primordials } from "ext:core/mod.js";
const {
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
} = primordials;
import { codes } from "ext:deno_node/internal/error_codes.ts";
import { hideStackFrames } from "ext:deno_node/internal/hide_stack_frames.ts";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { normalizeEncoding } from "ext:deno_node/internal/normalize_encoding.mjs";
/**
* @param {number} value
* @returns {boolean}

View file

@ -1,7 +1,10 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
const { ops } = globalThis.__bootstrap.core;
import { core } from "ext:core/mod.js";
const {
op_node_sys_to_uv_error,
} = core.ensureFastOps();
export function uvTranslateSysError(sysErrno: number): string {
return ops.op_node_sys_to_uv_error(sysErrno);
return op_node_sys_to_uv_error(sysErrno);
}

View file

@ -1,4 +1,10 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
const {
op_node_build_os,
} = core.ensureFastOps(true);
let os: {
dlopen: {
RTLD_DEEPBIND?: number;
@ -196,8 +202,7 @@ let os: {
UV_UDP_REUSEADDR: number;
};
const core = globalThis.__bootstrap.core;
const buildOs = core.ops.op_node_build_os();
const buildOs = op_node_build_os();
if (buildOs === "darwin") {
os = {
UV_UDP_REUSEADDR: 4,

View file

@ -30,6 +30,12 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_can_write_vectored,
op_raw_write_vectored,
} = core.ensureFastOps();
import { TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { Buffer } from "node:buffer";
import { notImplemented } from "ext:deno_node/_utils.ts";
@ -40,9 +46,6 @@ import {
} from "ext:deno_node/internal_binding/async_wrap.ts";
import { codeMap } from "ext:deno_node/internal_binding/uv.ts";
import { core } from "ext:core/mod.js";
const { ops } = core;
interface Reader {
read(p: Uint8Array): Promise<number | null>;
}
@ -204,13 +207,13 @@ export class LibuvStreamWrap extends HandleWrap {
// Fast case optimization: two chunks, and all buffers.
if (
chunks.length === 2 && allBuffers && supportsWritev &&
ops.op_can_write_vectored(rid)
op_can_write_vectored(rid)
) {
// String chunks.
if (typeof chunks[0] === "string") chunks[0] = Buffer.from(chunks[0]);
if (typeof chunks[1] === "string") chunks[1] = Buffer.from(chunks[1]);
ops.op_raw_write_vectored(
op_raw_write_vectored(
rid,
chunks[0],
chunks[1],

View file

@ -24,7 +24,11 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_node_unstable_net_listen_udp,
op_node_unstable_net_listen_unixpacket,
} = core.ensureFastOps();
import {
AsyncWrap,
providerType,
@ -41,8 +45,8 @@ import * as net from "ext:deno_net/01_net.js";
import { isLinux, isWindows } from "ext:deno_node/_util/os.ts";
const DenoListenDatagram = net.createListenDatagram(
ops.op_node_unstable_net_listen_udp,
ops.op_node_unstable_net_listen_unixpacket,
op_node_unstable_net_listen_udp,
op_node_unstable_net_listen_unixpacket,
);
type MessageType = string | Uint8Array | Buffer | DataView;

View file

@ -29,11 +29,13 @@
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_node_guess_handle_type,
} = core.ensureFastOps();
const handleTypes = ["TCP", "TTY", "UDP", "FILE", "PIPE", "UNKNOWN"];
export function guessHandleType(fd: number): string {
const type = ops.op_node_guess_handle_type(fd);
const type = op_node_guess_handle_type(fd);
return handleTypes[type];
}

View file

@ -23,7 +23,14 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
const core = globalThis.__bootstrap.core;
import { core } from "ext:core/mod.js";
const {
op_cpus,
op_node_os_get_priority,
op_node_os_set_priority,
op_node_os_username,
} = core.ensureFastOps();
import { validateIntegerRange } from "ext:deno_node/_utils.ts";
import process from "node:process";
import { isWindows, osType } from "ext:deno_node/_util/os.ts";
@ -32,8 +39,6 @@ import { os } from "ext:deno_node/internal_binding/constants.ts";
import { osUptime } from "ext:runtime/30_os.js";
import { Buffer } from "ext:deno_node/internal/buffer.mjs";
const ops = core.ops;
export const constants = os;
interface CPUTimes {
@ -133,7 +138,7 @@ export function arch(): string {
(machine as any)[Symbol.toPrimitive] = (): string => machine();
export function cpus(): CPUCoreInfo[] {
return ops.op_cpus();
return op_cpus();
}
/**
@ -164,7 +169,7 @@ export function freemem(): number {
/** Not yet implemented */
export function getPriority(pid = 0): number {
validateIntegerRange(pid, "pid");
return core.ops.op_node_os_get_priority(pid);
return op_node_os_get_priority(pid);
}
/** Returns the string path of the current user's home directory. */
@ -270,7 +275,7 @@ export function setPriority(pid: number, priority?: number) {
validateIntegerRange(pid, "pid");
validateIntegerRange(priority, "priority", -20, 19);
core.ops.op_node_os_set_priority(pid, priority);
op_node_os_set_priority(pid, priority);
}
/** Returns the operating system's default directory for temporary files as a string. */
@ -350,7 +355,7 @@ export function userInfo(
throw new ERR_OS_NO_HOMEDIR();
}
let shell = isWindows ? (Deno.env.get("SHELL") || null) : null;
let username = core.ops.op_node_os_username();
let username = op_node_os_username();
if (options?.encoding === "buffer") {
_homedir = _homedir ? Buffer.from(_homedir) : _homedir;

View file

@ -4,9 +4,15 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
const internals = globalThis.__bootstrap.internals;
const { core } = globalThis.__bootstrap;
const { ops } = core;
import { core, internals } from "ext:core/mod.js";
const {
op_process_abort,
op_geteuid,
} = core.ensureFastOps();
const {
op_set_exit_code,
} = core.ensureFastOps(true);
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
import { EventEmitter } from "node:events";
import Module from "node:module";
@ -99,7 +105,7 @@ export const exit = (code?: number | string) => {
};
export const abort = () => {
ops.op_process_abort();
op_process_abort();
};
function addReadOnlyProcessAlias(
@ -440,7 +446,7 @@ class Process extends EventEmitter {
globalProcessExitCode = code;
code = parseInt(code) || 0;
if (!isNaN(code)) {
ops.op_set_exit_code(code);
op_set_exit_code(code);
}
}
@ -676,7 +682,7 @@ class Process extends EventEmitter {
/** This method is removed on Windows */
geteuid?(): number {
return ops.op_geteuid();
return op_geteuid();
}
// TODO(kt3k): Implement this when we added -e option to node compat mode

View file

@ -1,23 +1,29 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
const {
op_node_idna_domain_to_unicode,
op_node_idna_punycode_decode,
op_node_idna_punycode_encode,
op_node_idna_domain_to_ascii,
} = core.ensureFastOps();
import { ucs2 } from "ext:deno_node/internal/idna.ts";
const { ops } = globalThis.__bootstrap.core;
function toASCII(domain) {
return ops.op_node_idna_domain_to_ascii(domain);
return op_node_idna_domain_to_ascii(domain);
}
function toUnicode(domain) {
return ops.op_node_idna_domain_to_unicode(domain);
return op_node_idna_domain_to_unicode(domain);
}
function decode(domain) {
return ops.op_node_idna_punycode_decode(domain);
return op_node_idna_punycode_decode(domain);
}
function encode(domain) {
return ops.op_node_idna_punycode_encode(domain);
return op_node_idna_punycode_encode(domain);
}
export { decode, encode, toASCII, toUnicode, ucs2 };

View file

@ -1,11 +1,15 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { primordials } from "ext:core/mod.js";
const {
Error,
} = primordials;
import { ERR_INVALID_FD } from "ext:deno_node/internal/errors.ts";
import { LibuvStreamWrap } from "ext:deno_node/internal_binding/stream_wrap.ts";
import { providerType } from "ext:deno_node/internal_binding/async_wrap.ts";
import { Socket } from "node:net";
import { setReadStream } from "ext:deno_node/_process/streams.mjs";
const { Error } = globalThis.__bootstrap.primordials;
// Returns true when the given numeric fd is associated with a TTY and false otherwise.
function isatty(fd) {

View file

@ -1,21 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { promisify } from "ext:deno_node/internal/util.mjs";
import { callbackify } from "ext:deno_node/_util/_util_callbackify.ts";
import { debuglog } from "ext:deno_node/internal/util/debuglog.ts";
import {
format,
formatWithOptions,
inspect,
stripVTControlCharacters,
} from "ext:deno_node/internal/util/inspect.mjs";
import { codes } from "ext:deno_node/internal/error_codes.ts";
import types from "node:util/types";
import { Buffer } from "node:buffer";
import { isDeepStrictEqual } from "ext:deno_node/internal/util/comparisons.ts";
import process from "node:process";
import { validateString } from "ext:deno_node/internal/validators.mjs";
import { parseArgs } from "ext:deno_node/internal/util/parse_args/parse_args.js";
import { primordials } from "ext:core/mod.js";
const {
ArrayIsArray,
@ -43,6 +27,23 @@ const {
StringPrototypeToWellFormed,
} = primordials;
import { promisify } from "ext:deno_node/internal/util.mjs";
import { callbackify } from "ext:deno_node/_util/_util_callbackify.ts";
import { debuglog } from "ext:deno_node/internal/util/debuglog.ts";
import {
format,
formatWithOptions,
inspect,
stripVTControlCharacters,
} from "ext:deno_node/internal/util/inspect.mjs";
import { codes } from "ext:deno_node/internal/error_codes.ts";
import types from "node:util/types";
import { Buffer } from "node:buffer";
import { isDeepStrictEqual } from "ext:deno_node/internal/util/comparisons.ts";
import process from "node:process";
import { validateString } from "ext:deno_node/internal/validators.mjs";
import { parseArgs } from "ext:deno_node/internal/util/parse_args/parse_args.js";
export {
callbackify,
debuglog,

View file

@ -4,12 +4,16 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core } from "ext:core/mod.js";
const {
op_v8_cached_data_version_tag,
op_v8_get_heap_statistics,
} = core.ensureFastOps();
import { notImplemented } from "ext:deno_node/_utils.ts";
const { ops } = globalThis.__bootstrap.core;
export function cachedDataVersionTag() {
return ops.op_v8_cached_data_version_tag();
return op_v8_cached_data_version_tag();
}
export function getHeapCodeStatistics() {
notImplemented("v8.getHeapCodeStatistics");
@ -24,7 +28,7 @@ export function getHeapSpaceStatistics() {
const buffer = new Float64Array(14);
export function getHeapStatistics() {
ops.op_v8_get_heap_statistics(buffer);
op_v8_get_heap_statistics(buffer);
return {
total_heap_size: buffer[0],

View file

@ -3,10 +3,11 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file no-explicit-any prefer-primordials
import { core } from "ext:core/mod.js";
import { notImplemented } from "ext:deno_node/_utils.ts";
const { core } = globalThis.__bootstrap;
const ops = core.ops;
const {
op_vm_run_in_new_context,
} = core.ensureFastOps();
export class Script {
code: string;
@ -32,7 +33,7 @@ export class Script {
"Script.runInNewContext options are currently not supported",
);
}
return ops.op_vm_run_in_new_context(this.code, contextObject);
return op_vm_run_in_new_context(this.code, contextObject);
}
createCachedData() {
@ -64,7 +65,7 @@ export function runInNewContext(
if (options) {
console.warn("vm.runInNewContext options are currently not supported");
}
return ops.op_vm_run_in_new_context(code, contextObject);
return op_vm_run_in_new_context(code, contextObject);
}
export function runInThisContext(

View file

@ -4,6 +4,11 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { core, internals } from "ext:core/mod.js";
const {
op_require_read_closest_package_json,
} = core.ensureFastOps(true);
import { isAbsolute, resolve } from "node:path";
import { notImplemented } from "ext:deno_node/_utils.ts";
import { EventEmitter, once } from "node:events";
@ -12,7 +17,6 @@ import { MessageChannel, MessagePort } from "ext:deno_web/13_message_port.js";
let environmentData = new Map();
let threads = 0;
const { core } = globalThis.__bootstrap;
export interface WorkerOptions {
// only for typings
@ -120,7 +124,7 @@ class _Worker extends EventEmitter {
specifier = resolve(specifier);
let pkg;
try {
pkg = core.ops.op_require_read_closest_package_json(specifier);
pkg = op_require_read_closest_package_json(specifier);
} catch (_) {
// empty catch block when package json might not be present
}
@ -203,7 +207,7 @@ type ParentPort = typeof self & NodeEventTarget;
// deno-lint-ignore no-explicit-any
let parentPort: ParentPort = null as any;
globalThis.__bootstrap.internals.__initWorkerThreads = () => {
internals.__initWorkerThreads = () => {
isMainThread =
// deno-lint-ignore no-explicit-any
(globalThis as any).name !== PRIVATE_WORKER_THREAD_NAME;

View file

@ -6,9 +6,14 @@
/// <reference path="../webidl/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
op_url_get_serialization,
op_url_parse,
op_url_parse_search_params,
op_url_parse_with_base,
op_url_reparse,
op_url_stringify_search_params,
} = core.ensureFastOps();
const {
ArrayIsArray,
ArrayPrototypeMap,
@ -28,6 +33,9 @@ const {
Uint32Array,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const _list = Symbol("list");
const _urlObject = Symbol("url object");
@ -50,7 +58,7 @@ const SET_USERNAME = 8;
* @returns {string}
*/
function opUrlReparse(href, setter, value) {
const status = ops.op_url_reparse(
const status = op_url_reparse(
href,
setter,
value,
@ -66,9 +74,9 @@ function opUrlReparse(href, setter, value) {
*/
function opUrlParse(href, maybeBase) {
if (maybeBase === undefined) {
return ops.op_url_parse(href, componentsBuf);
return op_url_parse(href, componentsBuf);
}
return ops.op_url_parse_with_base(
return op_url_parse_with_base(
href,
maybeBase,
componentsBuf,
@ -85,7 +93,7 @@ function getSerialization(status, href, maybeBase) {
if (status === 0) {
return href;
} else if (status === 1) {
return ops.op_url_get_serialization();
return op_url_get_serialization();
} else {
throw new TypeError(
`Invalid URL: '${href}'` +
@ -123,7 +131,7 @@ class URLSearchParams {
if (init[0] == "?") {
init = StringPrototypeSlice(init, 1);
}
this[_list] = ops.op_url_parse_search_params(init);
this[_list] = op_url_parse_search_params(init);
} else if (ArrayIsArray(init)) {
// Overload: sequence<sequence<USVString>>
this[_list] = ArrayPrototypeMap(init, (pair, i) => {
@ -314,7 +322,7 @@ class URLSearchParams {
*/
toString() {
webidl.assertBranded(this, URLSearchParamsPrototype);
return ops.op_url_stringify_search_params(this[_list]);
return op_url_stringify_search_params(this[_list]);
}
get size() {
@ -436,7 +444,7 @@ class URL {
#updateSearchParams() {
if (this.#queryObject !== null) {
const params = this.#queryObject[_list];
const newParams = ops.op_url_parse_search_params(
const newParams = op_url_parse_search_params(
StringPrototypeSlice(this.search, 1),
);
ArrayPrototypeSplice(
@ -823,7 +831,7 @@ const URLPrototype = URL.prototype;
* @returns {[string, string][]}
*/
function parseUrlEncoded(bytes) {
return ops.op_url_parse_search_params(null, bytes);
return op_url_parse_search_params(null, bytes);
}
webidl

View file

@ -8,9 +8,10 @@
/// <reference path="./lib.deno_url.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
op_urlpattern_parse,
op_urlpattern_process_match_input,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
MathRandom,
@ -26,6 +27,9 @@ const {
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const _components = Symbol("components");
/**
@ -152,7 +156,7 @@ class URLPattern {
baseURL = webidl.converters.USVString(baseURL, prefix, "Argument 2");
}
const components = ops.op_urlpattern_parse(input, baseURL);
const components = op_urlpattern_parse(input, baseURL);
for (let i = 0; i < COMPONENTS_KEYS.length; ++i) {
const key = COMPONENTS_KEYS[i];
@ -225,9 +229,9 @@ class URLPattern {
const res = baseURL === undefined
? matchInputCache.getOrInsert(
input,
ops.op_urlpattern_process_match_input,
op_urlpattern_process_match_input,
)
: ops.op_urlpattern_process_match_input(input, baseURL);
: op_urlpattern_process_match_input(input, baseURL);
if (res === null) return false;
const values = res[0];
@ -267,9 +271,9 @@ class URLPattern {
const res = baseURL === undefined
? matchInputCache.getOrInsert(
input,
ops.op_urlpattern_process_match_input,
op_urlpattern_process_match_input,
)
: ops.op_urlpattern_process_match_input(input, baseURL);
: op_urlpattern_process_match_input(input, baseURL);
if (res === null) {
return null;
}

View file

@ -7,7 +7,10 @@
/// <reference path="../web/lib.deno_web.d.ts" />
import { core, internals, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_base64_encode,
op_base64_decode,
} = core.ensureFastOps();
const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
@ -33,6 +36,7 @@ const {
Symbol,
TypeError,
} = primordials;
import { URLPrototype } from "ext:deno_url/00_url.js";
const ASCII_DIGIT = ["\u0030-\u0039"];
@ -245,7 +249,7 @@ function collectHttpQuotedString(input, position, extractValue) {
* @returns {string}
*/
function forgivingBase64Encode(data) {
return ops.op_base64_encode(data);
return op_base64_encode(data);
}
/**
@ -253,7 +257,7 @@ function forgivingBase64Encode(data) {
* @returns {Uint8Array}
*/
function forgivingBase64Decode(data) {
return ops.op_base64_decode(data);
return op_base64_decode(data);
}
// Taken from std/encoding/base64url.ts

View file

@ -20,6 +20,7 @@ const {
Symbol,
SymbolFor,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";

View file

@ -19,6 +19,7 @@ const {
StringPrototypeReplaceAll,
StringPrototypeToLowerCase,
} = primordials;
import {
collectHttpQuotedString,
collectSequenceOfCodepoints,

View file

@ -6,9 +6,6 @@
// and impossible logic branches based on what Deno currently supports.
import { core, primordials } from "ext:core/mod.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
@ -37,6 +34,10 @@ const {
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
// This should be set via setGlobalThis this is required so that if even
// user deletes globalThis it is still usable
let globalThis_;

View file

@ -7,7 +7,9 @@
/// <reference path="../web/lib.deno_web.d.ts" />
import { core, primordials } from "ext:core/mod.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
isArrayBuffer,
} = core;
const {
ArrayBuffer,
ArrayBufferPrototypeGetByteLength,
@ -37,9 +39,8 @@ const {
Float32Array,
Float64Array,
} = primordials;
const {
isArrayBuffer,
} = core;
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const objectCloneMemo = new SafeWeakMap();

View file

@ -1,7 +1,12 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_now,
op_sleep,
op_timer_handle,
op_void_async_deferred,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
ArrayPrototypeShift,
@ -19,15 +24,15 @@ const {
TypeError,
indirectEval,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { reportException } from "ext:deno_web/02_event.js";
import { assert } from "ext:deno_web/00_infra.js";
const { op_sleep, op_void_async_deferred } = core.ensureFastOps();
const hrU8 = new Uint8Array(8);
const hr = new Uint32Array(TypedArrayPrototypeGetBuffer(hrU8));
function opNow() {
ops.op_now(hrU8);
op_now(hrU8);
return (hr[0] * 1000 + hr[1] / 1e6);
}
@ -111,7 +116,7 @@ function initializeTimer(
// TODO(@andreubotella): Deal with overflow.
// https://github.com/whatwg/html/issues/7358
id = nextId++;
const cancelRid = ops.op_timer_handle();
const cancelRid = op_timer_handle();
timerInfo = { cancelRid, isRef: true, promise: null };
// Step 4 in "run steps after a timeout".

View file

@ -3,16 +3,6 @@
// @ts-check
/// <reference path="../../core/internal.d.ts" />
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { assert } from "ext:deno_web/00_infra.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import {
defineEventHandler,
Event,
EventTarget,
listenerCount,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { primordials } from "ext:core/mod.js";
const {
ArrayPrototypeEvery,
@ -32,6 +22,17 @@ const {
WeakSetPrototypeAdd,
WeakSetPrototypeHas,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { assert } from "ext:deno_web/00_infra.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import {
defineEventHandler,
Event,
EventTarget,
listenerCount,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { refTimer, setTimeout, unrefTimer } from "ext:deno_web/02_timers.js";
// Since WeakSet is not a iterable, WeakRefSet class is provided to store and

View file

@ -7,14 +7,18 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
op_base64_atob,
op_base64_btoa,
} = core.ensureFastOps();
const {
ObjectPrototypeIsPrototypeOf,
TypeErrorPrototype,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
/**
* @param {string} data
* @returns {string}
@ -24,7 +28,7 @@ function atob(data) {
webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.DOMString(data, prefix, "Argument 1");
try {
return ops.op_base64_atob(data);
return op_base64_atob(data);
} catch (e) {
if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {
throw new DOMException(
@ -45,7 +49,7 @@ function btoa(data) {
webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.DOMString(data, prefix, "Argument 1");
try {
return ops.op_base64_btoa(data);
return op_base64_btoa(data);
} catch (e) {
if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {
throw new DOMException(

View file

@ -7,6 +7,12 @@
/// <reference lib="esnext" />
import { core, internals, primordials } from "ext:core/mod.js";
const {
isAnyArrayBuffer,
isArrayBuffer,
isSharedArrayBuffer,
isTypedArray,
} = core;
const {
op_arraybuffer_was_detached,
op_transfer_arraybuffer,
@ -19,20 +25,10 @@ const {
op_readable_stream_resource_close,
op_readable_stream_resource_await_close,
} = core.ensureFastOps();
// TODO(mmastrac): use readAll
const {
// TODO(mmastrac): use readAll
op_read_all,
} = core.ensureFastOps(true);
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { structuredClone } from "ext:deno_web/02_structured_clone.js";
import {
AbortSignalPrototype,
add,
newSignal,
remove,
signalAbort,
} from "ext:deno_web/03_abort_signal.js";
const {
ArrayBuffer,
ArrayBufferIsView,
@ -95,12 +91,17 @@ const {
WeakMapPrototypeSet,
queueMicrotask,
} = primordials;
const {
isAnyArrayBuffer,
isArrayBuffer,
isSharedArrayBuffer,
isTypedArray,
} = core;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { structuredClone } from "ext:deno_web/02_structured_clone.js";
import {
AbortSignalPrototype,
add,
newSignal,
remove,
signalAbort,
} from "ext:deno_web/03_abort_signal.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { assert, AssertionError } from "ext:deno_web/00_infra.js";

View file

@ -10,9 +10,19 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
isDataView,
isSharedArrayBuffer,
isTypedArray,
} = core;
const {
op_encoding_decode,
op_encoding_decode_single,
op_encoding_decode_utf8,
op_encoding_encode_into,
op_encoding_new_decoder,
op_encoding_normalize_label,
} = core.ensureFastOps();
const {
DataViewPrototypeGetBuffer,
DataViewPrototypeGetByteLength,
@ -32,11 +42,9 @@ const {
Uint32Array,
Uint8Array,
} = primordials;
const {
isDataView,
isSharedArrayBuffer,
isTypedArray,
} = core;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
class TextDecoder {
/** @type {string} */
@ -63,7 +71,7 @@ class TextDecoder {
prefix,
"Argument 2",
);
const encoding = ops.op_encoding_normalize_label(label);
const encoding = op_encoding_normalize_label(label);
this.#encoding = encoding;
this.#fatal = options.fatal;
this.#ignoreBOM = options.ignoreBOM;
@ -154,10 +162,10 @@ class TextDecoder {
if (!stream && this.#rid === null) {
// Fast path for utf8 single pass encoding.
if (this.#utf8SinglePass) {
return ops.op_encoding_decode_utf8(input, this.#ignoreBOM);
return op_encoding_decode_utf8(input, this.#ignoreBOM);
}
return ops.op_encoding_decode_single(
return op_encoding_decode_single(
input,
this.#encoding,
this.#fatal,
@ -166,13 +174,13 @@ class TextDecoder {
}
if (this.#rid === null) {
this.#rid = ops.op_encoding_new_decoder(
this.#rid = op_encoding_new_decoder(
this.#encoding,
this.#fatal,
this.#ignoreBOM,
);
}
return ops.op_encoding_decode(input, this.#rid, stream);
return op_encoding_decode(input, this.#rid, stream);
} finally {
if (!stream && this.#rid !== null) {
core.close(this.#rid);
@ -246,7 +254,7 @@ class TextEncoder {
allowShared: true,
},
);
ops.op_encoding_encode_into(source, destination, encodeIntoBuf);
op_encoding_encode_into(source, destination, encodeIntoBuf);
return {
read: encodeIntoBuf[0],
written: encodeIntoBuf[1],

View file

@ -11,10 +11,21 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { ReadableStream } from "ext:deno_web/06_streams.js";
import { URL } from "ext:deno_url/00_url.js";
const {
isAnyArrayBuffer,
isArrayBuffer,
isDataView,
isTypedArray,
} = core;
const {
op_blob_create_object_url,
op_blob_create_part,
op_blob_from_object_url,
op_blob_read_part,
op_blob_remove_part,
op_blob_revoke_object_url,
op_blob_slice_part,
} = core.ensureFastOps();
const {
ArrayBufferIsView,
ArrayBufferPrototypeGetByteLength,
@ -44,16 +55,11 @@ const {
TypedArrayPrototypeSet,
Uint8Array,
} = primordials;
const {
isAnyArrayBuffer,
isArrayBuffer,
isDataView,
isTypedArray,
} = core;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { ReadableStream } from "ext:deno_web/06_streams.js";
import { URL } from "ext:deno_url/00_url.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
op_blob_read_part,
} = core.ensureFastOps();
// TODO(lucacasonato): this needs to not be hardcoded and instead depend on
// host os.
@ -568,7 +574,7 @@ webidl.converters["FilePropertyBag"] = webidl.createDictionaryConverter(
// A finalization registry to deallocate a blob part when its JS reference is
// garbage collected.
const registry = new SafeFinalizationRegistry((uuid) => {
ops.op_blob_remove_part(uuid);
op_blob_remove_part(uuid);
});
// TODO(lucacasonato): get a better stream from Rust in BlobReference#stream
@ -596,7 +602,7 @@ class BlobReference {
* @returns {BlobReference}
*/
static fromUint8Array(data) {
const id = ops.op_blob_create_part(data);
const id = op_blob_create_part(data);
return new BlobReference(id, TypedArrayPrototypeGetByteLength(data));
}
@ -611,7 +617,7 @@ class BlobReference {
*/
slice(start, end) {
const size = end - start;
const id = ops.op_blob_slice_part(this._id, {
const id = op_blob_slice_part(this._id, {
start,
len: size,
});
@ -651,7 +657,7 @@ class BlobReference {
* @returns {Blob | null}
*/
function blobFromObjectUrl(url) {
const blobData = ops.op_blob_from_object_url(url);
const blobData = op_blob_from_object_url(url);
if (blobData === null) {
return null;
}
@ -682,7 +688,7 @@ function createObjectURL(blob) {
webidl.requiredArguments(arguments.length, 1, prefix);
blob = webidl.converters["Blob"](blob, prefix, "Argument 1");
return ops.op_blob_create_object_url(blob.type, getParts(blob));
return op_blob_create_object_url(blob.type, getParts(blob));
}
/**
@ -694,7 +700,7 @@ function revokeObjectURL(url) {
webidl.requiredArguments(arguments.length, 1, prefix);
url = webidl.converters["DOMString"](url, prefix, "Argument 1");
ops.op_blob_revoke_object_url(url);
op_blob_revoke_object_url(url);
}
URL.createObjectURL = createObjectURL;

View file

@ -11,14 +11,9 @@
/// <reference lib="esnext" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { forgivingBase64Encode } from "ext:deno_web/00_infra.js";
import { EventTarget, ProgressEvent } from "ext:deno_web/02_event.js";
import { decode, TextDecoder } from "ext:deno_web/08_text_encoding.js";
import { parseMimeType } from "ext:deno_web/01_mimesniff.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
op_encode_binary_string,
} = core.ensureFastOps();
const {
ArrayPrototypePush,
ArrayPrototypeReduce,
@ -40,6 +35,14 @@ const {
Uint8Array,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { forgivingBase64Encode } from "ext:deno_web/00_infra.js";
import { EventTarget, ProgressEvent } from "ext:deno_web/02_event.js";
import { decode, TextDecoder } from "ext:deno_web/08_text_encoding.js";
import { parseMimeType } from "ext:deno_web/01_mimesniff.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const state = Symbol("[[state]]");
const result = Symbol("[[result]]");
const error = Symbol("[[error]]");
@ -171,7 +174,7 @@ class FileReader extends EventTarget {
break;
}
case "BinaryString":
this[result] = ops.op_encode_binary_string(bytes);
this[result] = op_encode_binary_string(bytes);
break;
case "Text": {
let decoder = undefined;

View file

@ -2,8 +2,6 @@
/// <reference path="../../core/internal.d.ts" />
import { URL } from "ext:deno_url/00_url.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { primordials } from "ext:core/mod.js";
const {
Error,
@ -17,6 +15,9 @@ const {
WeakMapPrototypeSet,
} = primordials;
import { URL } from "ext:deno_url/00_url.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const locationConstructorKey = Symbol("locationConstructorKey");
// The differences between the definitions of `Location` and `WorkerLocation`

View file

@ -6,12 +6,17 @@
/// <reference path="./lib.deno_web.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_compression_finish,
op_compression_new,
op_compression_write,
} = core.ensureFastOps();
const {
SymbolFor,
ObjectPrototypeIsPrototypeOf,
TypedArrayPrototypeGetByteLength,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { TransformStream } from "ext:deno_web/06_streams.js";
@ -33,19 +38,19 @@ class CompressionStream {
webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
const rid = ops.op_compression_new(format, false);
const rid = op_compression_new(format, false);
this.#transform = new TransformStream({
transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
const output = ops.op_compression_write(
const output = op_compression_write(
rid,
chunk,
);
maybeEnqueue(controller, output);
},
flush(controller) {
const output = ops.op_compression_finish(rid);
const output = op_compression_finish(rid);
maybeEnqueue(controller, output);
},
});
@ -92,19 +97,19 @@ class DecompressionStream {
webidl.requiredArguments(arguments.length, 1, prefix);
format = webidl.converters.CompressionFormat(format, prefix, "Argument 1");
const rid = ops.op_compression_new(format, true);
const rid = op_compression_new(format, true);
this.#transform = new TransformStream({
transform(chunk, controller) {
chunk = webidl.converters.BufferSource(chunk, prefix, "chunk");
const output = ops.op_compression_write(
const output = op_compression_write(
rid,
chunk,
);
maybeEnqueue(controller, output);
},
flush(controller) {
const output = ops.op_compression_finish(rid);
const output = op_compression_finish(rid);
maybeEnqueue(controller, output);
},
});

View file

@ -14,6 +14,7 @@ const {
SymbolFor,
TypeError,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { structuredClone } from "ext:deno_web/02_structured_clone.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";

View file

@ -1,9 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const primordials = globalThis.__bootstrap.primordials;
import { primordials } from "ext:core/mod.js";
const {
ObjectPrototypeIsPrototypeOf,
SymbolFor,
@ -12,6 +9,10 @@ const {
Uint8ClampedArray,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
webidl.converters["PredefinedColorSpace"] = webidl.createEnumConverter(
"PredefinedColorSpace",
[

View file

@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_lazy_load_esm,
} = core.ensureFastOps(true);
let webgpu;
@ -32,7 +34,7 @@ function webGPUNonEnumerable(getter) {
function loadWebGPU() {
if (!webgpu) {
webgpu = ops.op_lazy_load_esm("ext:deno_webgpu/01_webgpu.js");
webgpu = op_lazy_load_esm("ext:deno_webgpu/01_webgpu.js");
}
}

View file

@ -7,24 +7,101 @@
/// <reference path="./lib.deno_webgpu.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { EventTarget } from "ext:deno_web/02_event.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const {
isDataView,
isTypedArray,
} = core;
const {
op_webgpu_buffer_get_map_async,
op_webgpu_buffer_get_mapped_range,
op_webgpu_buffer_unmap,
op_webgpu_command_encoder_begin_compute_pass,
op_webgpu_command_encoder_begin_render_pass,
op_webgpu_command_encoder_clear_buffer,
op_webgpu_command_encoder_copy_buffer_to_buffer,
op_webgpu_command_encoder_copy_buffer_to_texture,
op_webgpu_command_encoder_copy_texture_to_buffer,
op_webgpu_command_encoder_copy_texture_to_texture,
op_webgpu_command_encoder_finish,
op_webgpu_command_encoder_insert_debug_marker,
op_webgpu_command_encoder_pop_debug_group,
op_webgpu_command_encoder_push_debug_group,
op_webgpu_command_encoder_resolve_query_set,
op_webgpu_command_encoder_write_timestamp,
op_webgpu_compute_pass_dispatch_workgroups,
op_webgpu_compute_pass_dispatch_workgroups_indirect,
op_webgpu_compute_pass_end,
op_webgpu_compute_pass_insert_debug_marker,
op_webgpu_compute_pass_pop_debug_group,
op_webgpu_compute_pass_push_debug_group,
op_webgpu_compute_pass_set_bind_group,
op_webgpu_compute_pass_set_pipeline,
op_webgpu_compute_pipeline_get_bind_group_layout,
op_webgpu_create_bind_group,
op_webgpu_create_bind_group_layout,
op_webgpu_create_buffer,
op_webgpu_create_command_encoder,
op_webgpu_create_compute_pipeline,
op_webgpu_create_pipeline_layout,
op_webgpu_create_query_set,
op_webgpu_create_render_bundle_encoder,
op_webgpu_create_render_pipeline,
op_webgpu_create_sampler,
op_webgpu_create_shader_module,
op_webgpu_create_texture,
op_webgpu_create_texture_view,
op_webgpu_queue_submit,
op_webgpu_render_bundle_encoder_draw,
op_webgpu_render_bundle_encoder_draw_indexed,
op_webgpu_render_bundle_encoder_draw_indirect,
op_webgpu_render_bundle_encoder_finish,
op_webgpu_render_bundle_encoder_insert_debug_marker,
op_webgpu_render_bundle_encoder_pop_debug_group,
op_webgpu_render_bundle_encoder_push_debug_group,
op_webgpu_render_bundle_encoder_set_bind_group,
op_webgpu_render_bundle_encoder_set_index_buffer,
op_webgpu_render_bundle_encoder_set_pipeline,
op_webgpu_render_bundle_encoder_set_vertex_buffer,
op_webgpu_render_pass_begin_occlusion_query,
op_webgpu_render_pass_draw,
op_webgpu_render_pass_draw_indexed,
op_webgpu_render_pass_draw_indexed_indirect,
op_webgpu_render_pass_draw_indirect,
op_webgpu_render_pass_end,
op_webgpu_render_pass_end_occlusion_query,
op_webgpu_render_pass_execute_bundles,
op_webgpu_render_pass_insert_debug_marker,
op_webgpu_render_pass_pop_debug_group,
op_webgpu_render_pass_push_debug_group,
op_webgpu_render_pass_set_bind_group,
op_webgpu_render_pass_set_blend_constant,
op_webgpu_render_pass_set_index_buffer,
op_webgpu_render_pass_set_pipeline,
op_webgpu_render_pass_set_scissor_rect,
op_webgpu_render_pass_set_stencil_reference,
op_webgpu_render_pass_set_vertex_buffer,
op_webgpu_render_pass_set_viewport,
op_webgpu_render_pipeline_get_bind_group_layout,
op_webgpu_request_adapter,
op_webgpu_request_adapter_info,
op_webgpu_request_device,
op_webgpu_write_buffer,
op_webgpu_write_texture,
} = core.ensureFastOps();
const {
ArrayBuffer,
ArrayBufferPrototypeGetByteLength,
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
ArrayPrototypeMap,
ArrayPrototypePop,
ArrayPrototypePush,
ObjectHasOwn,
ArrayPrototypeIncludes,
ArrayBufferPrototypeGetByteLength,
DataViewPrototypeGetBuffer,
Error,
MathMax,
ObjectDefineProperty,
ObjectHasOwn,
ObjectPrototypeIsPrototypeOf,
Promise,
PromisePrototypeCatch,
@ -34,28 +111,22 @@ const {
SafeArrayIterator,
SafePromiseAll,
SafeSet,
TypedArrayPrototypeGetSymbolToStringTag,
TypedArrayPrototypeGetBuffer,
DataViewPrototypeGetBuffer,
SafeWeakRef,
SetPrototypeHas,
Symbol,
SymbolFor,
SymbolIterator,
TypeError,
TypedArrayPrototypeGetBuffer,
TypedArrayPrototypeGetSymbolToStringTag,
Uint32Array,
Uint8Array,
} = primordials;
const {
isDataView,
isTypedArray,
} = core;
const {
op_webgpu_buffer_get_map_async,
op_webgpu_request_adapter,
op_webgpu_request_adapter_info,
op_webgpu_request_device,
} = core.ensureFastOps();
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { EventTarget } from "ext:deno_web/02_event.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const _rid = Symbol("[[rid]]");
const _size = Symbol("[[size]]");
@ -994,7 +1065,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_buffer(
const { rid, err } = op_webgpu_create_buffer(
device.rid,
descriptor.label,
descriptor.size,
@ -1045,7 +1116,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_texture({
const { rid, err } = op_webgpu_create_texture({
deviceRid: device.rid,
...descriptor,
size: normalizeGPUExtent3D(descriptor.size),
@ -1074,7 +1145,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_sampler({
const { rid, err } = op_webgpu_create_sampler({
deviceRid: device.rid,
...descriptor,
});
@ -1118,7 +1189,7 @@ class GPUDevice extends EventTarget {
}
}
const { rid, err } = ops.op_webgpu_create_bind_group_layout(
const { rid, err } = op_webgpu_create_bind_group_layout(
device.rid,
descriptor.label,
descriptor.entries,
@ -1161,7 +1232,7 @@ class GPUDevice extends EventTarget {
return rid;
},
);
const { rid, err } = ops.op_webgpu_create_pipeline_layout(
const { rid, err } = op_webgpu_create_pipeline_layout(
device.rid,
descriptor.label,
bindGroupLayouts,
@ -1246,7 +1317,7 @@ class GPUDevice extends EventTarget {
}
});
const { rid, err } = ops.op_webgpu_create_bind_group(
const { rid, err } = op_webgpu_create_bind_group(
device.rid,
descriptor.label,
layout,
@ -1276,7 +1347,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_shader_module(
const { rid, err } = op_webgpu_create_shader_module(
device.rid,
descriptor.label,
descriptor.code,
@ -1327,7 +1398,7 @@ class GPUDevice extends EventTarget {
selfContext: "this",
});
const { rid, err } = ops.op_webgpu_create_compute_pipeline(
const { rid, err } = op_webgpu_create_compute_pipeline(
device.rid,
descriptor.label,
layout,
@ -1401,7 +1472,7 @@ class GPUDevice extends EventTarget {
};
}
const { rid, err } = ops.op_webgpu_create_render_pipeline({
const { rid, err } = op_webgpu_create_render_pipeline({
deviceRid: device.rid,
label: descriptor.label,
layout,
@ -1449,7 +1520,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_command_encoder(
const { rid, err } = op_webgpu_create_command_encoder(
device.rid,
descriptor.label,
);
@ -1479,7 +1550,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_render_bundle_encoder({
const { rid, err } = op_webgpu_create_render_bundle_encoder({
deviceRid: device.rid,
...descriptor,
});
@ -1508,7 +1579,7 @@ class GPUDevice extends EventTarget {
"Argument 1",
);
const device = assertDevice(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_query_set({
const { rid, err } = op_webgpu_create_query_set({
deviceRid: device.rid,
...descriptor,
});
@ -1645,7 +1716,7 @@ class GPUQueue {
return rid;
},
);
const { err } = ops.op_webgpu_queue_submit(device.rid, commandBufferRids);
const { err } = op_webgpu_queue_submit(device.rid, commandBufferRids);
for (let i = 0; i < commandBuffers.length; ++i) {
commandBuffers[i][_rid] = undefined;
}
@ -1700,7 +1771,7 @@ class GPUQueue {
abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
}
const { err } = ops.op_webgpu_write_buffer(
const { err } = op_webgpu_write_buffer(
device.rid,
bufferRid,
bufferOffset,
@ -1751,7 +1822,7 @@ class GPUQueue {
abLike = DataViewPrototypeGetBuffer(/** @type {DataView} */ (data));
}
const { err } = ops.op_webgpu_write_texture(
const { err } = op_webgpu_write_texture(
device.rid,
{
texture: textureRid,
@ -2008,7 +2079,7 @@ class GPUBuffer {
}
const buffer = new ArrayBuffer(rangeSize);
const { rid } = ops.op_webgpu_buffer_get_mapped_range(
const { rid } = op_webgpu_buffer_get_mapped_range(
bufferRid,
offset,
size,
@ -2063,7 +2134,7 @@ class GPUBuffer {
}
for (let i = 0; i < mappedRanges.length; ++i) {
const { 0: buffer, 1: mappedRid } = mappedRanges[i];
const { err } = ops.op_webgpu_buffer_unmap(
const { err } = op_webgpu_buffer_unmap(
bufferRid,
mappedRid,
...new SafeArrayIterator(write ? [new Uint8Array(buffer)] : []),
@ -2235,7 +2306,7 @@ class GPUTexture {
);
const device = assertDevice(this, prefix, "this");
const textureRid = assertResource(this, prefix, "this");
const { rid, err } = ops.op_webgpu_create_texture_view({
const { rid, err } = op_webgpu_create_texture_view({
textureRid,
...descriptor,
});
@ -2694,8 +2765,8 @@ class GPUComputePipeline {
index = webidl.converters["unsigned long"](index, prefix, "Argument 1");
const device = assertDevice(this, prefix, "this");
const computePipelineRid = assertResource(this, prefix, "this");
const { rid, label, err } = ops
.op_webgpu_compute_pipeline_get_bind_group_layout(
const { rid, label, err } =
op_webgpu_compute_pipeline_get_bind_group_layout(
computePipelineRid,
index,
);
@ -2773,8 +2844,7 @@ class GPURenderPipeline {
index = webidl.converters["unsigned long"](index, prefix, "Argument 1");
const device = assertDevice(this, prefix, "this");
const renderPipelineRid = assertResource(this, prefix, "this");
const { rid, label, err } = ops
.op_webgpu_render_pipeline_get_bind_group_layout(
const { rid, label, err } = op_webgpu_render_pipeline_get_bind_group_layout(
renderPipelineRid,
index,
);
@ -3011,7 +3081,7 @@ class GPUCommandEncoder {
};
}
const { rid } = ops.op_webgpu_command_encoder_begin_render_pass(
const { rid } = op_webgpu_command_encoder_begin_render_pass(
commandEncoderRid,
descriptor.label,
colorAttachments,
@ -3061,7 +3131,7 @@ class GPUCommandEncoder {
};
}
const { rid } = ops.op_webgpu_command_encoder_begin_compute_pass(
const { rid } = op_webgpu_command_encoder_begin_compute_pass(
commandEncoderRid,
descriptor.label,
timestampWrites,
@ -3126,7 +3196,7 @@ class GPUCommandEncoder {
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_copy_buffer_to_buffer(
const { err } = op_webgpu_command_encoder_copy_buffer_to_buffer(
commandEncoderRid,
sourceRid,
sourceOffset,
@ -3179,7 +3249,7 @@ class GPUCommandEncoder {
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_copy_buffer_to_texture(
const { err } = op_webgpu_command_encoder_copy_buffer_to_texture(
commandEncoderRid,
{
...source,
@ -3243,7 +3313,7 @@ class GPUCommandEncoder {
resourceContext: "buffer in Argument 2",
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_copy_texture_to_buffer(
const { err } = op_webgpu_command_encoder_copy_texture_to_buffer(
commandEncoderRid,
{
texture: sourceTextureRid,
@ -3303,7 +3373,7 @@ class GPUCommandEncoder {
resourceContext: "texture in Argument 2",
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_copy_texture_to_texture(
const { err } = op_webgpu_command_encoder_copy_texture_to_texture(
commandEncoderRid,
{
texture: sourceTextureRid,
@ -3339,7 +3409,7 @@ class GPUCommandEncoder {
const device = assertDevice(this, prefix, "this");
const commandEncoderRid = assertResource(this, prefix, "this");
const bufferRid = assertResource(buffer, prefix, "Argument 1");
const { err } = ops.op_webgpu_command_encoder_clear_buffer(
const { err } = op_webgpu_command_encoder_clear_buffer(
commandEncoderRid,
bufferRid,
offset,
@ -3358,7 +3428,7 @@ class GPUCommandEncoder {
groupLabel = webidl.converters.USVString(groupLabel, prefix, "Argument 1");
const device = assertDevice(this, prefix, "this");
const commandEncoderRid = assertResource(this, prefix, "this");
const { err } = ops.op_webgpu_command_encoder_push_debug_group(
const { err } = op_webgpu_command_encoder_push_debug_group(
commandEncoderRid,
groupLabel,
);
@ -3370,7 +3440,7 @@ class GPUCommandEncoder {
const prefix = "Failed to execute 'popDebugGroup' on 'GPUCommandEncoder'";
const device = assertDevice(this, prefix, "this");
const commandEncoderRid = assertResource(this, prefix, "this");
const { err } = ops.op_webgpu_command_encoder_pop_debug_group(
const { err } = op_webgpu_command_encoder_pop_debug_group(
commandEncoderRid,
);
device.pushError(err);
@ -3391,7 +3461,7 @@ class GPUCommandEncoder {
);
const device = assertDevice(this, prefix, "this");
const commandEncoderRid = assertResource(this, prefix, "this");
const { err } = ops.op_webgpu_command_encoder_insert_debug_marker(
const { err } = op_webgpu_command_encoder_insert_debug_marker(
commandEncoderRid,
markerLabel,
);
@ -3416,7 +3486,7 @@ class GPUCommandEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_write_timestamp(
const { err } = op_webgpu_command_encoder_write_timestamp(
commandEncoderRid,
querySetRid,
queryIndex,
@ -3468,7 +3538,7 @@ class GPUCommandEncoder {
resourceContext: "Argument 3",
selfContext: "this",
});
const { err } = ops.op_webgpu_command_encoder_resolve_query_set(
const { err } = op_webgpu_command_encoder_resolve_query_set(
commandEncoderRid,
querySetRid,
firstQuery,
@ -3493,7 +3563,7 @@ class GPUCommandEncoder {
);
const device = assertDevice(this, prefix, "this");
const commandEncoderRid = assertResource(this, prefix, "this");
const { rid, err } = ops.op_webgpu_command_encoder_finish(
const { rid, err } = op_webgpu_command_encoder_finish(
commandEncoderRid,
descriptor.label,
);
@ -3584,7 +3654,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_set_viewport({
op_webgpu_render_pass_set_viewport({
renderPassRid,
x,
y,
@ -3617,7 +3687,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_set_scissor_rect(
op_webgpu_render_pass_set_scissor_rect(
renderPassRid,
x,
y,
@ -3638,7 +3708,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_set_blend_constant(
op_webgpu_render_pass_set_blend_constant(
renderPassRid,
normalizeGPUColor(color),
);
@ -3660,7 +3730,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_set_stencil_reference(
op_webgpu_render_pass_set_stencil_reference(
renderPassRid,
reference,
);
@ -3678,7 +3748,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_begin_occlusion_query(
op_webgpu_render_pass_begin_occlusion_query(
renderPassRid,
queryIndex,
);
@ -3691,7 +3761,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_end_occlusion_query(renderPassRid);
op_webgpu_render_pass_end_occlusion_query(renderPassRid);
}
/**
@ -3724,7 +3794,7 @@ class GPURenderPassEncoder {
});
return rid;
});
ops.op_webgpu_render_pass_execute_bundles(renderPassRid, bundleRids);
op_webgpu_render_pass_execute_bundles(renderPassRid, bundleRids);
}
end() {
@ -3741,7 +3811,7 @@ class GPURenderPassEncoder {
"encoder referenced by this",
);
const renderPassRid = assertResource(this, prefix, "this");
const { err } = ops.op_webgpu_render_pass_end(
const { err } = op_webgpu_render_pass_end(
commandEncoderRid,
renderPassRid,
);
@ -3780,7 +3850,7 @@ class GPURenderPassEncoder {
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
ops.op_webgpu_render_pass_set_bind_group(
op_webgpu_render_pass_set_bind_group(
renderPassRid,
index,
bindGroupRid,
@ -3802,7 +3872,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_push_debug_group(renderPassRid, groupLabel);
op_webgpu_render_pass_push_debug_group(renderPassRid, groupLabel);
}
popDebugGroup() {
@ -3812,7 +3882,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_pop_debug_group(renderPassRid);
op_webgpu_render_pass_pop_debug_group(renderPassRid);
}
/**
@ -3831,7 +3901,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_insert_debug_marker(renderPassRid, markerLabel);
op_webgpu_render_pass_insert_debug_marker(renderPassRid, markerLabel);
}
/**
@ -3859,7 +3929,7 @@ class GPURenderPassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_pass_set_pipeline(renderPassRid, pipelineRid);
op_webgpu_render_pass_set_pipeline(renderPassRid, pipelineRid);
}
/**
@ -3896,7 +3966,7 @@ class GPURenderPassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_pass_set_index_buffer(
op_webgpu_render_pass_set_index_buffer(
renderPassRid,
bufferRid,
indexFormat,
@ -3935,7 +4005,7 @@ class GPURenderPassEncoder {
resourceContext: "Argument 2",
selfContext: "this",
});
ops.op_webgpu_render_pass_set_vertex_buffer(
op_webgpu_render_pass_set_vertex_buffer(
renderPassRid,
slot,
bufferRid,
@ -3977,7 +4047,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_draw(
op_webgpu_render_pass_draw(
renderPassRid,
vertexCount,
instanceCount,
@ -4023,7 +4093,7 @@ class GPURenderPassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const renderPassRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_pass_draw_indexed(
op_webgpu_render_pass_draw_indexed(
renderPassRid,
indexCount,
instanceCount,
@ -4068,7 +4138,7 @@ class GPURenderPassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_pass_draw_indirect(
op_webgpu_render_pass_draw_indirect(
renderPassRid,
indirectBufferRid,
indirectOffset,
@ -4111,7 +4181,7 @@ class GPURenderPassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_pass_draw_indexed_indirect(
op_webgpu_render_pass_draw_indexed_indirect(
renderPassRid,
indirectBufferRid,
indirectOffset,
@ -4197,7 +4267,7 @@ class GPUComputePassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_compute_pass_set_pipeline(computePassRid, pipelineRid);
op_webgpu_compute_pass_set_pipeline(computePassRid, pipelineRid);
}
/**
@ -4232,7 +4302,7 @@ class GPUComputePassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const computePassRid = assertResource(this, prefix, "this");
ops.op_webgpu_compute_pass_dispatch_workgroups(
op_webgpu_compute_pass_dispatch_workgroups(
computePassRid,
workgroupCountX,
workgroupCountY,
@ -4276,7 +4346,7 @@ class GPUComputePassEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_compute_pass_dispatch_workgroups_indirect(
op_webgpu_compute_pass_dispatch_workgroups_indirect(
computePassRid,
indirectBufferRid,
indirectOffset,
@ -4297,7 +4367,7 @@ class GPUComputePassEncoder {
"encoder referenced by this",
);
const computePassRid = assertResource(this, prefix, "this");
const { err } = ops.op_webgpu_compute_pass_end(
const { err } = op_webgpu_compute_pass_end(
commandEncoderRid,
computePassRid,
);
@ -4337,7 +4407,7 @@ class GPUComputePassEncoder {
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
ops.op_webgpu_compute_pass_set_bind_group(
op_webgpu_compute_pass_set_bind_group(
computePassRid,
index,
bindGroupRid,
@ -4359,7 +4429,7 @@ class GPUComputePassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const computePassRid = assertResource(this, prefix, "this");
ops.op_webgpu_compute_pass_push_debug_group(computePassRid, groupLabel);
op_webgpu_compute_pass_push_debug_group(computePassRid, groupLabel);
}
popDebugGroup() {
@ -4369,7 +4439,7 @@ class GPUComputePassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const computePassRid = assertResource(this, prefix, "this");
ops.op_webgpu_compute_pass_pop_debug_group(computePassRid);
op_webgpu_compute_pass_pop_debug_group(computePassRid);
}
/**
@ -4388,7 +4458,7 @@ class GPUComputePassEncoder {
assertDevice(this[_encoder], prefix, "encoder referenced by this");
assertResource(this[_encoder], prefix, "encoder referenced by this");
const computePassRid = assertResource(this, prefix, "this");
ops.op_webgpu_compute_pass_insert_debug_marker(
op_webgpu_compute_pass_insert_debug_marker(
computePassRid,
markerLabel,
);
@ -4510,7 +4580,7 @@ class GPURenderBundleEncoder {
);
const device = assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
const { rid, err } = ops.op_webgpu_render_bundle_encoder_finish(
const { rid, err } = op_webgpu_render_bundle_encoder_finish(
renderBundleEncoderRid,
descriptor.label,
);
@ -4553,7 +4623,7 @@ class GPURenderBundleEncoder {
dynamicOffsetsDataStart = 0;
dynamicOffsetsDataLength = dynamicOffsetsData.length;
}
ops.op_webgpu_render_bundle_encoder_set_bind_group(
op_webgpu_render_bundle_encoder_set_bind_group(
renderBundleEncoderRid,
index,
bindGroupRid,
@ -4574,7 +4644,7 @@ class GPURenderBundleEncoder {
groupLabel = webidl.converters.USVString(groupLabel, prefix, "Argument 1");
assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_bundle_encoder_push_debug_group(
op_webgpu_render_bundle_encoder_push_debug_group(
renderBundleEncoderRid,
groupLabel,
);
@ -4586,7 +4656,7 @@ class GPURenderBundleEncoder {
"Failed to execute 'popDebugGroup' on 'GPURenderBundleEncoder'";
assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_bundle_encoder_pop_debug_group(
op_webgpu_render_bundle_encoder_pop_debug_group(
renderBundleEncoderRid,
);
}
@ -4606,7 +4676,7 @@ class GPURenderBundleEncoder {
);
assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_bundle_encoder_insert_debug_marker(
op_webgpu_render_bundle_encoder_insert_debug_marker(
renderBundleEncoderRid,
markerLabel,
);
@ -4633,7 +4703,7 @@ class GPURenderBundleEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_bundle_encoder_set_pipeline(
op_webgpu_render_bundle_encoder_set_pipeline(
renderBundleEncoderRid,
pipelineRid,
);
@ -4666,7 +4736,7 @@ class GPURenderBundleEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_bundle_encoder_set_index_buffer(
op_webgpu_render_bundle_encoder_set_index_buffer(
renderBundleEncoderRid,
bufferRid,
indexFormat,
@ -4700,7 +4770,7 @@ class GPURenderBundleEncoder {
resourceContext: "Argument 2",
selfContext: "this",
});
ops.op_webgpu_render_bundle_encoder_set_vertex_buffer(
op_webgpu_render_bundle_encoder_set_vertex_buffer(
renderBundleEncoderRid,
slot,
bufferRid,
@ -4741,7 +4811,7 @@ class GPURenderBundleEncoder {
);
assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_bundle_encoder_draw(
op_webgpu_render_bundle_encoder_draw(
renderBundleEncoderRid,
vertexCount,
instanceCount,
@ -4787,7 +4857,7 @@ class GPURenderBundleEncoder {
);
assertDevice(this, prefix, "this");
const renderBundleEncoderRid = assertResource(this, prefix, "this");
ops.op_webgpu_render_bundle_encoder_draw_indexed(
op_webgpu_render_bundle_encoder_draw_indexed(
renderBundleEncoderRid,
indexCount,
instanceCount,
@ -4828,7 +4898,7 @@ class GPURenderBundleEncoder {
resourceContext: "Argument 1",
selfContext: "this",
});
ops.op_webgpu_render_bundle_encoder_draw_indirect(
op_webgpu_render_bundle_encoder_draw_indirect(
renderBundleEncoderRid,
indirectBufferRid,
indirectOffset,

View file

@ -7,10 +7,19 @@
/// <reference path="./lib.deno_webgpu.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_webgpu_surface_configure,
op_webgpu_surface_get_current_texture,
op_webgpu_surface_present,
} = core.ensureFastOps();
const {
ObjectPrototypeIsPrototypeOf,
Symbol,
SymbolFor,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
const { Symbol, SymbolFor, ObjectPrototypeIsPrototypeOf } = primordials;
import { loadWebGPU, webgpu } from "ext:deno_webgpu/00_init.js";
const _surfaceRid = Symbol("[[surfaceRid]]");
@ -52,7 +61,7 @@ class GPUCanvasContext {
context: "configuration.device",
});
const { err } = ops.op_webgpu_surface_configure({
const { err } = op_webgpu_surface_configure({
surfaceRid: this[_surfaceRid],
deviceRid: device.rid,
format: configuration.format,
@ -91,7 +100,7 @@ class GPUCanvasContext {
return this[_currentTexture];
}
const { rid } = ops.op_webgpu_surface_get_current_texture(
const { rid } = op_webgpu_surface_get_current_texture(
device.rid,
this[_surfaceRid],
);
@ -127,7 +136,7 @@ class GPUCanvasContext {
prefix,
context: "this",
});
ops.op_webgpu_surface_present(device.rid, this[_surfaceRid]);
op_webgpu_surface_present(device.rid, this[_surfaceRid]);
this[_currentTexture].destroy();
this[_currentTexture] = undefined;
}

View file

@ -7,6 +7,12 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const {
isArrayBuffer,
isDataView,
isSharedArrayBuffer,
isTypedArray,
} = core;
const {
ArrayBufferIsView,
ArrayPrototypeForEach,
@ -80,12 +86,6 @@ const {
Uint8Array,
Uint8ClampedArray,
} = primordials;
const {
isArrayBuffer,
isDataView,
isSharedArrayBuffer,
isTypedArray,
} = core;
function makeException(ErrorType, message, prefix, context) {
return new ErrorType(

View file

@ -3,23 +3,24 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
import { URL } from "ext:deno_url/00_url.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
const {
isAnyArrayBuffer,
isArrayBuffer,
} = core;
import {
CloseEvent,
defineEventHandler,
dispatch,
ErrorEvent,
Event,
EventTarget,
MessageEvent,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { Blob, BlobPrototype } from "ext:deno_web/09_file.js";
import { getLocationHref } from "ext:deno_web/12_location.js";
op_ws_check_permission_and_cancel_handle,
op_ws_close,
op_ws_create,
op_ws_get_buffer,
op_ws_get_buffer_as_string,
op_ws_get_buffered_amount,
op_ws_get_error,
op_ws_next_event,
op_ws_send_binary,
op_ws_send_binary_ab,
op_ws_send_ping,
op_ws_send_text,
} from "ext:deno_websocket/00_ops.js";
const {
ArrayBufferIsView,
ArrayPrototypeJoin,
@ -42,24 +43,24 @@ const {
TypedArrayPrototypeGetByteLength,
Uint8Array,
} = primordials;
const {
isAnyArrayBuffer,
isArrayBuffer,
} = core;
import { URL } from "ext:deno_url/00_url.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import {
op_ws_check_permission_and_cancel_handle,
op_ws_close,
op_ws_create,
op_ws_get_buffer,
op_ws_get_buffer_as_string,
op_ws_get_buffered_amount,
op_ws_get_error,
op_ws_next_event,
op_ws_send_binary,
op_ws_send_binary_ab,
op_ws_send_ping,
op_ws_send_text,
} from "ext:deno_websocket/00_ops.js";
CloseEvent,
defineEventHandler,
dispatch,
ErrorEvent,
Event,
EventTarget,
MessageEvent,
setIsTrusted,
} from "ext:deno_web/02_event.js";
import { Blob, BlobPrototype } from "ext:deno_web/09_file.js";
import { getLocationHref } from "ext:deno_web/12_location.js";
webidl.converters["sequence<DOMString> or DOMString"] = (
V,

View file

@ -3,16 +3,17 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { Deferred, writableStreamClose } from "ext:deno_web/06_streams.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { add, remove } from "ext:deno_web/03_abort_signal.js";
import {
fillHeaders,
headerListFromHeaders,
headersFromHeaderList,
} from "ext:deno_fetch/20_headers.js";
op_ws_check_permission_and_cancel_handle,
op_ws_close,
op_ws_create,
op_ws_get_buffer,
op_ws_get_buffer_as_string,
op_ws_get_error,
op_ws_next_event,
op_ws_send_binary_async,
op_ws_send_text_async,
} from "ext:deno_websocket/00_ops.js";
const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
@ -31,17 +32,17 @@ const {
TypedArrayPrototypeGetByteLength,
TypedArrayPrototypeGetSymbolToStringTag,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { Deferred, writableStreamClose } from "ext:deno_web/06_streams.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import { add, remove } from "ext:deno_web/03_abort_signal.js";
import {
op_ws_check_permission_and_cancel_handle,
op_ws_close,
op_ws_create,
op_ws_get_buffer,
op_ws_get_buffer_as_string,
op_ws_get_error,
op_ws_next_event,
op_ws_send_binary_async,
op_ws_send_text_async,
} from "ext:deno_websocket/00_ops.js";
fillHeaders,
headerListFromHeaders,
headersFromHeaderList,
} from "ext:deno_fetch/20_headers.js";
webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter(
"WebSocketStreamOptions",

View file

@ -3,8 +3,15 @@
/// <reference path="../../core/internal.d.ts" />
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import * as webidl from "ext:deno_webidl/00_webidl.js";
const {
op_webstorage_clear,
op_webstorage_get,
op_webstorage_iterate_keys,
op_webstorage_key,
op_webstorage_length,
op_webstorage_remove,
op_webstorage_set,
} = core.ensureFastOps();
const {
Symbol,
SymbolFor,
@ -17,6 +24,8 @@ const {
Proxy,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
const _persistent = Symbol("[[persistent]]");
class Storage {
@ -28,7 +37,7 @@ class Storage {
get length() {
webidl.assertBranded(this, StoragePrototype);
return ops.op_webstorage_length(this[_persistent]);
return op_webstorage_length(this[_persistent]);
}
key(index) {
@ -37,7 +46,7 @@ class Storage {
webidl.requiredArguments(arguments.length, 1, prefix);
index = webidl.converters["unsigned long"](index, prefix, "Argument 1");
return ops.op_webstorage_key(index, this[_persistent]);
return op_webstorage_key(index, this[_persistent]);
}
setItem(key, value) {
@ -47,7 +56,7 @@ class Storage {
key = webidl.converters.DOMString(key, prefix, "Argument 1");
value = webidl.converters.DOMString(value, prefix, "Argument 2");
ops.op_webstorage_set(key, value, this[_persistent]);
op_webstorage_set(key, value, this[_persistent]);
}
getItem(key) {
@ -56,7 +65,7 @@ class Storage {
webidl.requiredArguments(arguments.length, 1, prefix);
key = webidl.converters.DOMString(key, prefix, "Argument 1");
return ops.op_webstorage_get(key, this[_persistent]);
return op_webstorage_get(key, this[_persistent]);
}
removeItem(key) {
@ -65,12 +74,12 @@ class Storage {
webidl.requiredArguments(arguments.length, 1, prefix);
key = webidl.converters.DOMString(key, prefix, "Argument 1");
ops.op_webstorage_remove(key, this[_persistent]);
op_webstorage_remove(key, this[_persistent]);
}
clear() {
webidl.assertBranded(this, StoragePrototype);
ops.op_webstorage_clear(this[_persistent]);
op_webstorage_clear(this[_persistent]);
}
}
@ -126,7 +135,7 @@ function createStorage(persistent) {
},
ownKeys() {
return ops.op_webstorage_iterate_keys(persistent);
return op_webstorage_iterate_keys(persistent);
},
getOwnPropertyDescriptor(target, key) {

View file

@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
const primordials = globalThis.__bootstrap.primordials;
const { ObjectFreeze } = primordials;
import { primordials } from "ext:core/mod.js";
const {
ObjectFreeze,
} = primordials;
interface Version {
deno: string;

View file

@ -1,7 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_bootstrap_log_level,
} = core.ensureFastOps();
const {
Promise,
SafeArrayIterator,
@ -20,7 +22,7 @@ const logSource = "JS";
let logLevel_ = null;
function logLevel() {
if (logLevel_ === null) {
logLevel_ = ops.op_bootstrap_log_level() || 3;
logLevel_ = op_bootstrap_log_level() || 3;
}
return logLevel_;
}

View file

@ -1,9 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import { pathFromURL } from "ext:deno_web/00_infra.js";
import { Event, EventTarget } from "ext:deno_web/02_event.js";
const {
op_query_permission,
op_request_permission,
op_revoke_permission,
} = core.ensureFastOps();
const {
ArrayIsArray,
ArrayPrototypeIncludes,
@ -23,6 +25,9 @@ const {
TypeError,
} = primordials;
import { pathFromURL } from "ext:deno_web/00_infra.js";
import { Event, EventTarget } from "ext:deno_web/02_event.js";
const illegalConstructorKey = Symbol("illegalConstructorKey");
/**
@ -49,7 +54,7 @@ const permissionNames = [
* @returns {Deno.PermissionState}
*/
function opQuery(desc) {
return ops.op_query_permission(desc);
return op_query_permission(desc);
}
/**
@ -57,7 +62,7 @@ function opQuery(desc) {
* @returns {Deno.PermissionState}
*/
function opRevoke(desc) {
return ops.op_revoke_permission(desc);
return op_revoke_permission(desc);
}
/**
@ -65,7 +70,7 @@ function opRevoke(desc) {
* @returns {Deno.PermissionState}
*/
function opRequest(desc) {
return ops.op_request_permission(desc);
return op_request_permission(desc);
}
class PermissionStatus extends EventTarget {

View file

@ -1,7 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
const {
op_create_worker,
op_host_post_message,
op_host_recv_ctrl,
op_host_recv_message,
op_host_terminate_worker,
} = core.ensureFastOps();
const {
ArrayPrototypeFilter,
Error,
@ -12,6 +18,7 @@ const {
SymbolIterator,
SymbolToStringTag,
} = primordials;
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { URL } from "ext:deno_url/00_url.js";
@ -30,10 +37,6 @@ import {
MessagePortPrototype,
serializeJsMessageData,
} from "ext:deno_web/13_message_port.js";
const {
op_host_recv_ctrl,
op_host_recv_message,
} = core.ensureFastOps();
function createWorker(
specifier,
@ -43,7 +46,7 @@ function createWorker(
name,
workerType,
) {
return ops.op_create_worker({
return op_create_worker({
hasSourceCode,
name,
permissions: serializePermissions(permissions),
@ -54,11 +57,11 @@ function createWorker(
}
function hostTerminateWorker(id) {
ops.op_host_terminate_worker(id);
op_host_terminate_worker(id);
}
function hostPostMessage(id, data) {
ops.op_host_post_message(id, data);
op_host_post_message(id, data);
}
function hostRecvCtrl(id) {

View file

@ -4,8 +4,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE
import { assert } from "ext:deno_web/00_infra.js";
const primordials = globalThis.__bootstrap.primordials;
import { primordials } from "ext:core/mod.js";
const {
ArrayBufferPrototypeGetByteLength,
TypedArrayPrototypeSubarray,
@ -20,6 +19,8 @@ const {
Error,
} = primordials;
import { assert } from "ext:deno_web/00_infra.js";
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
// what is required to hold the contents of r, readFrom() will not grow the

View file

@ -1,49 +1,68 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const ops = core.ops;
import { Event, EventTarget } from "ext:deno_web/02_event.js";
const {
op_delete_env,
op_env,
op_exec_path,
op_exit,
op_get_env,
op_gid,
op_hostname,
op_loadavg,
op_network_interfaces,
op_os_release,
op_os_uptime,
op_set_env,
op_system_memory_info,
op_uid,
} = core.ensureFastOps();
const {
op_set_exit_code,
} = core.ensureFastOps(true);
const {
Error,
FunctionPrototypeBind,
SymbolFor,
} = primordials;
import { Event, EventTarget } from "ext:deno_web/02_event.js";
const windowDispatchEvent = FunctionPrototypeBind(
EventTarget.prototype.dispatchEvent,
globalThis,
);
function loadavg() {
return ops.op_loadavg();
return op_loadavg();
}
function hostname() {
return ops.op_hostname();
return op_hostname();
}
function osRelease() {
return ops.op_os_release();
return op_os_release();
}
function osUptime() {
return ops.op_os_uptime();
return op_os_uptime();
}
function systemMemoryInfo() {
return ops.op_system_memory_info();
return op_system_memory_info();
}
function networkInterfaces() {
return ops.op_network_interfaces();
return op_network_interfaces();
}
function gid() {
return ops.op_gid();
return op_gid();
}
function uid() {
return ops.op_uid();
return op_uid();
}
// This is an internal only method used by the test harness to override the
@ -56,7 +75,7 @@ function setExitHandler(fn) {
function exit(code) {
// Set exit code first so unload event listeners can override it.
if (typeof code === "number") {
ops.op_set_exit_code(code);
op_set_exit_code(code);
} else {
code = 0;
}
@ -73,26 +92,26 @@ function exit(code) {
return;
}
ops.op_exit();
op_exit();
throw new Error("Code not reachable");
}
function setEnv(key, value) {
ops.op_set_env(key, value);
op_set_env(key, value);
}
function getEnv(key) {
return ops.op_get_env(key) ?? undefined;
return op_get_env(key) ?? undefined;
}
function deleteEnv(key) {
ops.op_delete_env(key);
op_delete_env(key);
}
const env = {
get: getEnv,
toObject() {
return ops.op_env();
return op_env();
},
set: setEnv,
has(key) {
@ -102,7 +121,7 @@ const env = {
};
function execPath() {
return ops.op_exec_path();
return op_exec_path();
}
export {

View file

@ -1,24 +1,29 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, primordials } from "ext:core/mod.js";
const { BadResourcePrototype, InterruptedPrototype, ops } = core;
const {
BadResourcePrototype,
InterruptedPrototype,
} = core;
const {
op_fs_events_open,
op_fs_events_poll,
} = core.ensureFastOps();
const {
ArrayIsArray,
ObjectPrototypeIsPrototypeOf,
PromiseResolve,
SymbolAsyncIterator,
} = primordials;
import { SymbolDispose } from "ext:deno_web/00_infra.js";
const {
op_fs_events_poll,
} = core.ensureFastOps();
class FsWatcher {
#rid = 0;
constructor(paths, options) {
const { recursive } = options;
this.#rid = ops.op_fs_events_open({ recursive, paths });
this.#rid = op_fs_events_open({ recursive, paths });
}
get rid() {

View file

@ -1,10 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
const ops = core.ops;
const {
op_http_start,
} = core.ensureFastOps();
import { HttpConn } from "ext:deno_http/01_http.js";
function serveHttp(conn) {
const rid = ops.op_http_start(conn.rid);
const rid = op_http_start(conn.rid);
return new HttpConn(rid, conn.remoteAddr, conn.localAddr);
}

Some files were not shown because too many files have changed in this diff Show more