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

refactor: prefix ops w/ crate they are defined in (#19044)

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Luca Casonato 2023-05-08 23:07:45 +02:00 committed by GitHub
parent e021070a2a
commit 1f9d47b174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 358 additions and 317 deletions

View file

@ -884,7 +884,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_sign_ed25519(keyData, data, signature)) {
if (!ops.op_crypto_sign_ed25519(keyData, data, signature)) {
throw new DOMException(
"Failed to sign",
"OperationError",
@ -1363,7 +1363,7 @@ class SubtleCrypto {
);
}
return ops.op_verify_ed25519(keyData, data, signature);
return ops.op_crypto_verify_ed25519(keyData, data, signature);
}
}
@ -1997,7 +1997,7 @@ async function generateKey(normalizedAlgorithm, extractable, usages) {
}
const privateKeyData = new Uint8Array(32);
const publicKeyData = new Uint8Array(32);
ops.op_generate_x25519_keypair(privateKeyData, publicKeyData);
ops.op_crypto_generate_x25519_keypair(privateKeyData, publicKeyData);
const handle = {};
WeakMapPrototypeSet(KEY_STORE, handle, privateKeyData);
@ -2042,7 +2042,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_generate_ed25519_keypair(privateKeyData, publicKeyData)
!ops.op_crypto_generate_ed25519_keypair(privateKeyData, publicKeyData)
) {
throw new DOMException("Failed to generate key", "OperationError");
}
@ -2179,7 +2179,7 @@ function importKeyEd25519(
}
const publicKeyData = new Uint8Array(32);
if (!ops.op_import_spki_ed25519(keyData, publicKeyData)) {
if (!ops.op_crypto_import_spki_ed25519(keyData, publicKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2210,7 +2210,7 @@ function importKeyEd25519(
}
const privateKeyData = new Uint8Array(32);
if (!ops.op_import_pkcs8_ed25519(keyData, privateKeyData)) {
if (!ops.op_crypto_import_pkcs8_ed25519(keyData, privateKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2397,7 +2397,7 @@ function importKeyX25519(
}
const publicKeyData = new Uint8Array(32);
if (!ops.op_import_spki_x25519(keyData, publicKeyData)) {
if (!ops.op_crypto_import_spki_x25519(keyData, publicKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -2428,7 +2428,7 @@ function importKeyX25519(
}
const privateKeyData = new Uint8Array(32);
if (!ops.op_import_pkcs8_x25519(keyData, privateKeyData)) {
if (!ops.op_crypto_import_pkcs8_x25519(keyData, privateKeyData)) {
throw new DOMException("Invalid key data", "DataError");
}
@ -4055,7 +4055,7 @@ function exportKeyEd25519(format, key, innerKey) {
);
}
const spkiDer = ops.op_export_spki_ed25519(innerKey);
const spkiDer = ops.op_crypto_export_spki_ed25519(innerKey);
return TypedArrayPrototypeGetBuffer(spkiDer);
}
case "pkcs8": {
@ -4067,7 +4067,7 @@ function exportKeyEd25519(format, key, innerKey) {
);
}
const pkcs8Der = ops.op_export_pkcs8_ed25519(
const pkcs8Der = ops.op_crypto_export_pkcs8_ed25519(
new Uint8Array([0x04, 0x22, ...new SafeArrayIterator(innerKey)]),
);
pkcs8Der[15] = 0x20;
@ -4075,7 +4075,7 @@ function exportKeyEd25519(format, key, innerKey) {
}
case "jwk": {
const x = key[_type] === "private"
? ops.op_jwk_x_ed25519(innerKey)
? ops.op_crypto_jwk_x_ed25519(innerKey)
: ops.op_crypto_base64url_encode(innerKey);
const jwk = {
kty: "OKP",
@ -4118,7 +4118,7 @@ function exportKeyX25519(format, key, innerKey) {
);
}
const spkiDer = ops.op_export_spki_x25519(innerKey);
const spkiDer = ops.op_crypto_export_spki_x25519(innerKey);
return TypedArrayPrototypeGetBuffer(spkiDer);
}
case "pkcs8": {
@ -4130,7 +4130,7 @@ function exportKeyX25519(format, key, innerKey) {
);
}
const pkcs8Der = ops.op_export_pkcs8_x25519(
const pkcs8Der = ops.op_crypto_export_pkcs8_x25519(
new Uint8Array([0x04, 0x22, ...new SafeArrayIterator(innerKey)]),
);
pkcs8Der[15] = 0x20;
@ -4476,7 +4476,7 @@ async function deriveBits(normalizedAlgorithm, baseKey, length) {
const u = WeakMapPrototypeGet(KEY_STORE, uHandle);
const secret = new Uint8Array(32);
const isIdentity = ops.op_derive_bits_x25519(k, u, secret);
const isIdentity = ops.op_crypto_derive_bits_x25519(k, u, secret);
// 6.
if (isIdentity) {

View file

@ -12,7 +12,10 @@ use spki::der::Decode;
use spki::der::Encode;
#[op(fast)]
pub fn op_generate_ed25519_keypair(pkey: &mut [u8], pubkey: &mut [u8]) -> bool {
pub fn op_crypto_generate_ed25519_keypair(
pkey: &mut [u8],
pubkey: &mut [u8],
) -> bool {
let mut rng = OsRng;
rng.fill_bytes(pkey);
@ -25,7 +28,11 @@ pub fn op_generate_ed25519_keypair(pkey: &mut [u8], pubkey: &mut [u8]) -> bool {
}
#[op(fast)]
pub fn op_sign_ed25519(key: &[u8], data: &[u8], signature: &mut [u8]) -> bool {
pub fn op_crypto_sign_ed25519(
key: &[u8],
data: &[u8],
signature: &mut [u8],
) -> bool {
let pair = match Ed25519KeyPair::from_seed_unchecked(key) {
Ok(p) => p,
Err(_) => return false,
@ -35,7 +42,11 @@ pub fn op_sign_ed25519(key: &[u8], data: &[u8], signature: &mut [u8]) -> bool {
}
#[op(fast)]
pub fn op_verify_ed25519(pubkey: &[u8], data: &[u8], signature: &[u8]) -> bool {
pub fn op_crypto_verify_ed25519(
pubkey: &[u8],
data: &[u8],
signature: &[u8],
) -> bool {
ring::signature::UnparsedPublicKey::new(&ring::signature::ED25519, pubkey)
.verify(data, signature)
.is_ok()
@ -46,7 +57,7 @@ pub const ED25519_OID: const_oid::ObjectIdentifier =
const_oid::ObjectIdentifier::new_unwrap("1.3.101.112");
#[op(fast)]
pub fn op_import_spki_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
pub fn op_crypto_import_spki_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
// 2-3.
let pk_info = match spki::SubjectPublicKeyInfo::from_der(key_data) {
Ok(pk_info) => pk_info,
@ -66,7 +77,7 @@ pub fn op_import_spki_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
}
#[op(fast)]
pub fn op_import_pkcs8_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
pub fn op_crypto_import_pkcs8_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
// 2-3.
// This should probably use OneAsymmetricKey instead
let pk_info = match PrivateKeyInfo::from_der(key_data) {
@ -92,7 +103,9 @@ pub fn op_import_pkcs8_ed25519(key_data: &[u8], out: &mut [u8]) -> bool {
}
#[op]
pub fn op_export_spki_ed25519(pubkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
pub fn op_crypto_export_spki_ed25519(
pubkey: &[u8],
) -> Result<ZeroCopyBuf, AnyError> {
let key_info = spki::SubjectPublicKeyInfo {
algorithm: spki::AlgorithmIdentifier {
// id-Ed25519
@ -105,7 +118,9 @@ pub fn op_export_spki_ed25519(pubkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
}
#[op]
pub fn op_export_pkcs8_ed25519(pkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
pub fn op_crypto_export_pkcs8_ed25519(
pkey: &[u8],
) -> Result<ZeroCopyBuf, AnyError> {
// This should probably use OneAsymmetricKey instead
let pk_info = rsa::pkcs8::PrivateKeyInfo {
public_key: None,
@ -123,7 +138,7 @@ pub fn op_export_pkcs8_ed25519(pkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
// 'x' from Section 2 of RFC 8037
// https://www.rfc-editor.org/rfc/rfc8037#section-2
#[op]
pub fn op_jwk_x_ed25519(pkey: &[u8]) -> Result<String, AnyError> {
pub fn op_crypto_jwk_x_ed25519(pkey: &[u8]) -> Result<String, AnyError> {
let pair = Ed25519KeyPair::from_seed_unchecked(pkey)?;
Ok(base64::encode_config(
pair.public_key().as_ref(),

View file

@ -88,20 +88,20 @@ deno_core::extension!(deno_crypto,
op_crypto_unwrap_key,
op_crypto_base64url_decode,
op_crypto_base64url_encode,
x25519::op_generate_x25519_keypair,
x25519::op_derive_bits_x25519,
x25519::op_import_spki_x25519,
x25519::op_import_pkcs8_x25519,
ed25519::op_generate_ed25519_keypair,
ed25519::op_import_spki_ed25519,
ed25519::op_import_pkcs8_ed25519,
ed25519::op_sign_ed25519,
ed25519::op_verify_ed25519,
ed25519::op_export_spki_ed25519,
ed25519::op_export_pkcs8_ed25519,
ed25519::op_jwk_x_ed25519,
x25519::op_export_spki_x25519,
x25519::op_export_pkcs8_x25519,
x25519::op_crypto_generate_x25519_keypair,
x25519::op_crypto_derive_bits_x25519,
x25519::op_crypto_import_spki_x25519,
x25519::op_crypto_import_pkcs8_x25519,
ed25519::op_crypto_generate_ed25519_keypair,
ed25519::op_crypto_import_spki_ed25519,
ed25519::op_crypto_import_pkcs8_ed25519,
ed25519::op_crypto_sign_ed25519,
ed25519::op_crypto_verify_ed25519,
ed25519::op_crypto_export_spki_ed25519,
ed25519::op_crypto_export_pkcs8_ed25519,
ed25519::op_crypto_jwk_x_ed25519,
x25519::op_crypto_export_spki_x25519,
x25519::op_crypto_export_pkcs8_x25519,
],
esm = [ "00_crypto.js", "01_webidl.js" ],
options = {

View file

@ -12,7 +12,7 @@ use spki::der::Decode;
use spki::der::Encode;
#[op(fast)]
pub fn op_generate_x25519_keypair(pkey: &mut [u8], pubkey: &mut [u8]) {
pub fn op_crypto_generate_x25519_keypair(pkey: &mut [u8], pubkey: &mut [u8]) {
// u-coordinate of the base point.
const X25519_BASEPOINT_BYTES: [u8; 32] = [
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -32,7 +32,11 @@ pub fn op_generate_x25519_keypair(pkey: &mut [u8], pubkey: &mut [u8]) {
const MONTGOMERY_IDENTITY: MontgomeryPoint = MontgomeryPoint([0; 32]);
#[op(fast)]
pub fn op_derive_bits_x25519(k: &[u8], u: &[u8], secret: &mut [u8]) -> bool {
pub fn op_crypto_derive_bits_x25519(
k: &[u8],
u: &[u8],
secret: &mut [u8],
) -> bool {
let k: [u8; 32] = k.try_into().expect("Expected byteLength 32");
let u: [u8; 32] = u.try_into().expect("Expected byteLength 32");
let sh_sec = x25519_dalek::x25519(k, u);
@ -49,7 +53,7 @@ pub const X25519_OID: const_oid::ObjectIdentifier =
const_oid::ObjectIdentifier::new_unwrap("1.3.101.110");
#[op(fast)]
pub fn op_import_spki_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
pub fn op_crypto_import_spki_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
// 2-3.
let pk_info = match spki::SubjectPublicKeyInfo::from_der(key_data) {
Ok(pk_info) => pk_info,
@ -69,7 +73,7 @@ pub fn op_import_spki_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
}
#[op(fast)]
pub fn op_import_pkcs8_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
pub fn op_crypto_import_pkcs8_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
// 2-3.
// This should probably use OneAsymmetricKey instead
let pk_info = match PrivateKeyInfo::from_der(key_data) {
@ -95,7 +99,9 @@ pub fn op_import_pkcs8_x25519(key_data: &[u8], out: &mut [u8]) -> bool {
}
#[op]
pub fn op_export_spki_x25519(pubkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
pub fn op_crypto_export_spki_x25519(
pubkey: &[u8],
) -> Result<ZeroCopyBuf, AnyError> {
let key_info = spki::SubjectPublicKeyInfo {
algorithm: spki::AlgorithmIdentifier {
// id-X25519
@ -108,7 +114,9 @@ pub fn op_export_spki_x25519(pubkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
}
#[op]
pub fn op_export_pkcs8_x25519(pkey: &[u8]) -> Result<ZeroCopyBuf, AnyError> {
pub fn op_crypto_export_pkcs8_x25519(
pkey: &[u8],
) -> Result<ZeroCopyBuf, AnyError> {
// This should probably use OneAsymmetricKey instead
let pk_info = rsa::pkcs8::PrivateKeyInfo {
public_key: None,

View file

@ -5,17 +5,17 @@
const core = globalThis.Deno.core;
const ops = core.ops;
const {
op_chmod_async,
op_ftruncate_async,
op_truncate_async,
op_link_async,
op_flock_async,
op_fs_chmod_async,
op_fs_ftruncate_async,
op_fs_truncate_async,
op_fs_link_async,
op_fs_flock_async,
} = Deno.core.generateAsyncOpHandler(
"op_chmod_async",
"op_ftruncate_async",
"op_truncate_async",
"op_link_async",
"op_flock_async",
"op_fs_chmod_async",
"op_fs_ftruncate_async",
"op_fs_truncate_async",
"op_fs_link_async",
"op_fs_flock_async",
);
const primordials = globalThis.__bootstrap.primordials;
const {
@ -45,11 +45,11 @@ import {
import { pathFromURL } from "ext:deno_web/00_infra.js";
function chmodSync(path, mode) {
ops.op_chmod_sync(pathFromURL(path), mode);
ops.op_fs_chmod_sync(pathFromURL(path), mode);
}
async function chmod(path, mode) {
await op_chmod_async(pathFromURL(path), mode);
await op_fs_chmod_async(pathFromURL(path), mode);
}
function chownSync(
@ -57,7 +57,7 @@ function chownSync(
uid,
gid,
) {
ops.op_chown_sync(pathFromURL(path), uid, gid);
ops.op_fs_chown_sync(pathFromURL(path), uid, gid);
}
async function chown(
@ -66,7 +66,7 @@ async function chown(
gid,
) {
await core.opAsync(
"op_chown_async",
"op_fs_chown_async",
pathFromURL(path),
uid,
gid,
@ -77,7 +77,7 @@ function copyFileSync(
fromPath,
toPath,
) {
ops.op_copy_file_sync(
ops.op_fs_copy_file_sync(
pathFromURL(fromPath),
pathFromURL(toPath),
);
@ -88,27 +88,31 @@ async function copyFile(
toPath,
) {
await core.opAsync(
"op_copy_file_async",
"op_fs_copy_file_async",
pathFromURL(fromPath),
pathFromURL(toPath),
);
}
function cwd() {
return ops.op_cwd();
return ops.op_fs_cwd();
}
function chdir(directory) {
ops.op_chdir(pathFromURL(directory));
ops.op_fs_chdir(pathFromURL(directory));
}
function makeTempDirSync(options = {}) {
return ops.op_make_temp_dir_sync(options.dir, options.prefix, options.suffix);
return ops.op_fs_make_temp_dir_sync(
options.dir,
options.prefix,
options.suffix,
);
}
function makeTempDir(options = {}) {
return core.opAsync(
"op_make_temp_dir_async",
"op_fs_make_temp_dir_async",
options.dir,
options.prefix,
options.suffix,
@ -116,7 +120,7 @@ function makeTempDir(options = {}) {
}
function makeTempFileSync(options = {}) {
return ops.op_make_temp_file_sync(
return ops.op_fs_make_temp_file_sync(
options.dir,
options.prefix,
options.suffix,
@ -125,7 +129,7 @@ function makeTempFileSync(options = {}) {
function makeTempFile(options = {}) {
return core.opAsync(
"op_make_temp_file_async",
"op_fs_make_temp_file_async",
options.dir,
options.prefix,
options.suffix,
@ -133,7 +137,7 @@ function makeTempFile(options = {}) {
}
function mkdirSync(path, options) {
ops.op_mkdir_sync(
ops.op_fs_mkdir_sync(
pathFromURL(path),
options?.recursive ?? false,
options?.mode,
@ -142,7 +146,7 @@ function mkdirSync(path, options) {
async function mkdir(path, options) {
await core.opAsync(
"op_mkdir_async",
"op_fs_mkdir_async",
pathFromURL(path),
options?.recursive ?? false,
options?.mode,
@ -150,14 +154,14 @@ async function mkdir(path, options) {
}
function readDirSync(path) {
return ops.op_read_dir_sync(pathFromURL(path))[
return ops.op_fs_read_dir_sync(pathFromURL(path))[
SymbolIterator
]();
}
function readDir(path) {
const array = core.opAsync(
"op_read_dir_async",
"op_fs_read_dir_async",
pathFromURL(path),
);
return {
@ -171,26 +175,26 @@ function readDir(path) {
}
function readLinkSync(path) {
return ops.op_read_link_sync(pathFromURL(path));
return ops.op_fs_read_link_sync(pathFromURL(path));
}
function readLink(path) {
return core.opAsync("op_read_link_async", pathFromURL(path));
return core.opAsync("op_fs_read_link_async", pathFromURL(path));
}
function realPathSync(path) {
return ops.op_realpath_sync(pathFromURL(path));
return ops.op_fs_realpath_sync(pathFromURL(path));
}
function realPath(path) {
return core.opAsync("op_realpath_async", pathFromURL(path));
return core.opAsync("op_fs_realpath_async", pathFromURL(path));
}
function removeSync(
path,
options = {},
) {
ops.op_remove_sync(
ops.op_fs_remove_sync(
pathFromURL(path),
!!options.recursive,
);
@ -201,14 +205,14 @@ async function remove(
options = {},
) {
await core.opAsync(
"op_remove_async",
"op_fs_remove_async",
pathFromURL(path),
!!options.recursive,
);
}
function renameSync(oldpath, newpath) {
ops.op_rename_sync(
ops.op_fs_rename_sync(
pathFromURL(oldpath),
pathFromURL(newpath),
);
@ -216,7 +220,7 @@ function renameSync(oldpath, newpath) {
async function rename(oldpath, newpath) {
await core.opAsync(
"op_rename_async",
"op_fs_rename_async",
pathFromURL(oldpath),
pathFromURL(newpath),
);
@ -322,31 +326,31 @@ function parseFileInfo(response) {
}
function fstatSync(rid) {
ops.op_fstat_sync(rid, statBuf);
ops.op_fs_fstat_sync(rid, statBuf);
return statStruct(statBuf);
}
async function fstat(rid) {
return parseFileInfo(await core.opAsync("op_fstat_async", rid));
return parseFileInfo(await core.opAsync("op_fs_fstat_async", rid));
}
async function lstat(path) {
const res = await core.opAsync("op_lstat_async", pathFromURL(path));
const res = await core.opAsync("op_fs_lstat_async", pathFromURL(path));
return parseFileInfo(res);
}
function lstatSync(path) {
ops.op_lstat_sync(pathFromURL(path), statBuf);
ops.op_fs_lstat_sync(pathFromURL(path), statBuf);
return statStruct(statBuf);
}
async function stat(path) {
const res = await core.opAsync("op_stat_async", pathFromURL(path));
const res = await core.opAsync("op_fs_stat_async", pathFromURL(path));
return parseFileInfo(res);
}
function statSync(path) {
ops.op_stat_sync(pathFromURL(path), statBuf);
ops.op_fs_stat_sync(pathFromURL(path), statBuf);
return statStruct(statBuf);
}
@ -358,31 +362,31 @@ function coerceLen(len) {
}
function ftruncateSync(rid, len) {
ops.op_ftruncate_sync(rid, coerceLen(len));
ops.op_fs_ftruncate_sync(rid, coerceLen(len));
}
async function ftruncate(rid, len) {
await op_ftruncate_async(rid, coerceLen(len));
await op_fs_ftruncate_async(rid, coerceLen(len));
}
function truncateSync(path, len) {
ops.op_truncate_sync(path, coerceLen(len));
ops.op_fs_truncate_sync(path, coerceLen(len));
}
async function truncate(path, len) {
await op_truncate_async(path, coerceLen(len));
await op_fs_truncate_async(path, coerceLen(len));
}
function umask(mask) {
return ops.op_umask(mask);
return ops.op_fs_umask(mask);
}
function linkSync(oldpath, newpath) {
ops.op_link_sync(oldpath, newpath);
ops.op_fs_link_sync(oldpath, newpath);
}
async function link(oldpath, newpath) {
await op_link_async(oldpath, newpath);
await op_fs_link_async(oldpath, newpath);
}
function toUnixTimeFromEpoch(value) {
@ -413,7 +417,7 @@ function futimeSync(
) {
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
ops.op_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec);
ops.op_fs_futime_sync(rid, atimeSec, atimeNsec, mtimeSec, mtimeNsec);
}
async function futime(
@ -424,7 +428,7 @@ async function futime(
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
await core.opAsync(
"op_futime_async",
"op_fs_futime_async",
rid,
atimeSec,
atimeNsec,
@ -440,7 +444,7 @@ function utimeSync(
) {
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
ops.op_utime_sync(
ops.op_fs_utime_sync(
pathFromURL(path),
atimeSec,
atimeNsec,
@ -457,7 +461,7 @@ async function utime(
const { 0: atimeSec, 1: atimeNsec } = toUnixTimeFromEpoch(atime);
const { 0: mtimeSec, 1: mtimeNsec } = toUnixTimeFromEpoch(mtime);
await core.opAsync(
"op_utime_async",
"op_fs_utime_async",
pathFromURL(path),
atimeSec,
atimeNsec,
@ -471,7 +475,7 @@ function symlinkSync(
newpath,
options,
) {
ops.op_symlink_sync(
ops.op_fs_symlink_sync(
pathFromURL(oldpath),
pathFromURL(newpath),
options?.type,
@ -484,7 +488,7 @@ async function symlink(
options,
) {
await core.opAsync(
"op_symlink_async",
"op_fs_symlink_async",
pathFromURL(oldpath),
pathFromURL(newpath),
options?.type,
@ -492,35 +496,35 @@ async function symlink(
}
function fdatasyncSync(rid) {
ops.op_fdatasync_sync(rid);
ops.op_fs_fdatasync_sync(rid);
}
async function fdatasync(rid) {
await core.opAsync("op_fdatasync_async", rid);
await core.opAsync("op_fs_fdatasync_async", rid);
}
function fsyncSync(rid) {
ops.op_fsync_sync(rid);
ops.op_fs_fsync_sync(rid);
}
async function fsync(rid) {
await core.opAsync("op_fsync_async", rid);
await core.opAsync("op_fs_fsync_async", rid);
}
function flockSync(rid, exclusive) {
ops.op_flock_sync(rid, exclusive === true);
ops.op_fs_flock_sync(rid, exclusive === true);
}
async function flock(rid, exclusive) {
await op_flock_async(rid, exclusive === true);
await op_fs_flock_async(rid, exclusive === true);
}
function funlockSync(rid) {
ops.op_funlock_sync(rid);
ops.op_fs_funlock_sync(rid);
}
async function funlock(rid) {
await core.opAsync("op_funlock_async", rid);
await core.opAsync("op_fs_funlock_async", rid);
}
function seekSync(
@ -528,7 +532,7 @@ function seekSync(
offset,
whence,
) {
return ops.op_seek_sync(rid, offset, whence);
return ops.op_fs_seek_sync(rid, offset, whence);
}
function seek(
@ -536,7 +540,7 @@ function seek(
offset,
whence,
) {
return core.opAsync("op_seek_async", rid, offset, whence);
return core.opAsync("op_fs_seek_async", rid, offset, whence);
}
function openSync(
@ -544,7 +548,7 @@ function openSync(
options,
) {
if (options) checkOpenOptions(options);
const rid = ops.op_open_sync(
const rid = ops.op_fs_open_sync(
pathFromURL(path),
options,
);
@ -558,7 +562,7 @@ async function open(
) {
if (options) checkOpenOptions(options);
const rid = await core.opAsync(
"op_open_async",
"op_fs_open_async",
pathFromURL(path),
options,
);
@ -685,7 +689,7 @@ function checkOpenOptions(options) {
const File = FsFile;
function readFileSync(path) {
return ops.op_read_file_sync(pathFromURL(path));
return ops.op_fs_read_file_sync(pathFromURL(path));
}
async function readFile(path, options) {
@ -700,7 +704,7 @@ async function readFile(path, options) {
try {
const read = await core.opAsync(
"op_read_file_async",
"op_fs_read_file_async",
pathFromURL(path),
cancelRid,
);
@ -716,7 +720,7 @@ async function readFile(path, options) {
}
function readTextFileSync(path) {
return ops.op_read_file_text_sync(pathFromURL(path));
return ops.op_fs_read_file_text_sync(pathFromURL(path));
}
async function readTextFile(path, options) {
@ -731,7 +735,7 @@ async function readTextFile(path, options) {
try {
const read = await core.opAsync(
"op_read_file_text_async",
"op_fs_read_file_text_async",
pathFromURL(path),
cancelRid,
);
@ -752,7 +756,7 @@ function writeFileSync(
options = {},
) {
options.signal?.throwIfAborted();
ops.op_write_file_sync(
ops.op_fs_write_file_sync(
pathFromURL(path),
options.mode,
options.append ?? false,
@ -789,7 +793,7 @@ async function writeFile(
});
} else {
await core.opAsync(
"op_write_file_async",
"op_fs_write_file_async",
pathFromURL(path),
options.mode,
options.append ?? false,

View file

@ -88,69 +88,69 @@ deno_core::extension!(deno_fs,
deps = [ deno_web ],
parameters = [P: FsPermissions],
ops = [
op_cwd<P>,
op_umask,
op_chdir<P>,
op_fs_cwd<P>,
op_fs_umask,
op_fs_chdir<P>,
op_open_sync<P>,
op_open_async<P>,
op_mkdir_sync<P>,
op_mkdir_async<P>,
op_chmod_sync<P>,
op_chmod_async<P>,
op_chown_sync<P>,
op_chown_async<P>,
op_remove_sync<P>,
op_remove_async<P>,
op_copy_file_sync<P>,
op_copy_file_async<P>,
op_stat_sync<P>,
op_stat_async<P>,
op_lstat_sync<P>,
op_lstat_async<P>,
op_realpath_sync<P>,
op_realpath_async<P>,
op_read_dir_sync<P>,
op_read_dir_async<P>,
op_rename_sync<P>,
op_rename_async<P>,
op_link_sync<P>,
op_link_async<P>,
op_symlink_sync<P>,
op_symlink_async<P>,
op_read_link_sync<P>,
op_read_link_async<P>,
op_truncate_sync<P>,
op_truncate_async<P>,
op_utime_sync<P>,
op_utime_async<P>,
op_make_temp_dir_sync<P>,
op_make_temp_dir_async<P>,
op_make_temp_file_sync<P>,
op_make_temp_file_async<P>,
op_write_file_sync<P>,
op_write_file_async<P>,
op_read_file_sync<P>,
op_read_file_async<P>,
op_read_file_text_sync<P>,
op_read_file_text_async<P>,
op_fs_open_sync<P>,
op_fs_open_async<P>,
op_fs_mkdir_sync<P>,
op_fs_mkdir_async<P>,
op_fs_chmod_sync<P>,
op_fs_chmod_async<P>,
op_fs_chown_sync<P>,
op_fs_chown_async<P>,
op_fs_remove_sync<P>,
op_fs_remove_async<P>,
op_fs_copy_file_sync<P>,
op_fs_copy_file_async<P>,
op_fs_stat_sync<P>,
op_fs_stat_async<P>,
op_fs_lstat_sync<P>,
op_fs_lstat_async<P>,
op_fs_realpath_sync<P>,
op_fs_realpath_async<P>,
op_fs_read_dir_sync<P>,
op_fs_read_dir_async<P>,
op_fs_rename_sync<P>,
op_fs_rename_async<P>,
op_fs_link_sync<P>,
op_fs_link_async<P>,
op_fs_symlink_sync<P>,
op_fs_symlink_async<P>,
op_fs_read_link_sync<P>,
op_fs_read_link_async<P>,
op_fs_truncate_sync<P>,
op_fs_truncate_async<P>,
op_fs_utime_sync<P>,
op_fs_utime_async<P>,
op_fs_make_temp_dir_sync<P>,
op_fs_make_temp_dir_async<P>,
op_fs_make_temp_file_sync<P>,
op_fs_make_temp_file_async<P>,
op_fs_write_file_sync<P>,
op_fs_write_file_async<P>,
op_fs_read_file_sync<P>,
op_fs_read_file_async<P>,
op_fs_read_file_text_sync<P>,
op_fs_read_file_text_async<P>,
op_seek_sync,
op_seek_async,
op_fdatasync_sync,
op_fdatasync_async,
op_fsync_sync,
op_fsync_async,
op_fstat_sync,
op_fstat_async,
op_flock_sync,
op_flock_async,
op_funlock_sync,
op_funlock_async,
op_ftruncate_sync,
op_ftruncate_async,
op_futime_sync,
op_futime_async,
op_fs_seek_sync,
op_fs_seek_async,
op_fs_fdatasync_sync,
op_fs_fdatasync_async,
op_fs_fsync_sync,
op_fs_fsync_async,
op_fs_fstat_sync,
op_fs_fstat_async,
op_fs_flock_sync,
op_fs_flock_async,
op_fs_funlock_sync,
op_fs_funlock_async,
op_fs_ftruncate_sync,
op_fs_ftruncate_async,
op_fs_futime_sync,
op_fs_futime_async,
],
esm = [ "30_fs.js" ],

View file

@ -34,7 +34,7 @@ use crate::FsPermissions;
use crate::OpenOptions;
#[op]
pub fn op_cwd<P>(state: &mut OpState) -> Result<String, AnyError>
pub fn op_fs_cwd<P>(state: &mut OpState) -> Result<String, AnyError>
where
P: FsPermissions + 'static,
{
@ -48,7 +48,7 @@ where
}
#[op]
fn op_chdir<P>(state: &mut OpState, directory: &str) -> Result<(), AnyError>
fn op_fs_chdir<P>(state: &mut OpState, directory: &str) -> Result<(), AnyError>
where
P: FsPermissions + 'static,
{
@ -61,7 +61,10 @@ where
}
#[op]
fn op_umask(state: &mut OpState, mask: Option<u32>) -> Result<u32, AnyError>
fn op_fs_umask(
state: &mut OpState,
mask: Option<u32>,
) -> Result<u32, AnyError>
where
{
check_unstable(state, "Deno.umask");
@ -69,7 +72,7 @@ where
}
#[op]
fn op_open_sync<P>(
fn op_fs_open_sync<P>(
state: &mut OpState,
path: String,
options: Option<OpenOptions>,
@ -93,7 +96,7 @@ where
}
#[op]
async fn op_open_async<P>(
async fn op_fs_open_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
options: Option<OpenOptions>,
@ -123,7 +126,7 @@ where
}
#[op]
fn op_mkdir_sync<P>(
fn op_fs_mkdir_sync<P>(
state: &mut OpState,
path: String,
recursive: bool,
@ -148,7 +151,7 @@ where
}
#[op]
async fn op_mkdir_async<P>(
async fn op_fs_mkdir_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
recursive: bool,
@ -175,7 +178,7 @@ where
}
#[op]
fn op_chmod_sync<P>(
fn op_fs_chmod_sync<P>(
state: &mut OpState,
path: String,
mode: u32,
@ -193,7 +196,7 @@ where
}
#[op]
async fn op_chmod_async<P>(
async fn op_fs_chmod_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
mode: u32,
@ -214,7 +217,7 @@ where
}
#[op]
fn op_chown_sync<P>(
fn op_fs_chown_sync<P>(
state: &mut OpState,
path: String,
uid: Option<u32>,
@ -234,7 +237,7 @@ where
}
#[op]
async fn op_chown_async<P>(
async fn op_fs_chown_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
uid: Option<u32>,
@ -256,7 +259,7 @@ where
}
#[op]
fn op_remove_sync<P>(
fn op_fs_remove_sync<P>(
state: &mut OpState,
path: &str,
recursive: bool,
@ -278,7 +281,7 @@ where
}
#[op]
async fn op_remove_async<P>(
async fn op_fs_remove_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
recursive: bool,
@ -304,7 +307,7 @@ where
}
#[op]
fn op_copy_file_sync<P>(
fn op_fs_copy_file_sync<P>(
state: &mut OpState,
from: &str,
to: &str,
@ -327,7 +330,7 @@ where
}
#[op]
async fn op_copy_file_async<P>(
async fn op_fs_copy_file_async<P>(
state: Rc<RefCell<OpState>>,
from: String,
to: String,
@ -354,7 +357,7 @@ where
}
#[op]
fn op_stat_sync<P>(
fn op_fs_stat_sync<P>(
state: &mut OpState,
path: String,
stat_out_buf: &mut [u32],
@ -374,7 +377,7 @@ where
}
#[op]
async fn op_stat_async<P>(
async fn op_fs_stat_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
) -> Result<SerializableStat, AnyError>
@ -396,7 +399,7 @@ where
}
#[op]
fn op_lstat_sync<P>(
fn op_fs_lstat_sync<P>(
state: &mut OpState,
path: String,
stat_out_buf: &mut [u32],
@ -416,7 +419,7 @@ where
}
#[op]
async fn op_lstat_async<P>(
async fn op_fs_lstat_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
) -> Result<SerializableStat, AnyError>
@ -438,7 +441,7 @@ where
}
#[op]
fn op_realpath_sync<P>(
fn op_fs_realpath_sync<P>(
state: &mut OpState,
path: String,
) -> Result<String, AnyError>
@ -462,7 +465,7 @@ where
}
#[op]
async fn op_realpath_async<P>(
async fn op_fs_realpath_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
) -> Result<String, AnyError>
@ -491,7 +494,7 @@ where
}
#[op]
fn op_read_dir_sync<P>(
fn op_fs_read_dir_sync<P>(
state: &mut OpState,
path: String,
) -> Result<Vec<FsDirEntry>, AnyError>
@ -511,7 +514,7 @@ where
}
#[op]
async fn op_read_dir_async<P>(
async fn op_fs_read_dir_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
) -> Result<Vec<FsDirEntry>, AnyError>
@ -537,7 +540,7 @@ where
}
#[op]
fn op_rename_sync<P>(
fn op_fs_rename_sync<P>(
state: &mut OpState,
oldpath: String,
newpath: String,
@ -561,7 +564,7 @@ where
}
#[op]
async fn op_rename_async<P>(
async fn op_fs_rename_async<P>(
state: Rc<RefCell<OpState>>,
oldpath: String,
newpath: String,
@ -589,7 +592,7 @@ where
}
#[op]
fn op_link_sync<P>(
fn op_fs_link_sync<P>(
state: &mut OpState,
oldpath: &str,
newpath: &str,
@ -614,7 +617,7 @@ where
}
#[op]
async fn op_link_async<P>(
async fn op_fs_link_async<P>(
state: Rc<RefCell<OpState>>,
oldpath: String,
newpath: String,
@ -643,7 +646,7 @@ where
}
#[op]
fn op_symlink_sync<P>(
fn op_fs_symlink_sync<P>(
state: &mut OpState,
oldpath: &str,
newpath: &str,
@ -667,7 +670,7 @@ where
}
#[op]
async fn op_symlink_async<P>(
async fn op_fs_symlink_async<P>(
state: Rc<RefCell<OpState>>,
oldpath: String,
newpath: String,
@ -695,7 +698,7 @@ where
}
#[op]
fn op_read_link_sync<P>(
fn op_fs_read_link_sync<P>(
state: &mut OpState,
path: String,
) -> Result<String, AnyError>
@ -716,7 +719,7 @@ where
}
#[op]
async fn op_read_link_async<P>(
async fn op_fs_read_link_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
) -> Result<String, AnyError>
@ -742,7 +745,7 @@ where
}
#[op]
fn op_truncate_sync<P>(
fn op_fs_truncate_sync<P>(
state: &mut OpState,
path: &str,
len: u64,
@ -764,7 +767,7 @@ where
}
#[op]
async fn op_truncate_async<P>(
async fn op_fs_truncate_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
len: u64,
@ -790,7 +793,7 @@ where
}
#[op]
fn op_utime_sync<P>(
fn op_fs_utime_sync<P>(
state: &mut OpState,
path: &str,
atime_secs: i64,
@ -813,7 +816,7 @@ where
}
#[op]
async fn op_utime_async<P>(
async fn op_fs_utime_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
atime_secs: i64,
@ -846,7 +849,7 @@ where
}
#[op]
fn op_make_temp_dir_sync<P>(
fn op_fs_make_temp_dir_sync<P>(
state: &mut OpState,
dir: Option<String>,
prefix: Option<String>,
@ -879,7 +882,7 @@ where
}
#[op]
async fn op_make_temp_dir_async<P>(
async fn op_fs_make_temp_dir_async<P>(
state: Rc<RefCell<OpState>>,
dir: Option<String>,
prefix: Option<String>,
@ -912,7 +915,7 @@ where
}
#[op]
fn op_make_temp_file_sync<P>(
fn op_fs_make_temp_file_sync<P>(
state: &mut OpState,
dir: Option<String>,
prefix: Option<String>,
@ -952,7 +955,7 @@ where
}
#[op]
async fn op_make_temp_file_async<P>(
async fn op_fs_make_temp_file_async<P>(
state: Rc<RefCell<OpState>>,
dir: Option<String>,
prefix: Option<String>,
@ -1067,7 +1070,7 @@ fn tmp_name(
}
#[op]
fn op_write_file_sync<P>(
fn op_fs_write_file_sync<P>(
state: &mut OpState,
path: String,
mode: Option<u32>,
@ -1094,7 +1097,7 @@ where
}
#[op]
async fn op_write_file_async<P>(
async fn op_fs_write_file_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
mode: Option<u32>,
@ -1138,7 +1141,7 @@ where
}
#[op]
fn op_read_file_sync<P>(
fn op_fs_read_file_sync<P>(
state: &mut OpState,
path: String,
) -> Result<ZeroCopyBuf, AnyError>
@ -1157,7 +1160,7 @@ where
}
#[op]
async fn op_read_file_async<P>(
async fn op_fs_read_file_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
cancel_rid: Option<ResourceId>,
@ -1194,7 +1197,7 @@ where
}
#[op]
fn op_read_file_text_sync<P>(
fn op_fs_read_file_text_sync<P>(
state: &mut OpState,
path: String,
) -> Result<String, AnyError>
@ -1213,7 +1216,7 @@ where
}
#[op]
async fn op_read_file_text_async<P>(
async fn op_fs_read_file_text_async<P>(
state: Rc<RefCell<OpState>>,
path: String,
cancel_rid: Option<ResourceId>,
@ -1273,7 +1276,7 @@ fn to_seek_from(offset: i64, whence: i32) -> Result<SeekFrom, AnyError> {
}
#[op]
fn op_seek_sync(
fn op_fs_seek_sync(
state: &mut OpState,
rid: ResourceId,
offset: i64,
@ -1286,7 +1289,7 @@ fn op_seek_sync(
}
#[op]
async fn op_seek_async(
async fn op_fs_seek_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
offset: i64,
@ -1299,7 +1302,7 @@ async fn op_seek_async(
}
#[op]
fn op_fdatasync_sync(
fn op_fs_fdatasync_sync(
state: &mut OpState,
rid: ResourceId,
) -> Result<(), AnyError> {
@ -1309,7 +1312,7 @@ fn op_fdatasync_sync(
}
#[op]
async fn op_fdatasync_async(
async fn op_fs_fdatasync_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
) -> Result<(), AnyError> {
@ -1319,14 +1322,17 @@ async fn op_fdatasync_async(
}
#[op]
fn op_fsync_sync(state: &mut OpState, rid: ResourceId) -> Result<(), AnyError> {
fn op_fs_fsync_sync(
state: &mut OpState,
rid: ResourceId,
) -> Result<(), AnyError> {
let file = FileResource::get_file(state, rid)?;
file.sync_sync()?;
Ok(())
}
#[op]
async fn op_fsync_async(
async fn op_fs_fsync_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
) -> Result<(), AnyError> {
@ -1336,7 +1342,7 @@ async fn op_fsync_async(
}
#[op]
fn op_fstat_sync(
fn op_fs_fstat_sync(
state: &mut OpState,
rid: ResourceId,
stat_out_buf: &mut [u32],
@ -1349,7 +1355,7 @@ fn op_fstat_sync(
}
#[op]
async fn op_fstat_async(
async fn op_fs_fstat_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
) -> Result<SerializableStat, AnyError> {
@ -1359,7 +1365,7 @@ async fn op_fstat_async(
}
#[op]
fn op_flock_sync(
fn op_fs_flock_sync(
state: &mut OpState,
rid: ResourceId,
exclusive: bool,
@ -1371,7 +1377,7 @@ fn op_flock_sync(
}
#[op]
async fn op_flock_async(
async fn op_fs_flock_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
exclusive: bool,
@ -1383,7 +1389,7 @@ async fn op_flock_async(
}
#[op]
fn op_funlock_sync(
fn op_fs_funlock_sync(
state: &mut OpState,
rid: ResourceId,
) -> Result<(), AnyError> {
@ -1394,7 +1400,7 @@ fn op_funlock_sync(
}
#[op]
async fn op_funlock_async(
async fn op_fs_funlock_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
) -> Result<(), AnyError> {
@ -1405,7 +1411,7 @@ async fn op_funlock_async(
}
#[op]
fn op_ftruncate_sync(
fn op_fs_ftruncate_sync(
state: &mut OpState,
rid: ResourceId,
len: u64,
@ -1416,7 +1422,7 @@ fn op_ftruncate_sync(
}
#[op]
async fn op_ftruncate_async(
async fn op_fs_ftruncate_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
len: u64,
@ -1427,7 +1433,7 @@ async fn op_ftruncate_async(
}
#[op]
fn op_futime_sync(
fn op_fs_futime_sync(
state: &mut OpState,
rid: ResourceId,
atime_secs: i64,
@ -1441,7 +1447,7 @@ fn op_futime_sync(
}
#[op]
async fn op_futime_async(
async fn op_fs_futime_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
atime_secs: i64,

View file

@ -50,35 +50,35 @@ const {
const {
op_http_wait,
op_upgrade,
op_get_request_headers,
op_get_request_method_and_url,
op_read_request_body,
op_serve_http,
op_set_promise_complete,
op_set_response_body_bytes,
op_set_response_body_resource,
op_set_response_body_stream,
op_set_response_body_text,
op_set_response_header,
op_set_response_headers,
op_upgrade_raw,
op_http_upgrade_next,
op_http_get_request_headers,
op_http_get_request_method_and_url,
op_http_read_request_body,
op_http_serve,
op_http_set_promise_complete,
op_http_set_response_body_bytes,
op_http_set_response_body_resource,
op_http_set_response_body_stream,
op_http_set_response_body_text,
op_http_set_response_header,
op_http_set_response_headers,
op_http_upgrade_raw,
op_ws_server_create,
} = core.generateAsyncOpHandler(
"op_http_wait",
"op_upgrade",
"op_get_request_headers",
"op_get_request_method_and_url",
"op_read_request_body",
"op_serve_http",
"op_set_promise_complete",
"op_set_response_body_bytes",
"op_set_response_body_resource",
"op_set_response_body_stream",
"op_set_response_body_text",
"op_set_response_header",
"op_set_response_headers",
"op_upgrade_raw",
"op_http_upgrade_next",
"op_http_get_request_headers",
"op_http_get_request_method_and_url",
"op_http_read_request_body",
"op_http_serve",
"op_http_set_promise_complete",
"op_http_set_response_body_bytes",
"op_http_set_response_body_resource",
"op_http_set_response_body_stream",
"op_http_set_response_body_text",
"op_http_set_response_header",
"op_http_set_response_headers",
"op_http_upgrade_raw",
"op_ws_server_create",
);
const _upgraded = Symbol("_upgraded");
@ -178,7 +178,7 @@ class InnerRequest {
this.#upgraded = () => {};
const upgradeRid = op_upgrade_raw(slabId);
const upgradeRid = op_http_upgrade_raw(slabId);
const conn = new TcpConn(
upgradeRid,
@ -209,7 +209,7 @@ class InnerRequest {
(async () => {
try {
// Returns the connection and extra bytes, which we can pass directly to op_ws_server_create
const upgrade = await op_upgrade(
const upgrade = await op_http_upgrade_next(
slabId,
response.headerList,
);
@ -248,7 +248,7 @@ class InnerRequest {
}
// TODO(mmastrac): This is quite slow as we're serializing a large number of values. We may want to consider
// splitting this up into multiple ops.
this.#methodAndUri = op_get_request_method_and_url(this.#slabId);
this.#methodAndUri = op_http_get_request_method_and_url(this.#slabId);
}
const path = this.#methodAndUri[2];
@ -283,7 +283,7 @@ class InnerRequest {
if (this.#slabId === undefined) {
throw new TypeError("request closed");
}
this.#methodAndUri = op_get_request_method_and_url(this.#slabId);
this.#methodAndUri = op_http_get_request_method_and_url(this.#slabId);
}
return {
transport: "tcp",
@ -297,7 +297,7 @@ class InnerRequest {
if (this.#slabId === undefined) {
throw new TypeError("request closed");
}
this.#methodAndUri = op_get_request_method_and_url(this.#slabId);
this.#methodAndUri = op_http_get_request_method_and_url(this.#slabId);
}
return this.#methodAndUri[0];
}
@ -315,7 +315,7 @@ class InnerRequest {
this.#body = null;
return null;
}
this.#streamRid = op_read_request_body(this.#slabId);
this.#streamRid = op_http_read_request_body(this.#slabId);
this.#body = new InnerBody(readableStreamForRid(this.#streamRid, false));
return this.#body;
}
@ -324,7 +324,7 @@ class InnerRequest {
if (this.#slabId === undefined) {
throw new TypeError("request closed");
}
return op_get_request_headers(this.#slabId);
return op_http_get_request_headers(this.#slabId);
}
get slabId() {
@ -365,12 +365,12 @@ function fastSyncResponseOrStream(req, respBody) {
const body = stream.body;
if (ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, body)) {
op_set_response_body_bytes(req, body);
op_http_set_response_body_bytes(req, body);
return null;
}
if (typeof body === "string") {
op_set_response_body_text(req, body);
op_http_set_response_body_text(req, body);
return null;
}
@ -380,7 +380,7 @@ function fastSyncResponseOrStream(req, respBody) {
}
const resourceBacking = getReadableStreamResourceBacking(stream);
if (resourceBacking) {
op_set_response_body_resource(
op_http_set_response_body_resource(
req,
resourceBacking.rid,
resourceBacking.autoClose,
@ -416,9 +416,9 @@ async function asyncResponse(responseBodies, req, status, stream) {
// and we race it.
let timeoutPromise;
timeout = setTimeout(() => {
responseRid = op_set_response_body_stream(req);
responseRid = op_http_set_response_body_stream(req);
SetPrototypeAdd(responseBodies, responseRid);
op_set_promise_complete(req, status);
op_http_set_promise_complete(req, status);
timeoutPromise = core.writeAll(responseRid, value1);
}, 250);
const { value: value2, done: done2 } = await reader.read();
@ -443,13 +443,13 @@ async function asyncResponse(responseBodies, req, status, stream) {
// Reader will be closed by finally block
// No response stream
closed = true;
op_set_response_body_bytes(req, value1);
op_http_set_response_body_bytes(req, value1);
return;
}
responseRid = op_set_response_body_stream(req);
responseRid = op_http_set_response_body_stream(req);
SetPrototypeAdd(responseBodies, responseRid);
op_set_promise_complete(req, status);
op_http_set_promise_complete(req, status);
// Write our first packet
await core.writeAll(responseRid, value1);
}
@ -481,7 +481,7 @@ async function asyncResponse(responseBodies, req, status, stream) {
core.tryClose(responseRid);
SetPrototypeDelete(responseBodies, responseRid);
} else {
op_set_promise_complete(req, status);
op_http_set_promise_complete(req, status);
}
}
}
@ -545,9 +545,9 @@ function mapToCallback(responseBodies, context, signal, callback, onError) {
const headers = inner.headerList;
if (headers && headers.length > 0) {
if (headers.length == 1) {
op_set_response_header(req, headers[0][0], headers[0][1]);
op_http_set_response_header(req, headers[0][0], headers[0][1]);
} else {
op_set_response_headers(req, headers);
op_http_set_response_headers(req, headers);
}
}
@ -557,7 +557,7 @@ function mapToCallback(responseBodies, context, signal, callback, onError) {
// Handle the stream asynchronously
await asyncResponse(responseBodies, req, status, stream);
} else {
op_set_promise_complete(req, status);
op_http_set_promise_complete(req, status);
}
innerRequest?.close();
@ -625,13 +625,13 @@ async function serve(arg1, arg2) {
listenOpts.alpnProtocols = ["h2", "http/1.1"];
const listener = Deno.listenTls(listenOpts);
listenOpts.port = listener.addr.port;
context.initialize(op_serve_http(
context.initialize(op_http_serve(
listener.rid,
));
} else {
const listener = Deno.listen(listenOpts);
listenOpts.port = listener.addr.port;
context.initialize(op_serve_http(
context.initialize(op_http_serve(
listener.rid,
));
}

View file

@ -235,7 +235,7 @@ fn slab_insert(
}
#[op]
pub fn op_upgrade_raw(
pub fn op_http_upgrade_raw(
state: &mut OpState,
index: u32,
) -> Result<ResourceId, AnyError> {
@ -310,7 +310,7 @@ pub fn op_upgrade_raw(
}
#[op]
pub async fn op_upgrade(
pub async fn op_http_upgrade_next(
state: Rc<RefCell<OpState>>,
index: u32,
headers: Vec<(ByteString, ByteString)>,
@ -353,7 +353,7 @@ pub async fn op_upgrade(
}
#[op(fast)]
pub fn op_set_promise_complete(index: u32, status: u16) {
pub fn op_http_set_promise_complete(index: u32, status: u16) {
with_resp_mut(index, |resp| {
// The Javascript code will never provide a status that is invalid here (see 23_response.js)
*resp.as_mut().unwrap().status_mut() =
@ -365,7 +365,7 @@ pub fn op_set_promise_complete(index: u32, status: u16) {
}
#[op]
pub fn op_get_request_method_and_url(
pub fn op_http_get_request_method_and_url(
index: u32,
) -> (String, Option<String>, String, String, Option<u16>) {
// TODO(mmastrac): Passing method can be optimized
@ -393,7 +393,10 @@ pub fn op_get_request_method_and_url(
}
#[op]
pub fn op_get_request_header(index: u32, name: String) -> Option<ByteString> {
pub fn op_http_get_request_header(
index: u32,
name: String,
) -> Option<ByteString> {
with_req(index, |req| {
let value = req.headers.get(name);
value.map(|value| value.as_bytes().into())
@ -401,7 +404,9 @@ pub fn op_get_request_header(index: u32, name: String) -> Option<ByteString> {
}
#[op]
pub fn op_get_request_headers(index: u32) -> Vec<(ByteString, ByteString)> {
pub fn op_http_get_request_headers(
index: u32,
) -> Vec<(ByteString, ByteString)> {
with_req(index, |req| {
let headers = &req.headers;
let mut vec = Vec::with_capacity(headers.len());
@ -436,7 +441,10 @@ pub fn op_get_request_headers(index: u32) -> Vec<(ByteString, ByteString)> {
}
#[op(fast)]
pub fn op_read_request_body(state: &mut OpState, index: u32) -> ResourceId {
pub fn op_http_read_request_body(
state: &mut OpState,
index: u32,
) -> ResourceId {
let incoming = with_req_body_mut(index, |body| body.take().unwrap());
let body_resource = Rc::new(HttpRequestBody::new(incoming));
let res = state.resource_table.add_rc(body_resource.clone());
@ -447,7 +455,7 @@ pub fn op_read_request_body(state: &mut OpState, index: u32) -> ResourceId {
}
#[op(fast)]
pub fn op_set_response_header(index: u32, name: &str, value: &str) {
pub fn op_http_set_response_header(index: u32, name: &str, value: &str) {
with_resp_mut(index, |resp| {
let resp_headers = resp.as_mut().unwrap().headers_mut();
// These are valid latin-1 strings
@ -458,7 +466,7 @@ pub fn op_set_response_header(index: u32, name: &str, value: &str) {
}
#[op]
pub fn op_set_response_headers(
pub fn op_http_set_response_headers(
index: u32,
headers: Vec<(ByteString, ByteString)>,
) {
@ -476,7 +484,7 @@ pub fn op_set_response_headers(
}
#[op(fast)]
pub fn op_set_response_body_resource(
pub fn op_http_set_response_body_resource(
state: &mut OpState,
index: u32,
stream_rid: ResourceId,
@ -502,7 +510,7 @@ pub fn op_set_response_body_resource(
}
#[op(fast)]
pub fn op_set_response_body_stream(
pub fn op_http_set_response_body_stream(
state: &mut OpState,
index: u32,
) -> Result<ResourceId, AnyError> {
@ -521,7 +529,7 @@ pub fn op_set_response_body_stream(
}
#[op(fast)]
pub fn op_set_response_body_text(index: u32, text: String) {
pub fn op_http_set_response_body_text(index: u32, text: String) {
if !text.is_empty() {
with_resp_mut(index, move |response| {
response
@ -534,7 +542,7 @@ pub fn op_set_response_body_text(index: u32, text: String) {
}
#[op(fast)]
pub fn op_set_response_body_bytes(index: u32, buffer: &[u8]) {
pub fn op_http_set_response_body_bytes(index: u32, buffer: &[u8]) {
if !buffer.is_empty() {
with_resp_mut(index, |response| {
response
@ -759,7 +767,7 @@ impl Drop for HttpJoinHandle {
}
#[op(v8)]
pub fn op_serve_http(
pub fn op_http_serve(
state: Rc<RefCell<OpState>>,
listener_rid: ResourceId,
) -> Result<(ResourceId, &'static str, String), AnyError> {
@ -814,7 +822,7 @@ pub fn op_serve_http(
}
#[op(v8)]
pub fn op_serve_http_on(
pub fn op_http_serve_on(
state: Rc<RefCell<OpState>>,
conn: ResourceId,
) -> Result<(ResourceId, &'static str, String), AnyError> {

View file

@ -88,30 +88,30 @@ deno_core::extension!(
deps = [deno_web, deno_net, deno_fetch, deno_websocket],
ops = [
op_http_accept,
op_http_write_headers,
op_http_headers,
op_http_write,
op_http_write_resource,
op_http_shutdown,
op_http_websocket_accept_header,
op_http_upgrade_websocket,
http_next::op_serve_http,
http_next::op_serve_http_on,
http_next::op_http_wait,
op_http_websocket_accept_header,
op_http_write_headers,
op_http_write_resource,
op_http_write,
http_next::op_http_get_request_header,
http_next::op_http_get_request_headers,
http_next::op_http_get_request_method_and_url,
http_next::op_http_read_request_body,
http_next::op_http_serve_on,
http_next::op_http_serve,
http_next::op_http_set_promise_complete,
http_next::op_http_set_response_body_bytes,
http_next::op_http_set_response_body_resource,
http_next::op_http_set_response_body_stream,
http_next::op_http_set_response_body_text,
http_next::op_http_set_response_header,
http_next::op_http_set_response_headers,
http_next::op_http_track,
http_next::op_set_response_header,
http_next::op_set_response_headers,
http_next::op_set_response_body_text,
http_next::op_set_promise_complete,
http_next::op_set_response_body_bytes,
http_next::op_set_response_body_resource,
http_next::op_set_response_body_stream,
http_next::op_get_request_header,
http_next::op_get_request_headers,
http_next::op_get_request_method_and_url,
http_next::op_read_request_body,
http_next::op_upgrade,
http_next::op_upgrade_raw,
http_next::op_http_upgrade_raw,
http_next::op_http_upgrade_next,
http_next::op_http_wait,
],
esm = ["00_serve.js", "01_http.js"],
);