0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-15 01:57:09 -05:00

Merge branch 'main' into support_create_connection

This commit is contained in:
Yoshiya Hinosawa 2024-12-04 11:52:11 +09:00 committed by GitHub
commit 502a6d21ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
559 changed files with 30894 additions and 950 deletions

View file

@ -1262,7 +1262,7 @@ impl DenoDiagnostic {
Self::NoAttributeType => (lsp::DiagnosticSeverity::ERROR, "The module is a JSON module and not being imported with an import attribute. Consider adding `with { type: \"json\" }` to the import statement.".to_string(), None),
Self::NoCache(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing remote URL: {specifier}"), Some(json!({ "specifier": specifier }))),
Self::NotInstalledJsr(pkg_req, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("JSR package \"{pkg_req}\" is not installed or doesn't exist."), Some(json!({ "specifier": specifier }))),
Self::NotInstalledNpm(pkg_req, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("NPM package \"{pkg_req}\" is not installed or doesn't exist."), Some(json!({ "specifier": specifier }))),
Self::NotInstalledNpm(pkg_req, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("npm package \"{pkg_req}\" is not installed or doesn't exist."), Some(json!({ "specifier": specifier }))),
Self::NoLocal(specifier) => {
let maybe_sloppy_resolution = CliSloppyImportsResolver::new(
SloppyImportsCachedFs::new(Arc::new(deno_fs::RealFs))

View file

@ -44,7 +44,6 @@ use crate::util::fs::canonicalize_path_maybe_not_exists_with_fs;
use crate::util::progress_bar::ProgressBar;
use crate::util::sync::AtomicFlag;
use self::registry::CliNpmRegistryApi;
use self::resolution::NpmResolution;
use self::resolvers::create_npm_fs_resolver;
use self::resolvers::NpmPackageFsResolver;
@ -57,7 +56,6 @@ use super::CliNpmTarballCache;
use super::InnerCliNpmResolverRef;
use super::ResolvePkgFolderFromDenoReqError;
mod registry;
mod resolution;
mod resolvers;
@ -120,13 +118,13 @@ pub async fn create_managed_npm_resolver(
) -> Result<Arc<dyn CliNpmResolver>, AnyError> {
let npm_cache_env = create_cache_env(&options);
let npm_cache = create_cache(npm_cache_env.clone(), &options);
let npm_api = create_api(npm_cache.clone(), npm_cache_env.clone(), &options);
let snapshot = resolve_snapshot(&npm_api, options.snapshot).await?;
let api = create_api(npm_cache.clone(), npm_cache_env.clone(), &options);
let snapshot = resolve_snapshot(&api, options.snapshot).await?;
Ok(create_inner(
npm_cache_env,
options.fs,
options.maybe_lockfile,
npm_api,
api,
npm_cache,
options.npmrc,
options.npm_install_deps_provider,
@ -143,7 +141,7 @@ fn create_inner(
env: Arc<CliNpmCacheEnv>,
fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
npm_cache: Arc<CliNpmCache>,
npm_rc: Arc<ResolvedNpmRc>,
npm_install_deps_provider: Arc<NpmInstallDepsProvider>,
@ -154,7 +152,7 @@ fn create_inner(
lifecycle_scripts: LifecycleScriptsConfig,
) -> Arc<dyn CliNpmResolver> {
let resolution = Arc::new(NpmResolution::from_serialized(
npm_api.clone(),
registry_info_provider.clone(),
snapshot,
maybe_lockfile.clone(),
));
@ -178,7 +176,7 @@ fn create_inner(
fs,
fs_resolver,
maybe_lockfile,
npm_api,
registry_info_provider,
npm_cache,
npm_install_deps_provider,
resolution,
@ -215,29 +213,29 @@ fn create_api(
cache: Arc<CliNpmCache>,
env: Arc<CliNpmCacheEnv>,
options: &CliManagedNpmResolverCreateOptions,
) -> Arc<CliNpmRegistryApi> {
Arc::new(CliNpmRegistryApi::new(
cache.clone(),
Arc::new(CliNpmRegistryInfoProvider::new(
cache,
env,
options.npmrc.clone(),
)),
) -> Arc<CliNpmRegistryInfoProvider> {
Arc::new(CliNpmRegistryInfoProvider::new(
cache,
env,
options.npmrc.clone(),
))
}
async fn resolve_snapshot(
api: &CliNpmRegistryApi,
registry_info_provider: &Arc<CliNpmRegistryInfoProvider>,
snapshot: CliNpmResolverManagedSnapshotOption,
) -> Result<Option<ValidSerializedNpmResolutionSnapshot>, AnyError> {
match snapshot {
CliNpmResolverManagedSnapshotOption::ResolveFromLockfile(lockfile) => {
if !lockfile.overwrite() {
let snapshot = snapshot_from_lockfile(lockfile.clone(), api)
.await
.with_context(|| {
format!("failed reading lockfile '{}'", lockfile.filename.display())
})?;
let snapshot = snapshot_from_lockfile(
lockfile.clone(),
&registry_info_provider.as_npm_registry_api(),
)
.await
.with_context(|| {
format!("failed reading lockfile '{}'", lockfile.filename.display())
})?;
Ok(Some(snapshot))
} else {
Ok(None)
@ -304,7 +302,7 @@ pub struct ManagedCliNpmResolver {
fs: Arc<dyn FileSystem>,
fs_resolver: Arc<dyn NpmPackageFsResolver>,
maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
npm_cache: Arc<CliNpmCache>,
npm_install_deps_provider: Arc<NpmInstallDepsProvider>,
resolution: Arc<NpmResolution>,
@ -329,7 +327,7 @@ impl ManagedCliNpmResolver {
fs: Arc<dyn FileSystem>,
fs_resolver: Arc<dyn NpmPackageFsResolver>,
maybe_lockfile: Option<Arc<CliLockfile>>,
npm_api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
npm_cache: Arc<CliNpmCache>,
npm_install_deps_provider: Arc<NpmInstallDepsProvider>,
resolution: Arc<NpmResolution>,
@ -342,7 +340,7 @@ impl ManagedCliNpmResolver {
fs,
fs_resolver,
maybe_lockfile,
npm_api,
registry_info_provider,
npm_cache,
npm_install_deps_provider,
text_only_progress_bar,
@ -588,7 +586,7 @@ impl ManagedCliNpmResolver {
) -> Result<Arc<NpmPackageInfo>, AnyError> {
// this will internally cache the package information
self
.npm_api
.registry_info_provider
.package_info(package_name)
.await
.map_err(|err| err.into())
@ -684,7 +682,7 @@ impl CliNpmResolver for ManagedCliNpmResolver {
fn clone_snapshotted(&self) -> Arc<dyn CliNpmResolver> {
// create a new snapshotted npm resolution and resolver
let npm_resolution = Arc::new(NpmResolution::new(
self.npm_api.clone(),
self.registry_info_provider.clone(),
self.resolution.snapshot(),
self.maybe_lockfile.clone(),
));
@ -703,7 +701,7 @@ impl CliNpmResolver for ManagedCliNpmResolver {
self.lifecycle_scripts.clone(),
),
self.maybe_lockfile.clone(),
self.npm_api.clone(),
self.registry_info_provider.clone(),
self.npm_cache.clone(),
self.npm_install_deps_provider.clone(),
npm_resolution,

View file

@ -1,201 +0,0 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use async_trait::async_trait;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::futures::future::BoxFuture;
use deno_core::futures::future::Shared;
use deno_core::futures::FutureExt;
use deno_core::parking_lot::Mutex;
use deno_npm::registry::NpmPackageInfo;
use deno_npm::registry::NpmRegistryApi;
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
use deno_npm_cache::NpmCacheSetting;
use crate::npm::CliNpmCache;
use crate::npm::CliNpmRegistryInfoProvider;
use crate::util::sync::AtomicFlag;
// todo(#27198): Remove this and move functionality down into
// RegistryInfoProvider, which already does most of this.
#[derive(Debug)]
pub struct CliNpmRegistryApi(Option<Arc<CliNpmRegistryApiInner>>);
impl CliNpmRegistryApi {
pub fn new(
cache: Arc<CliNpmCache>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
) -> Self {
Self(Some(Arc::new(CliNpmRegistryApiInner {
cache,
force_reload_flag: Default::default(),
mem_cache: Default::default(),
previously_reloaded_packages: Default::default(),
registry_info_provider,
})))
}
/// Clears the internal memory cache.
pub fn clear_memory_cache(&self) {
self.inner().clear_memory_cache();
}
fn inner(&self) -> &Arc<CliNpmRegistryApiInner> {
// this panicking indicates a bug in the code where this
// wasn't initialized
self.0.as_ref().unwrap()
}
}
#[async_trait(?Send)]
impl NpmRegistryApi for CliNpmRegistryApi {
async fn package_info(
&self,
name: &str,
) -> Result<Arc<NpmPackageInfo>, NpmRegistryPackageInfoLoadError> {
match self.inner().maybe_package_info(name).await {
Ok(Some(info)) => Ok(info),
Ok(None) => Err(NpmRegistryPackageInfoLoadError::PackageNotExists {
package_name: name.to_string(),
}),
Err(err) => {
Err(NpmRegistryPackageInfoLoadError::LoadError(Arc::new(err)))
}
}
}
fn mark_force_reload(&self) -> bool {
self.inner().mark_force_reload()
}
}
type CacheItemPendingResult =
Result<Option<Arc<NpmPackageInfo>>, Arc<AnyError>>;
#[derive(Debug)]
enum CacheItem {
Pending(Shared<BoxFuture<'static, CacheItemPendingResult>>),
Resolved(Option<Arc<NpmPackageInfo>>),
}
#[derive(Debug)]
struct CliNpmRegistryApiInner {
cache: Arc<CliNpmCache>,
force_reload_flag: AtomicFlag,
mem_cache: Mutex<HashMap<String, CacheItem>>,
previously_reloaded_packages: Mutex<HashSet<String>>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
}
impl CliNpmRegistryApiInner {
pub async fn maybe_package_info(
self: &Arc<Self>,
name: &str,
) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> {
let (created, future) = {
let mut mem_cache = self.mem_cache.lock();
match mem_cache.get(name) {
Some(CacheItem::Resolved(maybe_info)) => {
return Ok(maybe_info.clone());
}
Some(CacheItem::Pending(future)) => (false, future.clone()),
None => {
let future = {
let api = self.clone();
let name = name.to_string();
async move {
if (api.cache.cache_setting().should_use_for_npm_package(&name) && !api.force_reload_flag.is_raised())
// if this has been previously reloaded, then try loading from the
// file system cache
|| !api.previously_reloaded_packages.lock().insert(name.to_string())
{
// attempt to load from the file cache
if let Some(info) = api.load_file_cached_package_info(&name).await {
let result = Some(Arc::new(info));
return Ok(result);
}
}
api.registry_info_provider
.load_package_info(&name)
.await
.map_err(Arc::new)
}
.boxed()
.shared()
};
mem_cache
.insert(name.to_string(), CacheItem::Pending(future.clone()));
(true, future)
}
}
};
if created {
match future.await {
Ok(maybe_info) => {
// replace the cache item to say it's resolved now
self
.mem_cache
.lock()
.insert(name.to_string(), CacheItem::Resolved(maybe_info.clone()));
Ok(maybe_info)
}
Err(err) => {
// purge the item from the cache so it loads next time
self.mem_cache.lock().remove(name);
Err(anyhow!("{:#}", err))
}
}
} else {
Ok(future.await.map_err(|err| anyhow!("{:#}", err))?)
}
}
fn mark_force_reload(&self) -> bool {
// never force reload the registry information if reloading
// is disabled or if we're already reloading
if matches!(
self.cache.cache_setting(),
NpmCacheSetting::Only | NpmCacheSetting::ReloadAll
) {
return false;
}
if self.force_reload_flag.raise() {
self.clear_memory_cache();
true
} else {
false
}
}
async fn load_file_cached_package_info(
&self,
name: &str,
) -> Option<NpmPackageInfo> {
let result = deno_core::unsync::spawn_blocking({
let cache = self.cache.clone();
let name = name.to_string();
move || cache.load_package_info(&name)
})
.await
.unwrap();
match result {
Ok(value) => value,
Err(err) => {
if cfg!(debug_assertions) {
panic!("error loading cached npm package info for {name}: {err:#}");
} else {
None
}
}
}
}
fn clear_memory_cache(&self) {
self.mem_cache.lock().clear();
}
}

View file

@ -27,10 +27,9 @@ use deno_semver::package::PackageReq;
use deno_semver::VersionReq;
use crate::args::CliLockfile;
use crate::npm::CliNpmRegistryInfoProvider;
use crate::util::sync::SyncReadAsyncWriteLock;
use super::CliNpmRegistryApi;
pub struct AddPkgReqsResult {
/// Results from adding the individual packages.
///
@ -47,7 +46,7 @@ pub struct AddPkgReqsResult {
///
/// This does not interact with the file system.
pub struct NpmResolution {
api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
snapshot: SyncReadAsyncWriteLock<NpmResolutionSnapshot>,
maybe_lockfile: Option<Arc<CliLockfile>>,
}
@ -63,22 +62,22 @@ impl std::fmt::Debug for NpmResolution {
impl NpmResolution {
pub fn from_serialized(
api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
initial_snapshot: Option<ValidSerializedNpmResolutionSnapshot>,
maybe_lockfile: Option<Arc<CliLockfile>>,
) -> Self {
let snapshot =
NpmResolutionSnapshot::new(initial_snapshot.unwrap_or_default());
Self::new(api, snapshot, maybe_lockfile)
Self::new(registry_info_provider, snapshot, maybe_lockfile)
}
pub fn new(
api: Arc<CliNpmRegistryApi>,
registry_info_provider: Arc<CliNpmRegistryInfoProvider>,
initial_snapshot: NpmResolutionSnapshot,
maybe_lockfile: Option<Arc<CliLockfile>>,
) -> Self {
Self {
api,
registry_info_provider,
snapshot: SyncReadAsyncWriteLock::new(initial_snapshot),
maybe_lockfile,
}
@ -91,7 +90,7 @@ impl NpmResolution {
// only allow one thread in here at a time
let snapshot_lock = self.snapshot.acquire().await;
let result = add_package_reqs_to_snapshot(
&self.api,
&self.registry_info_provider,
package_reqs,
self.maybe_lockfile.clone(),
|| snapshot_lock.read().clone(),
@ -119,7 +118,7 @@ impl NpmResolution {
let reqs_set = package_reqs.iter().collect::<HashSet<_>>();
let snapshot = add_package_reqs_to_snapshot(
&self.api,
&self.registry_info_provider,
package_reqs,
self.maybe_lockfile.clone(),
|| {
@ -259,7 +258,7 @@ impl NpmResolution {
}
async fn add_package_reqs_to_snapshot(
api: &CliNpmRegistryApi,
registry_info_provider: &Arc<CliNpmRegistryInfoProvider>,
package_reqs: &[PackageReq],
maybe_lockfile: Option<Arc<CliLockfile>>,
get_new_snapshot: impl Fn() -> NpmResolutionSnapshot,
@ -282,26 +281,28 @@ async fn add_package_reqs_to_snapshot(
/* this string is used in tests */
"Running npm resolution."
);
let npm_registry_api = registry_info_provider.as_npm_registry_api();
let result = snapshot
.add_pkg_reqs(api, get_add_pkg_reqs_options(package_reqs))
.add_pkg_reqs(&npm_registry_api, get_add_pkg_reqs_options(package_reqs))
.await;
api.clear_memory_cache();
let result = match &result.dep_graph_result {
Err(NpmResolutionError::Resolution(err)) if api.mark_force_reload() => {
Err(NpmResolutionError::Resolution(err))
if npm_registry_api.mark_force_reload() =>
{
log::debug!("{err:#}");
log::debug!("npm resolution failed. Trying again...");
// try again
// try again with forced reloading
let snapshot = get_new_snapshot();
let result = snapshot
.add_pkg_reqs(api, get_add_pkg_reqs_options(package_reqs))
.await;
api.clear_memory_cache();
result
snapshot
.add_pkg_reqs(&npm_registry_api, get_add_pkg_reqs_options(package_reqs))
.await
}
_ => result,
};
registry_info_provider.clear_memory_cache();
if let Ok(snapshot) = &result.dep_graph_result {
if let Some(lockfile) = maybe_lockfile {
populate_lockfile_from_snapshot(&lockfile, snapshot);

View file

@ -241,12 +241,15 @@ pub async fn execute_script(
description: None,
},
kill_signal,
cli_options.argv(),
)
.await;
}
for task_config in &packages_task_configs {
let exit_code = task_runner.run_tasks(task_config, &kill_signal).await?;
let exit_code = task_runner
.run_tasks(task_config, &kill_signal, cli_options.argv())
.await?;
if exit_code > 0 {
return Ok(exit_code);
}
@ -263,6 +266,7 @@ struct RunSingleOptions<'a> {
cwd: &'a Path,
custom_commands: HashMap<String, Rc<dyn ShellCommand>>,
kill_signal: KillSignal,
argv: &'a [String],
}
struct TaskRunner<'a> {
@ -279,9 +283,10 @@ impl<'a> TaskRunner<'a> {
&self,
pkg_tasks_config: &PackageTaskInfo,
kill_signal: &KillSignal,
argv: &[String],
) -> Result<i32, deno_core::anyhow::Error> {
match sort_tasks_topo(pkg_tasks_config) {
Ok(sorted) => self.run_tasks_in_parallel(sorted, kill_signal).await,
Ok(sorted) => self.run_tasks_in_parallel(sorted, kill_signal, argv).await,
Err(err) => match err {
TaskError::NotFound(name) => {
if self.task_flags.is_run {
@ -317,6 +322,7 @@ impl<'a> TaskRunner<'a> {
&self,
tasks: Vec<ResolvedTask<'a>>,
kill_signal: &KillSignal,
args: &[String],
) -> Result<i32, deno_core::anyhow::Error> {
struct PendingTasksContext<'a> {
completed: HashSet<usize>,
@ -338,13 +344,21 @@ impl<'a> TaskRunner<'a> {
&mut self,
runner: &'b TaskRunner<'b>,
kill_signal: &KillSignal,
argv: &'a [String],
) -> Option<
LocalBoxFuture<'b, Result<(i32, &'a ResolvedTask<'a>), AnyError>>,
>
where
'a: 'b,
{
for task in self.tasks.iter() {
let mut tasks_iter = self.tasks.iter().peekable();
while let Some(task) = tasks_iter.next() {
let args = if tasks_iter.peek().is_none() {
argv
} else {
&[]
};
if self.completed.contains(&task.id)
|| self.running.contains(&task.id)
{
@ -366,7 +380,13 @@ impl<'a> TaskRunner<'a> {
match task.task_or_script {
TaskOrScript::Task(_, def) => {
runner
.run_deno_task(task.folder_url, task.name, def, kill_signal)
.run_deno_task(
task.folder_url,
task.name,
def,
kill_signal,
args,
)
.await
}
TaskOrScript::Script(scripts, _) => {
@ -376,6 +396,7 @@ impl<'a> TaskRunner<'a> {
task.name,
scripts,
kill_signal,
args,
)
.await
}
@ -399,7 +420,7 @@ impl<'a> TaskRunner<'a> {
while context.has_remaining_tasks() {
while queue.len() < self.concurrency {
if let Some(task) = context.get_next_task(self, kill_signal) {
if let Some(task) = context.get_next_task(self, kill_signal, args) {
queue.push(task);
} else {
break;
@ -429,6 +450,7 @@ impl<'a> TaskRunner<'a> {
task_name: &str,
definition: &TaskDefinition,
kill_signal: KillSignal,
argv: &'a [String],
) -> Result<i32, deno_core::anyhow::Error> {
let cwd = match &self.task_flags.cwd {
Some(path) => canonicalize_path(&PathBuf::from(path))
@ -447,6 +469,7 @@ impl<'a> TaskRunner<'a> {
cwd: &cwd,
custom_commands,
kill_signal,
argv,
})
.await
}
@ -457,6 +480,7 @@ impl<'a> TaskRunner<'a> {
task_name: &str,
scripts: &IndexMap<String, String>,
kill_signal: KillSignal,
argv: &[String],
) -> Result<i32, deno_core::anyhow::Error> {
// ensure the npm packages are installed if using a managed resolver
if let Some(npm_resolver) = self.npm_resolver.as_managed() {
@ -489,6 +513,7 @@ impl<'a> TaskRunner<'a> {
cwd: &cwd,
custom_commands: custom_commands.clone(),
kill_signal: kill_signal.clone(),
argv,
})
.await?;
if exit_code > 0 {
@ -510,11 +535,12 @@ impl<'a> TaskRunner<'a> {
cwd,
custom_commands,
kill_signal,
argv,
} = opts;
output_task(
opts.task_name,
&task_runner::get_script_with_args(script, self.cli_options.argv()),
&task_runner::get_script_with_args(script, argv),
);
Ok(
@ -525,7 +551,7 @@ impl<'a> TaskRunner<'a> {
env_vars: self.env_vars.clone(),
custom_commands,
init_cwd: self.cli_options.initial_cwd(),
argv: self.cli_options.argv(),
argv,
root_node_modules_dir: self.npm_resolver.root_node_modules_path(),
stdio: None,
kill_signal,

View file

@ -4,12 +4,13 @@
// deno-lint-ignore-file prefer-primordials
import { TextDecoder, TextEncoder } from "ext:deno_web/08_text_encoding.js";
import { asyncIterableToCallback } from "ext:deno_node/_fs/_fs_watch.ts";
import Dirent from "ext:deno_node/_fs/_fs_dirent.ts";
import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts";
import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs";
import { Buffer } from "node:buffer";
import { promisify } from "ext:deno_node/internal/util.mjs";
import { op_fs_read_dir_async, op_fs_read_dir_sync } from "ext:core/ops";
import { join, relative } from "node:path";
function toDirent(val: Deno.DirEntry & { parentPath: string }): Dirent {
return new Dirent(val);
@ -18,6 +19,7 @@ function toDirent(val: Deno.DirEntry & { parentPath: string }): Dirent {
type readDirOptions = {
encoding?: string;
withFileTypes?: boolean;
recursive?: boolean;
};
type readDirCallback = (err: Error | null, files: string[]) => void;
@ -30,12 +32,12 @@ type readDirBoth = (
export function readdir(
path: string | Buffer | URL,
options: { withFileTypes?: false; encoding?: string },
options: readDirOptions,
callback: readDirCallback,
): void;
export function readdir(
path: string | Buffer | URL,
options: { withFileTypes: true; encoding?: string },
options: readDirOptions,
callback: readDirCallbackDirent,
): void;
export function readdir(path: string | URL, callback: readDirCallback): void;
@ -51,8 +53,7 @@ export function readdir(
const options = typeof optionsOrCallback === "object"
? optionsOrCallback
: null;
const result: Array<string | Dirent> = [];
path = getValidatedPath(path);
path = getValidatedPath(path).toString();
if (!callback) throw new Error("No callback function supplied");
@ -66,24 +67,44 @@ export function readdir(
}
}
try {
path = path.toString();
asyncIterableToCallback(Deno.readDir(path), (val, done) => {
if (typeof path !== "string") return;
if (done) {
callback(null, result);
const result: Array<string | Dirent> = [];
const dirs = [path];
let current: string | undefined;
(async () => {
while ((current = dirs.shift()) !== undefined) {
try {
const entries = await op_fs_read_dir_async(current);
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (options?.recursive && entry.isDirectory) {
dirs.push(join(current, entry.name));
}
if (options?.withFileTypes) {
entry.parentPath = current;
result.push(toDirent(entry));
} else {
let name = decode(entry.name, options?.encoding);
if (options?.recursive) {
name = relative(path, join(current, name));
}
result.push(name);
}
}
} catch (err) {
callback(
denoErrorToNodeError(err as Error, {
syscall: "readdir",
path: current,
}),
);
return;
}
if (options?.withFileTypes) {
val.parentPath = path;
result.push(toDirent(val));
} else result.push(decode(val.name));
}, (e) => {
callback(denoErrorToNodeError(e as Error, { syscall: "readdir" }));
});
} catch (e) {
callback(denoErrorToNodeError(e as Error, { syscall: "readdir" }));
}
}
callback(null, result);
})();
}
function decode(str: string, encoding?: string): string {
@ -118,8 +139,7 @@ export function readdirSync(
path: string | Buffer | URL,
options?: readDirOptions,
): Array<string | Dirent> {
const result = [];
path = getValidatedPath(path);
path = getValidatedPath(path).toString();
if (options?.encoding) {
try {
@ -131,16 +151,37 @@ export function readdirSync(
}
}
try {
path = path.toString();
for (const file of Deno.readDirSync(path)) {
if (options?.withFileTypes) {
file.parentPath = path;
result.push(toDirent(file));
} else result.push(decode(file.name));
const result: Array<string | Dirent> = [];
const dirs = [path];
let current: string | undefined;
while ((current = dirs.shift()) !== undefined) {
try {
const entries = op_fs_read_dir_sync(current);
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (options?.recursive && entry.isDirectory) {
dirs.push(join(current, entry.name));
}
if (options?.withFileTypes) {
entry.parentPath = current;
result.push(toDirent(entry));
} else {
let name = decode(entry.name, options?.encoding);
if (options?.recursive) {
name = relative(path, join(current, name));
}
result.push(name);
}
}
} catch (e) {
throw denoErrorToNodeError(e as Error, {
syscall: "readdir",
path: current,
});
}
} catch (e) {
throw denoErrorToNodeError(e as Error, { syscall: "readdir" });
}
return result;
}

View file

@ -271,7 +271,7 @@ function addPaddingToBase64url(base64url) {
if (base64url.length % 4 === 2) return base64url + "==";
if (base64url.length % 4 === 3) return base64url + "=";
if (base64url.length % 4 === 1) {
throw new TypeError("Illegal base64url string!");
throw new TypeError("Illegal base64url string");
}
return base64url;
}
@ -382,7 +382,7 @@ function assert(cond, msg = "Assertion failed.") {
function serializeJSValueToJSONString(value) {
const result = JSONStringify(value);
if (result === undefined) {
throw new TypeError("Value is not JSON serializable.");
throw new TypeError("Value is not JSON serializable");
}
return result;
}
@ -429,7 +429,7 @@ function pathFromURLWin32(url) {
*/
function pathFromURLPosix(url) {
if (url.hostname !== "") {
throw new TypeError(`Host must be empty.`);
throw new TypeError("Host must be empty");
}
return decodeURIComponent(
@ -444,7 +444,7 @@ function pathFromURLPosix(url) {
function pathFromURL(pathOrUrl) {
if (ObjectPrototypeIsPrototypeOf(URLPrototype, pathOrUrl)) {
if (pathOrUrl.protocol != "file:") {
throw new TypeError("Must be a file URL.");
throw new TypeError("Must be a file URL");
}
return core.build.os == "windows"

View file

@ -1031,11 +1031,11 @@ class EventTarget {
}
if (getDispatched(event)) {
throw new DOMException("Invalid event state.", "InvalidStateError");
throw new DOMException("Invalid event state", "InvalidStateError");
}
if (event.eventPhase !== Event.NONE) {
throw new DOMException("Invalid event state.", "InvalidStateError");
throw new DOMException("Invalid event state", "InvalidStateError");
}
return dispatch(self, event);

View file

@ -196,7 +196,7 @@ class AbortSignal extends EventTarget {
constructor(key = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
super();
}

View file

@ -16,7 +16,7 @@ const illegalConstructorKey = Symbol("illegalConstructorKey");
class Window extends EventTarget {
constructor(key = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
super();
}
@ -29,7 +29,7 @@ class Window extends EventTarget {
class WorkerGlobalScope extends EventTarget {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
super();
}
@ -42,7 +42,7 @@ class WorkerGlobalScope extends EventTarget {
class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
super();
}

View file

@ -50,7 +50,7 @@ function btoa(data) {
} catch (e) {
if (ObjectPrototypeIsPrototypeOf(TypeErrorPrototype, e)) {
throw new DOMException(
"The string to be encoded contains characters outside of the Latin1 range.",
"Cannot encode string: string contains characters outside of the Latin1 range",
"InvalidCharacterError",
);
}

View file

@ -523,10 +523,14 @@ function dequeueValue(container) {
function enqueueValueWithSize(container, value, size) {
assert(container[_queue] && typeof container[_queueTotalSize] === "number");
if (isNonNegativeNumber(size) === false) {
throw new RangeError("chunk size isn't a positive number");
throw new RangeError(
"Cannot enqueue value with size: chunk size must be a positive number",
);
}
if (size === Infinity) {
throw new RangeError("chunk size is invalid");
throw new RangeError(
"Cannot enqueue value with size: chunk size is invalid",
);
}
container[_queue].enqueue({ value, size });
container[_queueTotalSize] += size;
@ -1097,7 +1101,7 @@ async function readableStreamCollectIntoUint8Array(stream) {
if (TypedArrayPrototypeGetSymbolToStringTag(chunk) !== "Uint8Array") {
throw new TypeError(
"Can't convert value to Uint8Array while consuming the stream",
"Cannot convert value to Uint8Array while consuming the stream",
);
}
@ -1347,7 +1351,7 @@ function readableByteStreamControllerEnqueue(controller, chunk) {
if (isDetachedBuffer(buffer)) {
throw new TypeError(
"chunk's buffer is detached and so cannot be enqueued",
"Chunk's buffer is detached and so cannot be enqueued",
);
}
const transferredBuffer = ArrayBufferPrototypeTransferToFixedLength(buffer);
@ -2095,14 +2099,14 @@ function readableByteStreamControllerRespond(controller, bytesWritten) {
if (state === "closed") {
if (bytesWritten !== 0) {
throw new TypeError(
"bytesWritten must be 0 when calling respond() on a closed stream",
`"bytesWritten" must be 0 when calling respond() on a closed stream: received ${bytesWritten}`,
);
}
} else {
assert(state === "readable");
if (bytesWritten === 0) {
throw new TypeError(
"bytesWritten must be greater than 0 when calling respond() on a readable stream",
'"bytesWritten" must be greater than 0 when calling respond() on a readable stream',
);
}
if (
@ -2110,7 +2114,7 @@ function readableByteStreamControllerRespond(controller, bytesWritten) {
// deno-lint-ignore prefer-primordials
firstDescriptor.byteLength
) {
throw new RangeError("bytesWritten out of range");
throw new RangeError('"bytesWritten" out of range');
}
}
firstDescriptor.buffer = ArrayBufferPrototypeTransferToFixedLength(
@ -2305,7 +2309,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
if (state === "closed") {
if (byteLength !== 0) {
throw new TypeError(
"The view's length must be 0 when calling respondWithNewView() on a closed stream",
`The view's length must be 0 when calling respondWithNewView() on a closed stream: received ${byteLength}`,
);
}
} else {
@ -3577,7 +3581,7 @@ function setUpReadableByteStreamControllerFromUnderlyingSource(
}
const autoAllocateChunkSize = underlyingSourceDict["autoAllocateChunkSize"];
if (autoAllocateChunkSize === 0) {
throw new TypeError("autoAllocateChunkSize must be greater than 0");
throw new TypeError('"autoAllocateChunkSize" must be greater than 0');
}
setUpReadableByteStreamController(
stream,
@ -3706,7 +3710,7 @@ function setUpReadableStreamDefaultControllerFromUnderlyingSource(
*/
function setUpReadableStreamBYOBReader(reader, stream) {
if (isReadableStreamLocked(stream)) {
throw new TypeError("ReadableStream is locked.");
throw new TypeError("ReadableStream is locked");
}
if (
!(ObjectPrototypeIsPrototypeOf(
@ -3727,7 +3731,7 @@ function setUpReadableStreamBYOBReader(reader, stream) {
*/
function setUpReadableStreamDefaultReader(reader, stream) {
if (isReadableStreamLocked(stream)) {
throw new TypeError("ReadableStream is locked.");
throw new TypeError("ReadableStream is locked");
}
readableStreamReaderGenericInitialize(reader, stream);
reader[_readRequests] = new Queue();
@ -3961,7 +3965,7 @@ function setUpWritableStreamDefaultControllerFromUnderlyingSink(
*/
function setUpWritableStreamDefaultWriter(writer, stream) {
if (isWritableStreamLocked(stream) === true) {
throw new TypeError("The stream is already locked.");
throw new TypeError("The stream is already locked");
}
writer[_stream] = stream;
stream[_writer] = writer;
@ -4019,7 +4023,7 @@ function transformStreamDefaultControllerEnqueue(controller, chunk) {
/** @type {ReadableStreamDefaultController<O>} */ readableController,
) === false
) {
throw new TypeError("Readable stream is unavailable.");
throw new TypeError("Readable stream is unavailable");
}
try {
readableStreamDefaultControllerEnqueue(
@ -5143,7 +5147,7 @@ class ReadableStream {
if (underlyingSourceDict.type === "bytes") {
if (strategy.size !== undefined) {
throw new RangeError(
`${prefix}: When underlying source is "bytes", strategy.size must be undefined.`,
`${prefix}: When underlying source is "bytes", strategy.size must be 'undefined'`,
);
}
const highWaterMark = extractHighWaterMark(strategy, 0);
@ -5273,10 +5277,10 @@ class ReadableStream {
const { readable, writable } = transform;
const { preventClose, preventAbort, preventCancel, signal } = options;
if (isReadableStreamLocked(this)) {
throw new TypeError("ReadableStream is already locked.");
throw new TypeError("ReadableStream is already locked");
}
if (isWritableStreamLocked(writable)) {
throw new TypeError("Target WritableStream is already locked.");
throw new TypeError("Target WritableStream is already locked");
}
const promise = readableStreamPipeTo(
this,
@ -5814,7 +5818,7 @@ class ReadableByteStreamController {
}
if (this[_stream][_state] !== "readable") {
throw new TypeError(
"ReadableByteStreamController's stream is not in a readable state.",
"ReadableByteStreamController's stream is not in a readable state",
);
}
readableByteStreamControllerClose(this);
@ -5846,7 +5850,7 @@ class ReadableByteStreamController {
if (byteLength === 0) {
throw webidl.makeException(
TypeError,
"length must be non-zero",
"Length must be non-zero",
prefix,
arg1,
);
@ -5854,19 +5858,19 @@ class ReadableByteStreamController {
if (getArrayBufferByteLength(buffer) === 0) {
throw webidl.makeException(
TypeError,
"buffer length must be non-zero",
"Buffer length must be non-zero",
prefix,
arg1,
);
}
if (this[_closeRequested] === true) {
throw new TypeError(
"Cannot enqueue chunk after a close has been requested.",
"Cannot enqueue chunk after a close has been requested",
);
}
if (this[_stream][_state] !== "readable") {
throw new TypeError(
"Cannot enqueue chunk when underlying stream is not readable.",
"Cannot enqueue chunk when underlying stream is not readable",
);
}
return readableByteStreamControllerEnqueue(this, chunk);
@ -6006,7 +6010,7 @@ class ReadableStreamDefaultController {
close() {
webidl.assertBranded(this, ReadableStreamDefaultControllerPrototype);
if (readableStreamDefaultControllerCanCloseOrEnqueue(this) === false) {
throw new TypeError("The stream controller cannot close or enqueue.");
throw new TypeError("The stream controller cannot close or enqueue");
}
readableStreamDefaultControllerClose(this);
}
@ -6021,7 +6025,7 @@ class ReadableStreamDefaultController {
chunk = webidl.converters.any(chunk);
}
if (readableStreamDefaultControllerCanCloseOrEnqueue(this) === false) {
throw new TypeError("The stream controller cannot close or enqueue.");
throw new TypeError("The stream controller cannot close or enqueue");
}
readableStreamDefaultControllerEnqueue(this, chunk);
}
@ -6146,12 +6150,12 @@ class TransformStream {
);
if (transformerDict.readableType !== undefined) {
throw new RangeError(
`${prefix}: readableType transformers not supported.`,
`${prefix}: readableType transformers not supported`,
);
}
if (transformerDict.writableType !== undefined) {
throw new RangeError(
`${prefix}: writableType transformers not supported.`,
`${prefix}: writableType transformers not supported`,
);
}
const readableHighWaterMark = extractHighWaterMark(readableStrategy, 0);
@ -6356,7 +6360,7 @@ class WritableStream {
);
if (underlyingSinkDict.type != null) {
throw new RangeError(
`${prefix}: WritableStream does not support 'type' in the underlying sink.`,
`${prefix}: WritableStream does not support 'type' in the underlying sink`,
);
}
initializeWritableStream(this);
@ -6483,7 +6487,7 @@ class WritableStreamDefaultWriter {
webidl.assertBranded(this, WritableStreamDefaultWriterPrototype);
if (this[_stream] === undefined) {
throw new TypeError(
"A writable stream is not associated with the writer.",
"A writable stream is not associated with the writer",
);
}
return writableStreamDefaultWriterGetDesiredSize(this);

View file

@ -65,7 +65,7 @@ class FileReader extends EventTarget {
// 1. If fr's state is "loading", throw an InvalidStateError DOMException.
if (this[state] === "loading") {
throw new DOMException(
"Invalid FileReader state.",
"Invalid FileReader state",
"InvalidStateError",
);
}

View file

@ -28,7 +28,7 @@ const locationConstructorKey = Symbol("locationConstructorKey");
class Location {
constructor(href = null, key = null) {
if (key != locationConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
const url = new URL(href);
url.username = "";
@ -41,7 +41,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.hash".`,
`Cannot set "location.hash"`,
"NotSupportedError",
);
},
@ -54,7 +54,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.host".`,
`Cannot set "location.host"`,
"NotSupportedError",
);
},
@ -67,7 +67,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.hostname".`,
`Cannot set "location.hostname"`,
"NotSupportedError",
);
},
@ -80,7 +80,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.href".`,
`Cannot set "location.href"`,
"NotSupportedError",
);
},
@ -100,7 +100,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.pathname".`,
`Cannot set "location.pathname"`,
"NotSupportedError",
);
},
@ -113,7 +113,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.port".`,
`Cannot set "location.port"`,
"NotSupportedError",
);
},
@ -126,7 +126,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.protocol".`,
`Cannot set "location.protocol"`,
"NotSupportedError",
);
},
@ -139,7 +139,7 @@ class Location {
},
set() {
throw new DOMException(
`Cannot set "location.search".`,
`Cannot set "location.search"`,
"NotSupportedError",
);
},
@ -161,7 +161,7 @@ class Location {
__proto__: null,
value: function assign() {
throw new DOMException(
`Cannot call "location.assign()".`,
`Cannot call "location.assign()"`,
"NotSupportedError",
);
},
@ -171,7 +171,7 @@ class Location {
__proto__: null,
value: function reload() {
throw new DOMException(
`Cannot call "location.reload()".`,
`Cannot call "location.reload()"`,
"NotSupportedError",
);
},
@ -181,7 +181,7 @@ class Location {
__proto__: null,
value: function replace() {
throw new DOMException(
`Cannot call "location.replace()".`,
`Cannot call "location.replace()"`,
"NotSupportedError",
);
},
@ -229,7 +229,7 @@ const workerLocationUrls = new SafeWeakMap();
class WorkerLocation {
constructor(href = null, key = null) {
if (key != locationConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
const url = new URL(href);
url.username = "";
@ -244,7 +244,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.hash;
},
@ -256,7 +256,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.host;
},
@ -268,7 +268,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.hostname;
},
@ -280,7 +280,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.href;
},
@ -292,7 +292,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.origin;
},
@ -304,7 +304,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.pathname;
},
@ -316,7 +316,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.port;
},
@ -328,7 +328,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.protocol;
},
@ -340,7 +340,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
get() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.search;
},
@ -352,7 +352,7 @@ ObjectDefineProperties(WorkerLocation.prototype, {
value: function toString() {
const url = WeakMapPrototypeGet(workerLocationUrls, this);
if (url == null) {
throw new TypeError("Illegal invocation.");
throw new TypeError("Illegal invocation");
}
return url.href;
},
@ -414,7 +414,7 @@ const locationDescriptor = {
return location;
},
set() {
throw new DOMException(`Cannot set "location".`, "NotSupportedError");
throw new DOMException(`Cannot set "location"`, "NotSupportedError");
},
enumerable: true,
};
@ -422,7 +422,7 @@ const workerLocationDescriptor = {
get() {
if (workerLocation == null) {
throw new Error(
`Assertion: "globalThis.location" must be defined in a worker.`,
`Assertion: "globalThis.location" must be defined in a worker`,
);
}
return workerLocation;

View file

@ -123,14 +123,14 @@ function convertMarkToTimestamp(mark) {
const entry = findMostRecent(mark, "mark");
if (!entry) {
throw new DOMException(
`Cannot find mark: "${mark}".`,
`Cannot find mark: "${mark}"`,
"SyntaxError",
);
}
return entry.startTime;
}
if (mark < 0) {
throw new TypeError("Mark cannot be negative.");
throw new TypeError(`Mark cannot be negative: received ${mark}`);
}
return mark;
}
@ -261,7 +261,9 @@ class PerformanceMark extends PerformanceEntry {
super(name, "mark", startTime, 0, illegalConstructorKey);
this[webidl.brand] = webidl.brand;
if (startTime < 0) {
throw new TypeError("startTime cannot be negative");
throw new TypeError(
`Cannot construct PerformanceMark: startTime cannot be negative, received ${startTime}`,
);
}
this[_detail] = structuredClone(detail);
}
@ -504,14 +506,14 @@ class Performance extends EventTarget {
ObjectKeys(startOrMeasureOptions).length > 0
) {
if (endMark) {
throw new TypeError("Options cannot be passed with endMark.");
throw new TypeError('Options cannot be passed with "endMark"');
}
if (
!ReflectHas(startOrMeasureOptions, "start") &&
!ReflectHas(startOrMeasureOptions, "end")
) {
throw new TypeError(
"A start or end mark must be supplied in options.",
'A "start" or "end" mark must be supplied in options',
);
}
if (
@ -520,7 +522,7 @@ class Performance extends EventTarget {
ReflectHas(startOrMeasureOptions, "end")
) {
throw new TypeError(
"Cannot specify start, end, and duration together in options.",
'Cannot specify "start", "end", and "duration" together in options',
);
}
}

View file

@ -84,35 +84,35 @@ class ImageData {
if (dataLength === 0) {
throw new DOMException(
"Failed to construct 'ImageData': The input data has zero elements.",
"Failed to construct 'ImageData': the input data has zero elements",
"InvalidStateError",
);
}
if (dataLength % 4 !== 0) {
throw new DOMException(
"Failed to construct 'ImageData': The input data length is not a multiple of 4.",
`Failed to construct 'ImageData': the input data length is not a multiple of 4, received ${dataLength}`,
"InvalidStateError",
);
}
if (sourceWidth < 1) {
throw new DOMException(
"Failed to construct 'ImageData': The source width is zero or not a number.",
"Failed to construct 'ImageData': the source width is zero or not a number",
"IndexSizeError",
);
}
if (webidl.type(sourceHeight) !== "Undefined" && sourceHeight < 1) {
throw new DOMException(
"Failed to construct 'ImageData': The source height is zero or not a number.",
"Failed to construct 'ImageData': the source height is zero or not a number",
"IndexSizeError",
);
}
if (dataLength / 4 % sourceWidth !== 0) {
throw new DOMException(
"Failed to construct 'ImageData': The input data length is not a multiple of (4 * width).",
"Failed to construct 'ImageData': the input data length is not a multiple of (4 * width)",
"IndexSizeError",
);
}
@ -122,7 +122,7 @@ class ImageData {
(sourceWidth * sourceHeight * 4 !== dataLength)
) {
throw new DOMException(
"Failed to construct 'ImageData': The input data length is not equal to (4 * width * height).",
"Failed to construct 'ImageData': the input data length is not equal to (4 * width * height)",
"IndexSizeError",
);
}
@ -159,14 +159,14 @@ class ImageData {
if (sourceWidth < 1) {
throw new DOMException(
"Failed to construct 'ImageData': The source width is zero or not a number.",
"Failed to construct 'ImageData': the source width is zero or not a number",
"IndexSizeError",
);
}
if (sourceHeight < 1) {
throw new DOMException(
"Failed to construct 'ImageData': The source height is zero or not a number.",
"Failed to construct 'ImageData': the source height is zero or not a number",
"IndexSizeError",
);
}

View file

@ -42,7 +42,7 @@ pub struct DownloadError {
impl std::error::Error for DownloadError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self.error.as_ref())
self.error.source()
}
}

View file

@ -1,14 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use anyhow::anyhow;
use anyhow::bail;
use anyhow::Context;
use anyhow::Error as AnyError;
use async_trait::async_trait;
use deno_npm::npm_rc::ResolvedNpmRc;
use deno_npm::registry::NpmPackageInfo;
use deno_npm::registry::NpmRegistryApi;
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
use deno_unsync::sync::AtomicFlag;
use deno_unsync::sync::MultiRuntimeAsyncValueCreator;
use futures::future::LocalBoxFuture;
use futures::FutureExt;
@ -43,8 +48,49 @@ enum MemoryCacheItem {
MemoryCached(Result<Option<Arc<NpmPackageInfo>>, Arc<AnyError>>),
}
// todo(#27198): refactor to store this only in the http cache and also
// consolidate with CliNpmRegistryApi.
#[derive(Debug, Default)]
struct MemoryCache {
clear_id: usize,
items: HashMap<String, MemoryCacheItem>,
}
impl MemoryCache {
#[inline(always)]
pub fn clear(&mut self) {
self.clear_id += 1;
self.items.clear();
}
#[inline(always)]
pub fn get(&self, key: &str) -> Option<&MemoryCacheItem> {
self.items.get(key)
}
#[inline(always)]
pub fn insert(&mut self, key: String, value: MemoryCacheItem) {
self.items.insert(key, value);
}
#[inline(always)]
pub fn try_insert(
&mut self,
clear_id: usize,
key: &str,
value: MemoryCacheItem,
) -> bool {
if clear_id != self.clear_id {
return false;
}
// if the clear_id is the same then the item should exist
debug_assert!(self.items.contains_key(key));
if let Some(item) = self.items.get_mut(key) {
*item = value;
}
true
}
}
// todo(#27198): refactor to store this only in the http cache
/// Downloads packuments from the npm registry.
///
@ -55,7 +101,9 @@ pub struct RegistryInfoProvider<TEnv: NpmCacheEnv> {
cache: Arc<NpmCache<TEnv>>,
env: Arc<TEnv>,
npmrc: Arc<ResolvedNpmRc>,
memory_cache: Mutex<HashMap<String, MemoryCacheItem>>,
force_reload_flag: AtomicFlag,
memory_cache: Mutex<MemoryCache>,
previously_loaded_packages: Mutex<HashSet<String>>,
}
impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
@ -68,17 +116,60 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
cache,
env,
npmrc,
force_reload_flag: AtomicFlag::lowered(),
memory_cache: Default::default(),
previously_loaded_packages: Default::default(),
}
}
pub async fn load_package_info(
/// Clears the internal memory cache.
pub fn clear_memory_cache(&self) {
self.memory_cache.lock().clear();
}
fn mark_force_reload(&self) -> bool {
// never force reload the registry information if reloading
// is disabled or if we're already reloading
if matches!(
self.cache.cache_setting(),
NpmCacheSetting::Only | NpmCacheSetting::ReloadAll
) {
return false;
}
if self.force_reload_flag.raise() {
self.clear_memory_cache();
true
} else {
false
}
}
pub fn as_npm_registry_api(self: &Arc<Self>) -> NpmRegistryApiAdapter<TEnv> {
NpmRegistryApiAdapter(self.clone())
}
pub async fn package_info(
self: &Arc<Self>,
name: &str,
) -> Result<Arc<NpmPackageInfo>, NpmRegistryPackageInfoLoadError> {
match self.maybe_package_info(name).await {
Ok(Some(info)) => Ok(info),
Ok(None) => Err(NpmRegistryPackageInfoLoadError::PackageNotExists {
package_name: name.to_string(),
}),
Err(err) => {
Err(NpmRegistryPackageInfoLoadError::LoadError(Arc::new(err)))
}
}
}
pub async fn maybe_package_info(
self: &Arc<Self>,
name: &str,
) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> {
self.load_package_info_inner(name).await.with_context(|| {
format!(
"Error getting response at {} for package \"{}\"",
"Failed loading {} for package \"{}\"",
get_package_url(&self.npmrc, name),
name
)
@ -89,18 +180,9 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
self: &Arc<Self>,
name: &str,
) -> Result<Option<Arc<NpmPackageInfo>>, AnyError> {
if *self.cache.cache_setting() == NpmCacheSetting::Only {
return Err(deno_core::error::custom_error(
"NotCached",
format!(
"An npm specifier not found in cache: \"{name}\", --cached-only is specified."
)
));
}
let cache_item = {
let (cache_item, clear_id) = {
let mut mem_cache = self.memory_cache.lock();
if let Some(cache_item) = mem_cache.get(name) {
let cache_item = if let Some(cache_item) = mem_cache.get(name) {
cache_item.clone()
} else {
let value_creator = MultiRuntimeAsyncValueCreator::new({
@ -111,7 +193,8 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
let cache_item = MemoryCacheItem::Pending(Arc::new(value_creator));
mem_cache.insert(name.to_string(), cache_item.clone());
cache_item
}
};
(cache_item, mem_cache.clear_id)
};
match cache_item {
@ -130,25 +213,37 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
Ok(FutureResult::SavedFsCache(info)) => {
// return back the future and mark this package as having
// been saved in the cache for next time it's requested
*self.memory_cache.lock().get_mut(name).unwrap() =
MemoryCacheItem::FsCached;
self.memory_cache.lock().try_insert(
clear_id,
name,
MemoryCacheItem::FsCached,
);
Ok(Some(info))
}
Ok(FutureResult::ErroredFsCache(info)) => {
// since saving to the fs cache failed, keep the package information in memory
*self.memory_cache.lock().get_mut(name).unwrap() =
MemoryCacheItem::MemoryCached(Ok(Some(info.clone())));
self.memory_cache.lock().try_insert(
clear_id,
name,
MemoryCacheItem::MemoryCached(Ok(Some(info.clone()))),
);
Ok(Some(info))
}
Ok(FutureResult::PackageNotExists) => {
*self.memory_cache.lock().get_mut(name).unwrap() =
MemoryCacheItem::MemoryCached(Ok(None));
self.memory_cache.lock().try_insert(
clear_id,
name,
MemoryCacheItem::MemoryCached(Ok(None)),
);
Ok(None)
}
Err(err) => {
let return_err = anyhow!("{}", err);
*self.memory_cache.lock().get_mut(name).unwrap() =
MemoryCacheItem::MemoryCached(Err(err));
let return_err = anyhow!("{:#}", err);
self.memory_cache.lock().try_insert(
clear_id,
name,
MemoryCacheItem::MemoryCached(Err(err)),
);
Err(return_err)
}
}
@ -196,6 +291,29 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
};
let name = name.to_string();
async move {
if (downloader.cache.cache_setting().should_use_for_npm_package(&name) && !downloader.force_reload_flag.is_raised())
// if this has been previously reloaded, then try loading from the
// file system cache
|| downloader.previously_loaded_packages.lock().contains(&name)
{
// attempt to load from the file cache
if let Some(info) = downloader.cache.load_package_info(&name)? {
let result = Arc::new(info);
return Ok(FutureResult::SavedFsCache(result));
}
}
if *downloader.cache.cache_setting() == NpmCacheSetting::Only {
return Err(deno_core::error::custom_error(
"NotCached",
format!(
"npm package not found in cache: \"{name}\", --cached-only is specified."
)
));
}
downloader.previously_loaded_packages.lock().insert(name.to_string());
let maybe_bytes = downloader
.env
.download_with_retries_on_any_tokio_runtime(
@ -234,6 +352,24 @@ impl<TEnv: NpmCacheEnv> RegistryInfoProvider<TEnv> {
}
}
pub struct NpmRegistryApiAdapter<TEnv: NpmCacheEnv>(
Arc<RegistryInfoProvider<TEnv>>,
);
#[async_trait(?Send)]
impl<TEnv: NpmCacheEnv> NpmRegistryApi for NpmRegistryApiAdapter<TEnv> {
async fn package_info(
&self,
name: &str,
) -> Result<Arc<NpmPackageInfo>, NpmRegistryPackageInfoLoadError> {
self.0.package_info(name).await
}
fn mark_force_reload(&self) -> bool {
self.0.mark_force_reload()
}
}
// todo(#27198): make this private and only use RegistryInfoProvider in the rest of
// the code
pub fn get_package_url(npmrc: &ResolvedNpmRc, name: &str) -> Url {

View file

@ -65,13 +65,13 @@ impl<TEnv: NpmCacheEnv> TarballCache<TEnv> {
pub async fn ensure_package(
self: &Arc<Self>,
package: &PackageNv,
package_nv: &PackageNv,
dist: &NpmPackageVersionDistInfo,
) -> Result<(), AnyError> {
self
.ensure_package_inner(package, dist)
.ensure_package_inner(package_nv, dist)
.await
.with_context(|| format!("Failed caching npm package '{}'.", package))
.with_context(|| format!("Failed caching npm package '{}'.", package_nv))
}
async fn ensure_package_inner(
@ -100,7 +100,7 @@ impl<TEnv: NpmCacheEnv> TarballCache<TEnv> {
match cache_item {
MemoryCacheItem::Cached => Ok(()),
MemoryCacheItem::Errored(err) => Err(anyhow!("{}", err)),
MemoryCacheItem::Errored(err) => Err(anyhow!("{:#}", err)),
MemoryCacheItem::Pending(creator) => {
let result = creator.get().await;
match result {
@ -110,7 +110,7 @@ impl<TEnv: NpmCacheEnv> TarballCache<TEnv> {
Ok(())
}
Err(err) => {
let result_err = anyhow!("{}", err);
let result_err = anyhow!("{:#}", err);
*self.memory_cache.lock().get_mut(package_nv).unwrap() =
MemoryCacheItem::Errored(err);
Err(result_err)
@ -138,7 +138,7 @@ impl<TEnv: NpmCacheEnv> TarballCache<TEnv> {
return Err(deno_core::error::custom_error(
"NotCached",
format!(
"An npm specifier not found in cache: \"{}\", --cached-only is specified.",
"npm package not found in cache: \"{}\", --cached-only is specified.",
&package_nv.name
)
)

View file

@ -6009,7 +6009,7 @@ fn lsp_code_actions_deno_cache_npm() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"chalk\" is not installed or doesn't exist.",
"message": "npm package \"chalk\" is not installed or doesn't exist.",
"data": { "specifier": "npm:chalk" }
}],
"version": 1
@ -6036,7 +6036,7 @@ fn lsp_code_actions_deno_cache_npm() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"chalk\" is not installed or doesn't exist.",
"message": "npm package \"chalk\" is not installed or doesn't exist.",
"data": { "specifier": "npm:chalk" }
}],
"only": ["quickfix"]
@ -6056,7 +6056,7 @@ fn lsp_code_actions_deno_cache_npm() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"chalk\" is not installed or doesn't exist.",
"message": "npm package \"chalk\" is not installed or doesn't exist.",
"data": { "specifier": "npm:chalk" }
}],
"command": {
@ -6111,7 +6111,7 @@ fn lsp_code_actions_deno_cache_all() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"chalk\" is not installed or doesn't exist.",
"message": "npm package \"chalk\" is not installed or doesn't exist.",
"data": { "specifier": "npm:chalk" },
},
],
@ -6199,7 +6199,7 @@ fn lsp_code_actions_deno_cache_all() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"chalk\" is not installed or doesn't exist.",
"message": "npm package \"chalk\" is not installed or doesn't exist.",
"data": { "specifier": "npm:chalk" },
},
],
@ -9860,7 +9860,7 @@ fn lsp_completions_node_builtin() {
"severity": 1,
"code": "not-installed-npm",
"source": "deno",
"message": "NPM package \"@types/node\" is not installed or doesn't exist."
"message": "npm package \"@types/node\" is not installed or doesn't exist."
}
])
);

View file

@ -102,7 +102,7 @@ fn cached_only_after_first_run() {
let stdout = String::from_utf8_lossy(&output.stdout);
assert_contains!(
stderr,
"An npm specifier not found in cache: \"ansi-styles\", --cached-only is specified."
"npm package not found in cache: \"ansi-styles\", --cached-only is specified."
);
assert!(stdout.is_empty());
assert!(!output.status.success());

View file

@ -122,6 +122,16 @@
"sequential": ["test-child-process-exit.js"]
},
"tests": {
"abort": [
"test-addon-uv-handle-leak.js"
],
"benchmark": [
"test-benchmark-async-hooks.js",
"test-benchmark-http.js",
"test-benchmark-http2.js",
"test-benchmark-tls.js",
"test-benchmark-worker.js"
],
"common": [
"child_process.js",
"countdown.js",
@ -133,6 +143,13 @@
"internet.js",
"tmpdir.js"
],
"es-module": [
"test-cjs-prototype-pollution.js",
"test-esm-dynamic-import-mutating-fs.js",
"test-esm-loader-cache-clearing.js",
"test-esm-windows.js",
"test-vm-compile-function-lineoffset.js"
],
"fixtures": [
"a.js",
"child_process_should_emit_error.js",
@ -161,12 +178,29 @@
// "test-dns.js",
"test-http-https-default-ports.js"
],
"message": [
"eval_messages.js",
"max_tick_depth.js",
"stdin_messages.js",
"util_inspect_error.js"
],
"parallel": [
"test-arm-math-illegal-instruction.js",
"test-assert-async.js",
"test-assert-fail.js",
"test-assert-strict-exists.js",
"test-assert.js",
"test-async-hooks-run-in-async-scope-caught-exception.js",
"test-async-hooks-run-in-async-scope-this-arg.js",
"test-async-local-storage-bind.js",
"test-async-local-storage-contexts.js",
"test-async-local-storage-deep-stack.js",
"test-async-local-storage-http-multiclients.js",
"test-async-local-storage-snapshot.js",
"test-atomics-wake.js",
"test-bad-unicode.js",
"test-beforeexit-event-exit.js",
"test-blob-buffer-too-large.js",
"test-blocklist.js",
"test-btoa-atob.js",
"test-buffer-alloc.js",
@ -202,6 +236,7 @@
"test-buffer-readint.js",
"test-buffer-readuint.js",
"test-buffer-safe-unsafe.js",
"test-buffer-sharedarraybuffer.js",
"test-buffer-slice.js",
"test-buffer-slow.js",
"test-buffer-swap.js",
@ -209,6 +244,7 @@
"test-buffer-tostring-range.js",
"test-buffer-tostring-rangeerror.js",
"test-buffer-tostring.js",
"test-buffer-write.js",
"test-buffer-writedouble.js",
"test-buffer-writefloat.js",
"test-buffer-writeint.js",
@ -237,8 +273,10 @@
"test-child-process-execfilesync-maxbuf.js",
"test-child-process-execsync-maxbuf.js",
"test-child-process-flush-stdio.js",
"test-child-process-fork3.js",
"test-child-process-ipc-next-tick.js",
"test-child-process-kill.js",
"test-child-process-send-type-error.js",
"test-child-process-set-blocking.js",
"test-child-process-spawn-args.js",
"test-child-process-spawn-event.js",
@ -246,49 +284,140 @@
"test-child-process-spawnsync-maxbuf.js",
"test-child-process-spawnsync-validation-errors.js",
"test-child-process-spawnsync.js",
// TODO(crowlKats): socket is not yet polyfilled
// "test-client-request-destroy.js",
"test-child-process-stdin-ipc.js",
"test-child-process-stdio-overlapped.js",
"test-client-request-destroy.js",
"test-cluster-uncaught-exception.js",
"test-console-assign-undefined.js",
"test-console-async-write-error.js",
"test-console-formatTime.js",
"test-console-group.js",
"test-console-log-stdio-broken-dest.js",
"test-console-log-throw-primitive.js",
"test-console-no-swallow-stack-overflow.js",
"test-console-not-call-toString.js",
"test-console-self-assign.js",
"test-console-sync-write-error.js",
"test-console-table.js",
"test-console-tty-colors.js",
"test-crypto-dh-errors.js",
"test-crypto-dh-odd-key.js",
"test-crypto-dh-shared.js",
"test-crypto-dh.js",
"test-crypto-domain.js",
"test-crypto-from-binary.js",
"test-crypto-hash.js",
"test-crypto-hkdf.js",
"test-crypto-hmac.js",
"test-crypto-keygen-dh-classic.js",
"test-crypto-keygen-duplicate-deprecated-option.js",
"test-crypto-keygen-empty-passphrase-no-error.js",
"test-crypto-keygen-key-objects.js",
"test-crypto-keygen-missing-oid.js",
"test-crypto-keygen-non-standard-public-exponent.js",
"test-crypto-keygen-rfc8017-9-1.js",
"test-crypto-keygen-rfc8017-a-2-3.js",
"test-crypto-lazy-transform-writable.js",
"test-crypto-no-algorithm.js",
"test-crypto-op-during-process-exit.js",
"test-crypto-padding-aes256.js",
"test-crypto-pbkdf2.js",
"test-crypto-prime.js",
"test-crypto-psychic-signatures.js",
"test-crypto-publicDecrypt-fails-first-time.js",
"test-crypto-randomfillsync-regression.js",
"test-crypto-scrypt.js",
"test-crypto-secret-keygen.js",
"test-crypto-stream.js",
"test-crypto-subtle-zero-length.js",
"test-crypto-update-encoding.js",
"test-crypto-x509.js",
"test-dgram-address.js",
"test-dgram-bind-default-address.js",
"test-dgram-bind-error-repeat.js",
"test-dgram-bind.js",
"test-dgram-bytes-length.js",
"test-dgram-close-during-bind.js",
"test-dgram-close-in-listening.js",
"test-dgram-close-is-not-callback.js",
"test-dgram-close-signal.js",
"test-dgram-close.js",
"test-dgram-connect-send-callback-buffer-length.js",
"test-dgram-connect-send-callback-buffer.js",
"test-dgram-connect-send-callback-multi-buffer.js",
"test-dgram-connect-send-default-host.js",
"test-dgram-connect-send-empty-array.js",
"test-dgram-connect-send-empty-buffer.js",
"test-dgram-connect-send-empty-packet.js",
"test-dgram-connect-send-multi-buffer-copy.js",
"test-dgram-connect-send-multi-string-array.js",
"test-dgram-connect.js",
"test-dgram-createSocket-type.js",
"test-dgram-error-message-address.js",
"test-dgram-implicit-bind.js",
"test-dgram-listen-after-bind.js",
"test-dgram-msgsize.js",
"test-dgram-oob-buffer.js",
"test-dgram-recv-error.js",
"test-dgram-ref.js",
"test-dgram-send-bad-arguments.js",
"test-dgram-send-callback-buffer-empty-address.js",
"test-dgram-send-callback-buffer-length-empty-address.js",
"test-dgram-send-callback-buffer-length.js",
"test-dgram-send-callback-buffer.js",
"test-dgram-send-callback-multi-buffer-empty-address.js",
"test-dgram-send-callback-multi-buffer.js",
"test-dgram-send-callback-recursive.js",
"test-dgram-send-default-host.js",
"test-dgram-send-empty-array.js",
"test-dgram-send-empty-buffer.js",
"test-dgram-send-empty-packet.js",
"test-dgram-send-error.js",
"test-dgram-send-invalid-msg-type.js",
"test-dgram-send-multi-buffer-copy.js",
"test-dgram-send-multi-string-array.js",
"test-dgram-udp4.js",
"test-dgram-udp6-send-default-host.js",
"test-dgram-unref.js",
"test-diagnostics-channel-bind-store.js",
"test-diagnostics-channel-has-subscribers.js",
"test-diagnostics-channel-net.js",
"test-diagnostics-channel-object-channel-pub-sub.js",
"test-diagnostics-channel-pub-sub.js",
"test-diagnostics-channel-safe-subscriber-errors.js",
"test-diagnostics-channel-symbol-named.js",
"test-diagnostics-channel-sync-unsubscribe.js",
"test-diagnostics-channel-tracing-channel-args-types.js",
"test-diagnostics-channel-tracing-channel-async-error.js",
"test-diagnostics-channel-tracing-channel-async.js",
"test-diagnostics-channel-tracing-channel-callback-run-stores.js",
"test-diagnostics-channel-tracing-channel-promise-run-stores.js",
"test-diagnostics-channel-tracing-channel-run-stores.js",
"test-diagnostics-channel-tracing-channel-sync-error.js",
"test-diagnostics-channel-tracing-channel-sync.js",
"test-diagnostics-channel-udp.js",
"test-dns-lookup.js",
"test-dns-memory-error.js",
"test-dns-multi-channel.js",
"test-dns-promises-exists.js",
"test-dns-resolvens-typeerror.js",
"test-dns-setservers-type-check.js",
"test-domain-crypto.js",
"test-domain-ee-error-listener.js",
"test-domain-nested-throw.js",
"test-domain-nested.js",
"test-domain-stack.js",
"test-domain-top-level-error-handler-clears-stack.js",
"test-dsa-fips-invalid-key.js",
"test-env-newprotomethod-remove-unnecessary-prototypes.js",
"test-error-aggregateTwoErrors.js",
"test-error-prepare-stack-trace.js",
"test-errors-aborterror.js",
"test-eval-strict-referenceerror.js",
"test-eval.js",
"test-event-capture-rejections.js",
"test-event-emitter-add-listeners.js",
"test-event-emitter-check-listener-leaks.js",
"test-event-emitter-emit-context.js",
"test-event-emitter-error-monitor.js",
"test-event-emitter-errors.js",
@ -297,6 +426,9 @@
"test-event-emitter-listener-count.js",
"test-event-emitter-listeners-side-effects.js",
"test-event-emitter-listeners.js",
"test-event-emitter-max-listeners-warning-for-null.js",
"test-event-emitter-max-listeners-warning-for-symbol.js",
"test-event-emitter-max-listeners-warning.js",
"test-event-emitter-max-listeners.js",
"test-event-emitter-method-names.js",
"test-event-emitter-modify-in-emit.js",
@ -315,6 +447,7 @@
"test-events-once.js",
"test-events-uncaught-exception-stack.js",
"test-eventtarget-brandcheck.js",
"test-eventtarget-once-twice.js",
"test-exception-handler.js",
"test-exception-handler2.js",
"test-file-read-noexist.js",
@ -325,28 +458,42 @@
"test-fs-access.js",
"test-fs-append-file-sync.js",
"test-fs-append-file.js",
"test-fs-buffertype-writesync.js",
"test-fs-chmod-mask.js",
"test-fs-chmod.js",
"test-fs-chown-type-check.js",
"test-fs-close.js",
"test-fs-constants.js",
"test-fs-copyfile.js",
"test-fs-empty-readStream.js",
"test-fs-fmap.js",
"test-fs-lchown.js",
"test-fs-long-path.js",
"test-fs-mkdir.js",
"test-fs-non-number-arguments-throw.js",
"test-fs-open-flags.js",
"test-fs-open-mode-mask.js",
"test-fs-open-no-close.js",
"test-fs-open-numeric-flags.js",
"test-fs-open.js",
"test-fs-opendir.js",
"test-fs-promises-exists.js",
"test-fs-promises-file-handle-stat.js",
"test-fs-promises-file-handle-write.js",
"test-fs-promises-readfile-empty.js",
"test-fs-promises-readfile-with-fd.js",
"test-fs-promises-writefile-with-fd.js",
"test-fs-read-file-sync-hostname.js",
"test-fs-read-file-sync.js",
"test-fs-read-stream-autoClose.js",
"test-fs-read-stream-concurrent-reads.js",
"test-fs-read-stream-double-close.js",
"test-fs-read-stream-encoding.js",
"test-fs-read-stream-fd-leak.js",
"test-fs-read-stream-fd.js",
"test-fs-read-stream-inherit.js",
"test-fs-read-stream-patch-open.js",
"test-fs-read-stream-pos.js",
"test-fs-read-stream-resume.js",
"test-fs-read-stream-throw-type-error.js",
"test-fs-read-stream.js",
@ -356,8 +503,12 @@
"test-fs-readdir-stack-overflow.js",
"test-fs-readdir.js",
"test-fs-readfile-empty.js",
"test-fs-readfile-unlink.js",
"test-fs-readfile-zero-byte-liar.js",
"test-fs-readfilesync-enoent.js",
"test-fs-readv-sync.js",
"test-fs-readv.js",
"test-fs-ready-event-stream.js",
"test-fs-realpath-native.js",
"test-fs-rmdir-recursive-sync-warns-not-found.js",
"test-fs-rmdir-recursive-sync-warns-on-file.js",
@ -367,33 +518,122 @@
"test-fs-rmdir-recursive-warns-on-file.js",
"test-fs-rmdir-recursive.js",
"test-fs-rmdir-type-check.js",
"test-fs-sir-writes-alot.js",
"test-fs-stream-construct-compat-error-read.js",
"test-fs-stream-construct-compat-graceful-fs.js",
"test-fs-stream-construct-compat-old-node.js",
"test-fs-stream-destroy-emit-error.js",
"test-fs-stream-double-close.js",
"test-fs-stream-fs-options.js",
"test-fs-stream-options.js",
"test-fs-symlink-dir-junction-relative.js",
"test-fs-timestamp-parsing-error.js",
"test-fs-truncate-clear-file-zero.js",
"test-fs-util-validateoffsetlength.js",
"test-fs-utimes-y2K38.js",
"test-fs-utimes.js",
"test-fs-watch-file-enoent-after-deletion.js",
"test-fs-watch-recursive-add-file-with-url.js",
"test-fs-watch-recursive-add-file.js",
"test-fs-watch-recursive-add-folder.js",
"test-fs-watch-recursive-update-file.js",
"test-fs-watchfile.js",
"test-fs-write-buffer.js",
"test-fs-write-file-buffer.js",
"test-fs-write-file-invalid-path.js",
"test-fs-write-file-sync.js",
"test-fs-write-file.js",
"test-fs-write-negativeoffset.js",
"test-fs-write-no-fd.js",
"test-fs-write-stream-autoclose-option.js",
"test-fs-write-stream-close-without-callback.js",
"test-fs-write-stream-double-close.js",
"test-fs-write-stream-encoding.js",
"test-fs-write-stream-end.js",
"test-fs-write-stream-fs.js",
"test-fs-write-stream-patch-open.js",
"test-fs-write-stream-throw-type-error.js",
"test-fs-write-stream.js",
"test-fs-write-sync.js",
"test-fs-write.js",
"test-fs-writev-sync.js",
"test-fs-writev.js",
"test-global-domexception.js",
"test-global-encoder.js",
"test-global-webcrypto.js",
"test-global-webstreams.js",
"test-handle-wrap-close-abort.js",
"test-http-abort-before-end.js",
"test-http-addrequest-localaddress.js",
"test-http-agent-false.js",
"test-http-agent-getname.js",
"test-http-agent-keepalive-delay.js",
"test-http-agent-maxtotalsockets.js",
"test-http-agent-no-protocol.js",
"test-http-agent-null.js",
"test-http-allow-req-after-204-res.js",
"test-http-bind-twice.js",
"test-http-buffer-sanity.js",
"test-http-chunked-smuggling.js",
"test-http-chunked.js",
"test-http-client-abort2.js",
"test-http-client-check-http-token.js",
"test-http-client-close-with-default-agent.js",
"test-http-client-default-headers-exist.js",
"test-http-client-defaults.js",
"test-http-client-encoding.js",
"test-http-client-get-url.js",
"test-http-client-headers-array.js",
"test-http-client-invalid-path.js",
"test-http-client-keep-alive-hint.js",
"test-http-client-race-2.js",
"test-http-client-race.js",
"test-http-client-read-in-error.js",
"test-http-client-reject-unexpected-agent.js",
"test-http-client-timeout-connect-listener.js",
"test-http-client-timeout-with-data.js",
"test-http-client-unescaped-path.js",
"test-http-client-upload-buf.js",
"test-http-client-upload.js",
// TODO(lev): ClientRequest.socket is not polyfilled so this test keeps
// failing
//"test-http-client-set-timeout.js",
"test-http-common.js",
"test-http-contentLength0.js",
"test-http-correct-hostname.js",
"test-http-date-header.js",
"test-http-decoded-auth.js",
"test-http-default-encoding.js",
"test-http-dump-req-when-res-ends.js",
"test-http-end-throw-socket-handling.js",
"test-http-eof-on-connect.js",
"test-http-extra-response.js",
"test-http-flush-headers.js",
"test-http-full-response.js",
"test-http-head-request.js",
"test-http-head-response-has-no-body-end-implicit-headers.js",
"test-http-head-response-has-no-body-end.js",
"test-http-head-response-has-no-body.js",
"test-http-head-throw-on-response-body-write.js",
"test-http-header-obstext.js",
"test-http-header-owstext.js",
"test-http-header-read.js",
"test-http-header-validators.js",
"test-http-hex-write.js",
"test-http-highwatermark.js",
"test-http-host-headers.js",
"test-http-hostname-typechecking.js",
"test-http-incoming-message-destroy.js",
"test-http-invalid-path-chars.js",
"test-http-invalidheaderfield.js",
"test-http-invalidheaderfield2.js",
"test-http-keep-alive-timeout-custom.js",
"test-http-listening.js",
"test-http-localaddress-bind-error.js",
"test-http-localaddress.js",
"test-http-methods.js",
"test-http-outgoing-end-types.js",
"test-http-outgoing-finished.js",
// TODO(bartlomieju): temporarily disabled while we iterate on the HTTP client
// "test-http-outgoing-buffer.js",
"test-http-outgoing-internal-headernames-getter.js",
@ -403,53 +643,186 @@
// "test-http-outgoing-message-inheritance.js",
"test-http-outgoing-renderHeaders.js",
"test-http-outgoing-settimeout.js",
"test-http-outgoing-write-types.js",
"test-http-parser-free.js",
"test-http-pause-no-dump.js",
"test-http-pause-resume-one-end.js",
"test-http-pause.js",
"test-http-pipe-fs.js",
"test-http-pipeline-requests-connection-leak.js",
"test-http-proxy.js",
"test-http-readable-data-event.js",
"test-http-request-arguments.js",
"test-http-request-dont-override-options.js",
"test-http-request-end-twice.js",
"test-http-request-end.js",
"test-http-request-invalid-method-error.js",
"test-http-request-large-payload.js",
"test-http-request-methods.js",
"test-http-res-write-end-dont-take-array.js",
"test-http-response-multiheaders.js",
"test-http-response-readable.js",
"test-http-response-writehead-returns-this.js",
"test-http-server-delete-parser.js",
"test-http-server-write-after-end.js",
"test-http-server-write-end-after-end.js",
"test-http-set-cookies.js",
"test-http-set-header-chain.js",
"test-http-status-code.js",
"test-http-status-reason-invalid-chars.js",
"test-http-uncaught-from-request-callback.js",
"test-http-url.parse-auth.js",
"test-http-url.parse-basic.js",
"test-http-url.parse-https.request.js",
"test-http-url.parse-only-support-http-https-protocol.js",
"test-http-url.parse-path.js",
"test-http-url.parse-post.js",
"test-http-url.parse-search.js",
"test-http-wget.js",
"test-http-write-empty-string.js",
"test-http-zerolengthbuffer.js",
"test-http2-client-request-listeners-warning.js",
"test-http2-compat-expect-handling.js",
"test-http2-compat-socket-set.js",
"test-http2-connect-options.js",
"test-http2-date-header.js",
"test-http2-dont-override.js",
"test-http2-endafterheaders.js",
"test-http2-methods.js",
"test-http2-request-response-proto.js",
"test-http2-respond-file-204.js",
"test-http2-respond-file-compat.js",
"test-http2-session-timeout.js",
"test-http2-socket-proxy.js",
"test-http2-status-code-invalid.js",
"test-http2-status-code.js",
"test-http2-stream-removelisteners-after-close.js",
"test-http2-write-empty-string.js",
"test-https-client-renegotiation-limit.js",
"test-https-connecting-to-http.js",
"test-https-foafssl.js",
"test-https-localaddress-bind-error.js",
"test-https-localaddress.js",
"test-icu-data-dir.js",
"test-icu-env.js",
"test-icu-stringwidth.js",
"test-icu-transcode.js",
"test-inspector-stops-no-file.js",
"test-instanceof.js",
"test-internal-fs.js",
"test-internal-util-normalizeencoding.js",
"test-kill-segfault-freebsd.js",
"test-listen-fd-detached-inherit.js",
"test-listen-fd-detached.js",
"test-memory-usage-emfile.js",
"test-memory-usage.js",
"test-messagechannel.js",
"test-microtask-queue-integration.js",
"test-microtask-queue-run-immediate.js",
"test-microtask-queue-run.js",
"test-module-cache.js",
"test-module-circular-symlinks.js",
"test-module-isBuiltin.js",
"test-module-multi-extensions.js",
"test-module-nodemodulepaths.js",
"test-module-readonly.js",
"test-module-relative-lookup.js",
"test-net-access-byteswritten.js",
"test-net-after-close.js",
"test-net-autoselectfamily.js",
"test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-listen.js",
"test-net-better-error-messages-path.js",
"test-net-better-error-messages-port-hostname.js",
"test-net-bind-twice.js",
"test-net-buffersize.js",
"test-net-bytes-written-large.js",
"test-net-can-reset-timeout.js",
"test-net-connect-after-destroy.js",
"test-net-connect-call-socket-connect.js",
"test-net-connect-destroy.js",
"test-net-connect-immediate-destroy.js",
"test-net-connect-immediate-finish.js",
"test-net-connect-no-arg.js",
"test-net-connect-options-fd.js",
"test-net-connect-options-ipv6.js",
"test-net-connect-options-port.js",
"test-net-connect-paused-connection.js",
"test-net-dns-custom-lookup.js",
"test-net-dns-error.js",
"test-net-dns-lookup-skip.js",
"test-net-dns-lookup.js",
"test-net-during-close.js",
"test-net-eaddrinuse.js",
"test-net-end-close.js",
"test-net-end-without-connect.js",
"test-net-error-twice.js",
"test-net-isip.js",
"test-net-isipv4.js",
"test-net-isipv6.js",
"test-net-keepalive.js",
"test-net-listen-after-destroying-stdin.js",
"test-net-listen-close-server-callback-is-not-function.js",
"test-net-listen-close-server.js",
"test-net-listen-error.js",
"test-net-listen-invalid-port.js",
"test-net-listening.js",
"test-net-local-address-port.js",
"test-net-localerror.js",
"test-net-options-lookup.js",
"test-net-pause-resume-connecting.js",
"test-net-persistent-keepalive.js",
"test-net-persistent-nodelay.js",
"test-net-persistent-ref-unref.js",
"test-net-pipe-connect-errors.js",
"test-net-reconnect.js",
"test-net-remote-address-port.js",
"test-net-remote-address.js",
"test-net-server-capture-rejection.js",
"test-net-server-close.js",
"test-net-server-listen-options-signal.js",
"test-net-server-listen-options.js",
"test-net-server-listen-path.js",
"test-net-server-listen-remove-callback.js",
"test-net-server-options.js",
"test-net-server-pause-on-connect.js",
"test-net-server-unref-persistent.js",
"test-net-server-unref.js",
"test-net-settimeout.js",
"test-net-socket-close-after-end.js",
"test-net-socket-connect-invalid-autoselectfamily.js",
"test-net-socket-connect-without-cb.js",
"test-net-socket-connecting.js",
"test-net-socket-destroy-send.js",
"test-net-socket-destroy-twice.js",
"test-net-socket-end-before-connect.js",
"test-net-socket-end-callback.js",
"test-net-socket-no-halfopen-enforcer.js",
"test-net-socket-ready-without-cb.js",
"test-net-socket-setnodelay.js",
"test-net-socket-timeout-unref.js",
"test-net-socket-write-after-close.js",
"test-net-socket-write-error.js",
"test-net-sync-cork.js",
"test-net-timeout-no-handle.js",
"test-net-writable.js",
"test-net-write-arguments.js",
"test-net-write-connect-write.js",
"test-net-write-fully-async-buffer.js",
"test-net-write-fully-async-hex-string.js",
"test-net-write-slow.js",
"test-next-tick-doesnt-hang.js",
"test-next-tick-domain.js",
"test-next-tick-errors.js",
"test-next-tick-fixed-queue-regression.js",
"test-next-tick-intentional-starvation.js",
"test-next-tick-ordering.js",
"test-next-tick-ordering2.js",
"test-next-tick-when-exiting.js",
"test-next-tick.js",
"test-no-node-snapshot.js",
"test-nodeeventtarget.js",
"test-os-homedir-no-envvar.js",
"test-os.js",
"test-outgoing-message-destroy.js",
"test-outgoing-message-pipe.js",
@ -468,15 +841,35 @@
"test-path-win32-exists.js",
"test-path-zero-length-strings.js",
"test-path.js",
"test-perf-gc-crash.js",
"test-performanceobserver-gc.js",
"test-pipe-return-val.js",
"test-pipe-writev.js",
"test-process-abort.js",
"test-process-argv-0.js",
"test-process-beforeexit.js",
"test-process-binding-internalbinding-allowlist.js",
"test-process-binding.js",
"test-process-dlopen-undefined-exports.js",
"test-process-domain-segfault.js",
"test-process-emitwarning.js",
"test-process-env-allowed-flags.js",
"test-process-env-delete.js",
"test-process-env-windows-error-reset.js",
"test-process-exit-from-before-exit.js",
"test-process-exit-handler.js",
"test-process-exit-recursive.js",
"test-process-exit.js",
"test-process-getgroups.js",
"test-process-hrtime-bigint.js",
"test-process-kill-pid.js",
"test-process-next-tick.js",
"test-process-no-deprecation.js",
"test-process-ppid.js",
"test-process-really-exit.js",
"test-process-uptime.js",
"test-process-warning.js",
"test-promise-handled-rejection-no-warning.js",
"test-promise-unhandled-silent.js",
"test-promise-unhandled-throw-handler.js",
"test-punycode.js",
@ -484,6 +877,14 @@
"test-querystring-maxKeys-non-finite.js",
"test-querystring-multichar-separator.js",
"test-querystring.js",
"test-readable-from-iterator-closing.js",
"test-readable-from.js",
"test-readable-large-hwm.js",
"test-readable-single-end.js",
"test-readline-async-iterators-destroy.js",
"test-readline-async-iterators.js",
"test-readline-carriage-return-between-chunks.js",
"test-readline-csi.js",
"test-readline-emit-keypress-events.js",
"test-readline-interface-escapecodetimeout.js",
"test-readline-keys.js",
@ -492,7 +893,31 @@
"test-readline-set-raw-mode.js",
"test-readline-undefined-columns.js",
"test-readline.js",
"test-ref-unref-return.js",
"test-regression-object-prototype.js",
"test-require-invalid-package.js",
"test-require-long-path.js",
"test-require-nul.js",
"test-require-process.js",
"test-signal-handler-remove-on-exit.js",
"test-signal-handler.js",
"test-socket-address.js",
"test-socket-write-after-fin-error.js",
"test-source-map-enable.js",
"test-spawn-cmd-named-pipe.js",
"test-stdin-from-file-spawn.js",
"test-stdin-hang.js",
"test-stdin-pipe-large.js",
"test-stdin-pipe-resume.js",
"test-stdin-script-child-option.js",
"test-stdio-pipe-access.js",
"test-stdio-pipe-redirect.js",
"test-stdio-pipe-stderr.js",
"test-stdio-undestroy.js",
"test-stdout-cannot-be-closed-child-process-pipe.js",
"test-stdout-pipeline-destroy.js",
"test-stdout-stderr-reading.js",
"test-stdout-stderr-write.js",
"test-stream-add-abort-signal.js",
"test-stream-aliases-legacy.js",
"test-stream-auto-destroy.js",
@ -500,22 +925,30 @@
"test-stream-backpressure.js",
"test-stream-big-packet.js",
"test-stream-big-push.js",
"test-stream-catch-rejections.js",
"test-stream-construct.js",
"test-stream-decoder-objectmode.js",
"test-stream-destroy-event-order.js",
"test-stream-duplex-destroy.js",
"test-stream-duplex-end.js",
"test-stream-duplex-from.js",
"test-stream-duplex-props.js",
"test-stream-duplex-readable-end.js",
"test-stream-duplex-readable-writable.js",
"test-stream-duplex-writable-finished.js",
"test-stream-duplex.js",
"test-stream-end-of-streams.js",
"test-stream-end-paused.js",
"test-stream-error-once.js",
"test-stream-events-prepend.js",
"test-stream-filter.js",
"test-stream-flatMap.js",
"test-stream-forEach.js",
"test-stream-inheritance.js",
"test-stream-ispaused.js",
"test-stream-objectmode-undefined.js",
"test-stream-once-readable-pipe.js",
"test-stream-passthrough-drain.js",
"test-stream-pipe-after-end.js",
"test-stream-pipe-await-drain-manual-resume.js",
"test-stream-pipe-await-drain-push-while-write.js",
@ -523,6 +956,7 @@
"test-stream-pipe-cleanup-pause.js",
"test-stream-pipe-cleanup.js",
"test-stream-pipe-error-handling.js",
"test-stream-pipe-error-unhandled.js",
"test-stream-pipe-event.js",
"test-stream-pipe-flow-after-unpipe.js",
"test-stream-pipe-flow.js",
@ -533,8 +967,12 @@
"test-stream-pipe-unpipe-streams.js",
"test-stream-pipe-without-listenerCount.js",
"test-stream-pipeline-async-iterator.js",
"test-stream-pipeline-duplex.js",
"test-stream-pipeline-listeners.js",
"test-stream-pipeline-queued-end-in-destroy.js",
"test-stream-pipeline-uncaught.js",
"test-stream-pipeline-with-empty-string.js",
"test-stream-push-order.js",
"test-stream-push-strings.js",
"test-stream-readable-aborted.js",
"test-stream-readable-add-chunk-during-data.js",
@ -566,15 +1004,21 @@
"test-stream-readable-resumeScheduled.js",
"test-stream-readable-setEncoding-existing-buffers.js",
"test-stream-readable-setEncoding-null.js",
"test-stream-readable-strategy-option.js",
"test-stream-readable-unpipe-resume.js",
"test-stream-readable-unshift.js",
"test-stream-readable-with-unimplemented-_read.js",
"test-stream-readableListening-state.js",
"test-stream-reduce.js",
"test-stream-toArray.js",
"test-stream-toWeb-allows-server-response.js",
"test-stream-transform-callback-twice.js",
"test-stream-transform-constructor-set-methods.js",
"test-stream-transform-destroy.js",
"test-stream-transform-final-sync.js",
"test-stream-transform-final.js",
"test-stream-transform-flush-data.js",
"test-stream-transform-hwm0.js",
"test-stream-transform-objectmode-falsey-value.js",
"test-stream-transform-split-highwatermark.js",
"test-stream-transform-split-objectmode.js",
@ -589,6 +1033,7 @@
"test-stream-writable-decoded-encoding.js",
"test-stream-writable-destroy.js",
"test-stream-writable-end-cb-error.js",
"test-stream-writable-end-cb-uncaught.js",
"test-stream-writable-end-multiple.js",
"test-stream-writable-ended-state.js",
"test-stream-writable-final-async.js",
@ -616,6 +1061,7 @@
"test-stream2-basic.js",
"test-stream2-compatibility.js",
"test-stream2-decode-partial.js",
"test-stream2-finish-pipe-error.js",
"test-stream2-finish-pipe.js",
"test-stream2-large-read-stall.js",
"test-stream2-objects.js",
@ -638,24 +1084,60 @@
"test-stream3-cork-end.js",
"test-stream3-cork-uncork.js",
"test-stream3-pause-then-read.js",
"test-stream3-pipeline-async-iterator.js",
"test-streams-highwatermark.js",
"test-string-decoder.js",
"test-stringbytes-external.js",
"test-sync-fileread.js",
"test-sys.js",
"test-tick-processor-arguments.js",
"test-timers-api-refs.js",
"test-timers-args.js",
"test-timers-clear-null-does-not-throw-error.js",
"test-timers-clear-object-does-not-throw-error.js",
"test-timers-clear-timeout-interval-equivalent.js",
"test-timers-clearImmediate-als.js",
"test-timers-clearImmediate.js",
"test-timers-immediate-queue.js",
"test-timers-immediate.js",
"test-timers-interval-throw.js",
"test-timers-non-integer-delay.js",
"test-timers-refresh-in-callback.js",
"test-timers-refresh.js",
"test-timers-same-timeout-wrong-list-deleted.js",
"test-timers-setimmediate-infinite-loop.js",
"test-timers-socket-timeout-removes-other-socket-unref-timer.js",
"test-timers-timeout-with-non-integer.js",
"test-timers-uncaught-exception.js",
"test-timers-unref-throw-then-ref.js",
"test-timers-unref.js",
"test-timers-unrefd-interval-still-fires.js",
"test-timers-unrefed-in-beforeexit.js",
"test-timers-unrefed-in-callback.js",
"test-timers-user-call.js",
"test-timers-zero-timeout.js",
"test-timers.js",
"test-tls-alert-handling.js",
"test-tls-alert.js",
"test-tls-client-renegotiation-limit.js",
"test-tls-dhe.js",
"test-tls-ecdh-auto.js",
"test-tls-ecdh-multiple.js",
"test-tls-ecdh.js",
"test-tls-enable-trace-cli.js",
"test-tls-enable-trace.js",
"test-tls-env-extra-ca-no-crypto.js",
"test-tls-ocsp-callback.js",
"test-tls-psk-server.js",
"test-tls-securepair-server.js",
"test-tls-server-verify.js",
"test-tls-session-cache.js",
"test-tls-set-ciphers.js",
"test-tls-transport-destroy-after-own-gc.js",
"test-trace-events-async-hooks-dynamic.js",
"test-trace-events-async-hooks-worker.js",
"test-tty-stdin-end.js",
"test-tz-version.js",
"test-url-domain-ascii-unicode.js",
"test-url-fileurltopath.js",
"test-url-format-invalid-input.js",
@ -666,19 +1148,31 @@
"test-url-pathtofileurl.js",
"test-url-relative.js",
"test-url-urltooptions.js",
"test-utf8-scripts.js",
"test-util-deprecate-invalid-code.js",
"test-util-deprecate.js",
"test-util-format.js",
"test-util-inherits.js",
"test-util-inspect-getters-accessing-this.js",
"test-util-inspect-long-running.js",
"test-util-inspect-namespace.js",
"test-util-inspect-proxy.js",
"test-util-inspect.js",
"test-util-isDeepStrictEqual.js",
"test-util-primordial-monkeypatching.js",
"test-util-promisify.js",
"test-util-types-exists.js",
"test-util-types.js",
"test-util.js",
"test-uv-binding-constant.js",
"test-uv-unmapped-exception.js",
"test-v8-coverage.js",
"test-v8-deserialize-buffer.js",
"test-v8-flag-pool-size-0.js",
"test-v8-global-setter.js",
"test-v8-stop-coverage.js",
"test-v8-take-coverage-noop.js",
"test-v8-take-coverage.js",
"test-vm-access-process-env.js",
"test-vm-attributes-property-not-on-sandbox.js",
"test-vm-codegen.js",
@ -723,28 +1217,39 @@
"test-vm-timeout-escape-promise-2.js",
"test-vm-timeout-escape-promise.js",
"test-vm-timeout.js",
"test-weakref.js",
"test-webcrypto-encrypt-decrypt.js",
"test-webcrypto-sign-verify.js",
"test-websocket.js",
"test-webstream-string-tag.js",
"test-whatwg-encoding-custom-api-basics.js",
"test-whatwg-encoding-custom-textdecoder-ignorebom.js",
"test-whatwg-encoding-custom-textdecoder-streaming.js",
"test-whatwg-events-add-event-listener-options-passive.js",
"test-whatwg-events-add-event-listener-options-signal.js",
"test-whatwg-events-customevent.js",
"test-whatwg-readablebytestreambyob.js",
"test-whatwg-url-custom-deepequal.js",
"test-whatwg-url-custom-global.js",
"test-whatwg-url-custom-href-side-effect.js",
"test-whatwg-url-custom-tostringtag.js",
"test-whatwg-url-override-hostname.js",
"test-whatwg-url-properties.js",
"test-worker-cleanexit-with-js.js",
"test-worker-message-port-infinite-message-loop.js",
"test-worker-message-port-multiple-sharedarraybuffers.js",
"test-worker-message-port-receive-message.js",
"test-worker-on-process-exit.js",
"test-worker-ref-onexit.js",
"test-worker-terminate-unrefed.js",
"test-zlib-close-after-error.js",
"test-zlib-close-after-write.js",
"test-zlib-convenience-methods.js",
"test-zlib-create-raw.js",
"test-zlib-deflate-raw-inherits.js",
"test-zlib-destroy-pipe.js",
"test-zlib-empty-buffer.js",
"test-zlib-flush-write-sync-interleaved.js",
"test-zlib-from-string.js",
"test-zlib-invalid-input.js",
"test-zlib-no-stream.js",
@ -762,14 +1267,41 @@
"console-dumb-tty.js",
"no_dropped_stdio.js",
"no_interleaved_stdio.js",
"test-set-raw-mode-reset-process-exit.js",
"test-set-raw-mode-reset.js",
"test-tty-color-support-warning-2.js",
"test-tty-color-support-warning.js",
"test-tty-stdin-call-end.js",
"test-tty-stdin-end.js",
"test-tty-stdout-end.js"
],
"pummel": [],
"pummel": [
"test-crypto-dh-hash.js",
"test-crypto-timing-safe-equal-benchmarks.js",
"test-dh-regr.js",
"test-fs-largefile.js",
"test-fs-readfile-tostring-fail.js",
"test-fs-watch-system-limit.js",
"test-heapsnapshot-near-heap-limit-big.js",
"test-net-many-clients.js",
"test-net-pingpong-delay.js",
"test-process-cpuUsage.js",
"test-stream-pipe-multi.js"
],
"sequential": [
"test-child-process-exit.js"
"test-buffer-creation-regression.js",
"test-child-process-exit.js",
"test-http-server-keep-alive-timeout-slow-server.js",
"test-net-better-error-messages-port.js",
"test-net-connect-handle-econnrefused.js",
"test-net-connect-local-error.js",
"test-net-reconnect-error.js",
"test-net-response-size.js",
"test-net-server-bind.js",
"test-tls-lookup.js",
"test-tls-psk-client.js",
"test-tls-securepair-client.js",
"test-tls-session-timeout.js"
]
},
"windowsIgnore": {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,143 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const { spawnSync } = require('child_process');
// This is a sibling test to test/addons/uv-handle-leak.
const bindingPath = path.resolve(
__dirname, '..', 'addons', 'uv-handle-leak', 'build',
`${common.buildType}/binding.node`);
if (!fs.existsSync(bindingPath))
common.skip('binding not built yet');
if (process.argv[2] === 'child') {
const { Worker } = require('worker_threads');
// The worker thread loads and then unloads `bindingPath`. Because of this the
// symbols in `bindingPath` are lost when the worker thread quits, but the
// number of open handles in the worker thread's event loop is assessed in the
// main thread afterwards, and the names of the callbacks associated with the
// open handles is retrieved at that time as well. Thus, we require
// `bindingPath` here so that the symbols and their names survive the life
// cycle of the worker thread.
require(bindingPath);
new Worker(`
const binding = require(${JSON.stringify(bindingPath)});
binding.leakHandle();
binding.leakHandle(0);
binding.leakHandle(0x42);
`, { eval: true });
} else {
const child = cp.spawnSync(process.execPath, [__filename, 'child']);
const stderr = child.stderr.toString();
assert.strictEqual(child.stdout.toString(), '');
const lines = stderr.split('\n');
let state = 'initial';
// Parse output that is formatted like this:
// uv loop at [0x559b65ed5770] has open handles:
// [0x7f2de0018430] timer (active)
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: 0x7f2df33df140 example_instance [...]
// (First field): 0x7f2df33dedc0 vtable for ExampleOwnerClass [...]
// [0x7f2de000b870] timer
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: (nil)
// [0x7f2de000b910] timer
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: 0x42
// uv loop at [0x559b65ed5770] has 3 open handles in total
function isGlibc() {
try {
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
const libcInfo = lddOut.toString().split('\n').map(
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
if (libcInfo.length === 0)
return false;
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
if (/gnu_get_libc_version/.test(nmOut))
return true;
} catch {
return false;
}
}
if (!(common.isFreeBSD ||
common.isAIX ||
common.isIBMi ||
(common.isLinux && !isGlibc()) ||
common.isWindows)) {
assert(stderr.includes('ExampleOwnerClass'), stderr);
assert(stderr.includes('CloseCallback'), stderr);
assert(stderr.includes('example_instance'), stderr);
}
while (lines.length > 0) {
const line = lines.shift().trim();
if (line.length === 0) {
continue; // Skip empty lines.
}
switch (state) {
case 'initial':
assert.match(line, /^uv loop at \[.+\] has open handles:$/);
state = 'handle-start';
break;
case 'handle-start':
if (/^uv loop at \[.+\] has \d+ open handles in total$/.test(line)) {
state = 'source-line';
break;
}
assert.match(line, /^\[.+\] timer( \(active\))?$/);
state = 'close-callback';
break;
case 'close-callback':
assert.match(line, /^Close callback:/);
state = 'data';
break;
case 'data':
assert.match(line, /^Data: .+$/);
state = 'maybe-first-field';
break;
case 'maybe-first-field':
if (!/^\(First field\)/.test(line)) {
lines.unshift(line);
}
state = 'handle-start';
break;
case 'source-line':
assert.match(line, /CheckedUvLoopClose/);
state = 'assertion-failure';
break;
case 'assertion-failure':
assert.match(line, /Assertion failed:/);
state = 'done';
break;
case 'done':
break;
}
}
assert.strictEqual(state, 'done');
}

View file

@ -0,0 +1,20 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for async_hooks benchmark test');
const runBenchmark = require('../common/benchmark');
runBenchmark('async_hooks');

View file

@ -0,0 +1,21 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP benchmark test');
// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('http', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,23 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP/2 benchmark test');
// Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('http2', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,24 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.enoughTestMem)
common.skip('Insufficient memory for TLS benchmark test');
// Because the TLS benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose
// random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('tls', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,21 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.enoughTestMem)
common.skip('Insufficient memory for Worker benchmark test');
// Because the worker benchmarks can run on different threads,
// this should be in sequential rather than parallel to make sure
// it does not conflict with tests that choose random available ports.
const runBenchmark = require('../common/benchmark');
runBenchmark('worker', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

View file

@ -0,0 +1,19 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const { mustNotCall, mustCall } = require('../common');
Object.defineProperties(Object.prototype, {
then: {
set: mustNotCall('set %Object.prototype%.then'),
get: mustNotCall('get %Object.prototype%.then'),
},
});
import('data:text/javascript,').then(mustCall());

View file

@ -0,0 +1,29 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('node:assert');
const fs = require('node:fs/promises');
tmpdir.refresh();
const target = tmpdir.fileURL(`${Math.random()}.mjs`);
(async () => {
await assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' });
await fs.writeFile(target, 'export default "actual target"\n');
const moduleRecord = await import(target);
await fs.rm(target);
assert.strictEqual(await import(target), moduleRecord);
})().then(common.mustCall());

View file

@ -0,0 +1,17 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const { cache } = require;
Object.keys(cache).forEach((key) => {
delete cache[key];
});
// Require the same module again triggers the crash
require('../common');

View file

@ -0,0 +1,54 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// This test ensures that JavaScript file that includes
// a reserved Windows word can be loaded as ESM module
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs').promises;
const path = require('path');
const imp = (file) => {
return import(path.relative(__dirname, file).replace(/\\/g, '/'));
};
(async () => {
tmpdir.refresh();
const rel = (file) => tmpdir.resolve(file);
{ // Load a single script
const file = rel('con.mjs');
await fs.writeFile(file, 'export default "ok"');
assert.strictEqual((await imp(file)).default, 'ok');
await fs.unlink(file);
}
{ // Load a module
const entry = rel('entry.mjs');
const nmDir = rel('node_modules');
const mDir = rel('node_modules/con');
const pkg = rel('node_modules/con/package.json');
const script = rel('node_modules/con/index.mjs');
await fs.writeFile(entry, 'export {default} from "con"');
await fs.mkdir(nmDir);
await fs.mkdir(mDir);
await fs.writeFile(pkg, '{"main":"index.mjs"}');
await fs.writeFile(script, 'export default "ok"');
assert.strictEqual((await imp(entry)).default, 'ok');
await fs.unlink(script);
await fs.unlink(pkg);
await fs.rmdir(mDir);
await fs.rmdir(nmDir);
await fs.unlink(entry);
}
})().then(common.mustCall());

View file

@ -0,0 +1,41 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
const { compileFunction } = require('node:vm');
const min = -2147483648;
const max = 2147483647;
compileFunction('', [], { lineOffset: min, columnOffset: min });
compileFunction('', [], { lineOffset: max, columnOffset: max });
assert.throws(
() => {
compileFunction('', [], { lineOffset: min - 1, columnOffset: max });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.lineOffset" is out of range/,
}
);
assert.throws(
() => {
compileFunction('', [], { lineOffset: min, columnOffset: min - 1 });
},
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: /The value of "options\.columnOffset" is out of range/,
}
);

View file

@ -0,0 +1,60 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
const args = [];
if (strict) args.push('--use_strict');
args.push('-pe', cmd);
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.on('close', cb);
}
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
'var x = 100; y = x;',
'var ______________________________________________; throw 10' ];
function go() {
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);
});
}
go();

View file

@ -0,0 +1,38 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
process.maxTickDepth = 10;
let i = 20;
process.nextTick(function f() {
console.error(`tick ${i}`);
if (i-- > 0)
process.nextTick(f);
});

View file

@ -0,0 +1,61 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const spawn = require('child_process').spawn;
function run(cmd, strict, cb) {
const args = [];
if (strict) args.push('--use_strict');
args.push('-p');
const child = spawn(process.execPath, args);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stdout);
child.stdin.end(cmd);
child.on('close', cb);
}
const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
'let x = 100; y = x;',
'let ______________________________________________; throw 10' ];
function go() {
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, true, go);
});
}
go();

View file

@ -0,0 +1,19 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const util = require('util');
const err = new Error('foo\nbar');
console.log(util.inspect({ err, nested: { err } }, { compact: true }));
console.log(util.inspect({ err, nested: { err } }, { compact: false }));
err.foo = 'bar';
console.log(util.inspect(err, { compact: true, breakLength: 5 }));

View file

@ -0,0 +1,22 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
// This test ensures Math functions don't fail with an "illegal instruction"
// error on ARM devices (primarily on the Raspberry Pi 1)
// See https://github.com/nodejs/node/issues/1376
// and https://code.google.com/p/v8/issues/detail?id=4019
// Iterate over all Math functions
Object.getOwnPropertyNames(Math).forEach((functionName) => {
if (!/[A-Z]/.test(functionName)) {
// The function names don't have capital letters.
Math[functionName](-0.5);
}
});

View file

@ -0,0 +1,18 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const { AsyncResource } = require('async_hooks');
try {
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
} catch {
// Continue regardless of error.
}
// Should abort (fail the case) if async id is not matching.

View file

@ -0,0 +1,24 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// Test that passing thisArg to runInAsyncScope() works.
const common = require('../common');
const assert = require('assert');
const { AsyncResource } = require('async_hooks');
const thisArg = {};
const res = new AsyncResource('fhqwhgads');
function callback() {
assert.strictEqual(this, thisArg);
}
res.runInAsyncScope(common.mustCall(callback), thisArg);

View file

@ -0,0 +1,24 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
[1, false, '', {}, []].forEach((i) => {
assert.throws(() => AsyncLocalStorage.bind(i), {
code: 'ERR_INVALID_ARG_TYPE'
});
});
const fn = common.mustCall(AsyncLocalStorage.bind(() => 123));
assert.strictEqual(fn(), 123);
const fn2 = AsyncLocalStorage.bind(common.mustCall((arg) => assert.strictEqual(arg, 'test')));
fn2('test');

View file

@ -0,0 +1,42 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
const { AsyncLocalStorage } = require('async_hooks');
// Regression test for https://github.com/nodejs/node/issues/38781
const context = vm.createContext({
AsyncLocalStorage,
assert
});
vm.runInContext(`
const storage = new AsyncLocalStorage()
async function test() {
return storage.run({ test: 'vm' }, async () => {
assert.strictEqual(storage.getStore().test, 'vm');
await 42;
assert.strictEqual(storage.getStore().test, 'vm');
});
}
test()
`, context);
const storage = new AsyncLocalStorage();
async function test() {
return storage.run({ test: 'main context' }, async () => {
assert.strictEqual(storage.getStore().test, 'main context');
await 42;
assert.strictEqual(storage.getStore().test, 'main context');
});
}
test();

View file

@ -0,0 +1,22 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');
// Regression test for: https://github.com/nodejs/node/issues/34556
const als = new AsyncLocalStorage();
const done = common.mustCall();
function run(count) {
if (count !== 0) return als.run({}, run, --count);
done();
}
run(1000);

View file

@ -0,0 +1,72 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const http = require('http');
const cls = new AsyncLocalStorage();
const NUM_CLIENTS = 10;
// Run multiple clients that receive data from a server
// in multiple chunks, in a single non-closure function.
// Use the AsyncLocalStorage (ALS) APIs to maintain the context
// and data download. Make sure that individual clients
// receive their respective data, with no conflicts.
// Set up a server that sends large buffers of data, filled
// with cardinal numbers, increasing per request
let index = 0;
const server = http.createServer((q, r) => {
// Send a large chunk as response, otherwise the data
// may be sent in a single chunk, and the callback in the
// client may be called only once, defeating the purpose of test
r.end((index++ % 10).toString().repeat(1024 * 1024));
});
const countdown = new Countdown(NUM_CLIENTS, () => {
server.close();
});
server.listen(0, common.mustCall(() => {
for (let i = 0; i < NUM_CLIENTS; i++) {
cls.run(new Map(), common.mustCall(() => {
const options = { port: server.address().port };
const req = http.get(options, common.mustCall((res) => {
const store = cls.getStore();
store.set('data', '');
// Make ondata and onend non-closure
// functions and fully dependent on ALS
res.setEncoding('utf8');
res.on('data', ondata);
res.on('end', common.mustCall(onend));
}));
req.end();
}));
}
}));
// Accumulate the current data chunk with the store data
function ondata(d) {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
let chunk = store.get('data');
chunk += d;
store.set('data', chunk);
}
// Retrieve the store data, and test for homogeneity
function onend() {
const store = cls.getStore();
assert.notStrictEqual(store, undefined);
const data = store.get('data');
assert.strictEqual(data, data[0].repeat(data.length));
countdown.dec();
}

View file

@ -0,0 +1,23 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
const runInAsyncScope =
asyncLocalStorage.run(123, common.mustCall(() => AsyncLocalStorage.snapshot()));
const result =
asyncLocalStorage.run(321, common.mustCall(() => {
return runInAsyncScope(() => {
return asyncLocalStorage.getStore();
});
}));
strictEqual(result, 123);

View file

@ -0,0 +1,14 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
// https://github.com/nodejs/node/issues/21219
assert.strictEqual(Atomics.wake, undefined);

View file

@ -0,0 +1,34 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const { mustNotCall } = require('../common');
process.on('beforeExit', mustNotCall('exit should not allow this to occur'));
process.exit();

View file

@ -0,0 +1,31 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Flags: --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
const { Blob, kMaxLength } = require('buffer');
if (common.isFreeBSD)
common.skip('Oversized buffer make the FreeBSD CI runner crash');
try {
new Blob([new Uint8Array(kMaxLength), [1]]);
} catch (e) {
if (
e.message === 'Array buffer allocation failed' ||
e.message === `Invalid typed array length: ${kMaxLength}`
) {
common.skip(
'Insufficient memory on this platform for oversized buffer test.'
);
} else {
assert.strictEqual(e.code, 'ERR_BUFFER_TOO_LARGE');
}
}

View file

@ -0,0 +1,34 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
const sab = new SharedArrayBuffer(24);
const arr1 = new Uint16Array(sab);
const arr2 = new Uint16Array(12);
arr2[0] = 5000;
arr1[0] = 5000;
arr1[1] = 4000;
arr2[1] = 4000;
const arr_buf = Buffer.from(arr1.buffer);
const ar_buf = Buffer.from(arr2.buffer);
assert.deepStrictEqual(arr_buf, ar_buf);
arr1[1] = 6000;
arr2[1] = 6000;
assert.deepStrictEqual(arr_buf, ar_buf);
// Checks for calling Buffer.byteLength on a SharedArrayBuffer.
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
Buffer.from({ buffer: sab }); // Should not throw.

View file

@ -0,0 +1,115 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
[-1, 10].forEach((offset) => {
assert.throws(
() => Buffer.alloc(9).write('foo', offset),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0 && <= 9. Received ${offset}`
}
);
});
const resultMap = new Map([
['utf8', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['ucs2', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['ascii', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['latin1', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['binary', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['utf16le', Buffer.from([102, 0, 111, 0, 111, 0, 0, 0, 0])],
['base64', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['base64url', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
['hex', Buffer.from([102, 111, 111, 0, 0, 0, 0, 0, 0])],
]);
// utf8, ucs2, ascii, latin1, utf16le
const encodings = ['utf8', 'utf-8', 'ucs2', 'ucs-2', 'ascii', 'latin1',
'binary', 'utf16le', 'utf-16le'];
encodings
.reduce((es, e) => es.concat(e, e.toUpperCase()), [])
.forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('foo', encoding);
assert.strictEqual(buf.write('foo', 0, len, encoding), len);
if (encoding.includes('-'))
encoding = encoding.replace('-', '');
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// base64
['base64', 'BASE64', 'base64url', 'BASE64URL'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('Zm9v', encoding);
assert.strictEqual(buf.write('Zm9v', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// hex
['hex', 'HEX'].forEach((encoding) => {
const buf = Buffer.alloc(9);
const len = Buffer.byteLength('666f6f', encoding);
assert.strictEqual(buf.write('666f6f', 0, len, encoding), len);
assert.deepStrictEqual(buf, resultMap.get(encoding.toLowerCase()));
});
// Invalid encodings
for (let i = 1; i < 10; i++) {
const encoding = String(i).repeat(i);
const error = common.expectsError({
code: 'ERR_UNKNOWN_ENCODING',
name: 'TypeError',
message: `Unknown encoding: ${encoding}`
});
assert.ok(!Buffer.isEncoding(encoding));
assert.throws(() => Buffer.alloc(9).write('foo', encoding), error);
}
// UCS-2 overflow CVE-2018-12115
for (let i = 1; i < 4; i++) {
// Allocate two Buffers sequentially off the pool. Run more than once in case
// we hit the end of the pool and don't get sequential allocations
const x = Buffer.allocUnsafe(4).fill(0);
const y = Buffer.allocUnsafe(4).fill(1);
// Should not write anything, pos 3 doesn't have enough room for a 16-bit char
assert.strictEqual(x.write('ыыыыыы', 3, 'ucs2'), 0);
// CVE-2018-12115 experienced via buffer overrun to next block in the pool
assert.strictEqual(Buffer.compare(y, Buffer.alloc(4, 1)), 0);
}
// Should not write any data when there is no space for 16-bit chars
const z = Buffer.alloc(4, 0);
assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0);
assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0);
// Make sure longer strings are written up to the buffer end.
assert.strictEqual(z.write('abcd', 2), 2);
assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]);
// Large overrun could corrupt the process
assert.strictEqual(Buffer.alloc(4)
.write('ыыыыыы'.repeat(100), 3, 'utf16le'), 0);
{
// .write() does not affect the byte after the written-to slice of the Buffer.
// Refs: https://github.com/nodejs/node/issues/26422
const buf = Buffer.alloc(8);
assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4);
assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]);
}

View file

@ -0,0 +1,34 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const child_process = require('child_process');
const fixtures = require('../common/fixtures');
child_process.fork(fixtures.path('empty.js')); // should not hang

View file

@ -0,0 +1,36 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
function fail(proc, args) {
assert.throws(() => {
proc.send.apply(proc, args);
}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
}
let target = process;
if (process.argv[2] !== 'child') {
target = cp.fork(__filename, ['child']);
target.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
}
fail(target, ['msg', null, null]);
fail(target, ['msg', null, '']);
fail(target, ['msg', null, 'foo']);
fail(target, ['msg', null, 0]);
fail(target, ['msg', null, NaN]);
fail(target, ['msg', null, 1]);
fail(target, ['msg', null, null, common.mustNotCall()]);

View file

@ -0,0 +1,47 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
if (process.argv[2] === 'child') {
// Just reference stdin, it should start it
process.stdin; // eslint-disable-line no-unused-expressions
return;
}
const proc = spawn(process.execPath, [__filename, 'child'], {
stdio: ['ipc', 'inherit', 'inherit']
});
proc.on('exit', common.mustCall(function(code) {
assert.strictEqual(code, 0);
}));

View file

@ -0,0 +1,86 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Test for "overlapped" stdio option. This test uses the "overlapped-checker"
// helper program which basically a specialized echo program.
//
// The test has two goals:
//
// - Verify that overlapped I/O works on windows. The test program will deadlock
// if stdin doesn't have the FILE_FLAG_OVERLAPPED flag set on startup (see
// test/overlapped-checker/main_win.c for more details).
// - Verify that "overlapped" stdio option works transparently as a pipe (on
// unix/windows)
//
// This is how the test works:
//
// - This script assumes only numeric strings are written to the test program
// stdout.
// - The test program will be spawned with "overlapped" set on stdin and "pipe"
// set on stdout/stderr and at startup writes a number to its stdout
// - When this script receives some data, it will parse the number, add 50 and
// write to the test program's stdin.
// - The test program will then echo the number back to us which will repeat the
// cycle until the number reaches 200, at which point we send the "exit"
// string, which causes the test program to exit.
// - Extra assertion: Every time the test program writes a string to its stdout,
// it will write the number of bytes written to stderr.
// - If overlapped I/O is not setup correctly, this test is going to hang.
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const child_process = require('child_process');
const exeExtension = process.platform === 'win32' ? '.exe' : '';
const exe = 'overlapped-checker' + exeExtension;
const exePath = path.join(path.dirname(process.execPath), exe);
if (!require('fs').existsSync(exePath)) {
common.skip(exe + ' binary is not available');
}
const child = child_process.spawn(exePath, [], {
stdio: ['overlapped', 'pipe', 'pipe']
});
child.stdin.setEncoding('utf8');
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
function writeNext(n) {
child.stdin.write((n + 50).toString());
}
child.stdout.on('data', (s) => {
const n = Number(s);
if (n >= 200) {
child.stdin.write('exit');
return;
}
writeNext(n);
});
let stderr = '';
child.stderr.on('data', (s) => {
stderr += s;
});
child.stderr.on('end', common.mustCall(() => {
// This is the sequence of numbers sent to us:
// - 0 (1 byte written)
// - 50 (2 bytes written)
// - 100 (3 bytes written)
// - 150 (3 bytes written)
// - 200 (3 bytes written)
assert.strictEqual(stderr, '12333');
}));
child.on('exit', common.mustCall((status) => {
// The test program will return the number of writes as status code.
assert.strictEqual(status, 0);
}));

View file

@ -0,0 +1,20 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// Test that http.ClientRequest,prototype.destroy() returns `this`.
require('../common');
const assert = require('assert');
const http = require('http');
const clientRequest = new http.ClientRequest({ createConnection: () => {} });
assert.strictEqual(clientRequest.destroyed, false);
assert.strictEqual(clientRequest.destroy(), clientRequest);
assert.strictEqual(clientRequest.destroyed, true);
assert.strictEqual(clientRequest.destroy(), clientRequest);

View file

@ -0,0 +1,56 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// Installing a custom uncaughtException handler should override the default
// one that the cluster module installs.
// https://github.com/joyent/node/issues/2556
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const fork = require('child_process').fork;
const MAGIC_EXIT_CODE = 42;
const isTestRunner = process.argv[2] !== 'child';
if (isTestRunner) {
const primary = fork(__filename, ['child']);
primary.on('exit', common.mustCall((code) => {
assert.strictEqual(code, MAGIC_EXIT_CODE);
}));
} else if (cluster.isPrimary) {
process.on('uncaughtException', common.mustCall(() => {
process.nextTick(() => process.exit(MAGIC_EXIT_CODE));
}));
cluster.fork();
throw new Error('kill primary');
} else { // worker
process.exit();
}

View file

@ -0,0 +1,35 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// Patch global.console before importing modules that may modify the console
// object.
const tmp = global.console;
global.console = 42;
require('../common');
const assert = require('assert');
// Originally the console had a getter. Test twice to verify it had no side
// effect.
assert.strictEqual(global.console, 42);
assert.strictEqual(global.console, 42);
assert.throws(
() => console.log('foo'),
{ name: 'TypeError' }
);
global.console = 1;
assert.strictEqual(global.console, 1);
assert.strictEqual(console, 1);
// Reset the console
global.console = tmp;
console.log('foo');

View file

@ -0,0 +1,21 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// Flags: --expose-internals
require('../common');
const { formatTime } = require('internal/console/constructor');
const assert = require('assert');
assert.strictEqual(formatTime(100.0096), '100.01ms');
assert.strictEqual(formatTime(100.0115), '100.011ms');
assert.strictEqual(formatTime(1500.04), '1.500s');
assert.strictEqual(formatTime(1000.056), '1.000s');
assert.strictEqual(formatTime(60300.3), '1:00.300 (m:ss.mmm)');
assert.strictEqual(formatTime(4000457.4), '1:06:40.457 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3601310.4), '1:00:01.310 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3213601017.6), '892:40:01.018 (h:mm:ss.mmm)');

View file

@ -0,0 +1,41 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('assert');
function func() {}
let toStringCalled = false;
func.toString = function() {
toStringCalled = true;
};
require('util').inspect(func);
assert.ok(!toStringCalled);

View file

@ -0,0 +1,13 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
// Assigning to itself should not throw.
global.console = global.console; // eslint-disable-line no-self-assign

View file

@ -0,0 +1,118 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
// https://github.com/nodejs/node/issues/32738
// XXX(bnoordhuis) validateInt32() throwing ERR_OUT_OF_RANGE and RangeError
// instead of ERR_INVALID_ARG_TYPE and TypeError is questionable, IMO.
assert.throws(() => crypto.createDiffieHellman(13.37), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "sizeOrKey" is out of range. ' +
'It must be an integer. Received 13.37',
});
assert.throws(() => crypto.createDiffieHellman('abcdef', 13.37), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "generator" is out of range. ' +
'It must be an integer. Received 13.37',
});
for (const bits of [-1, 0, 1]) {
if (common.hasOpenSSL3) {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_DH_MODULUS_TOO_SMALL',
name: 'Error',
message: /modulus too small/,
});
} else {
assert.throws(() => crypto.createDiffieHellman(bits), {
code: 'ERR_OSSL_BN_BITS_TOO_SMALL',
name: 'Error',
message: /bits too small/,
});
}
}
for (const g of [-1, 1]) {
const ex = {
code: 'ERR_OSSL_DH_BAD_GENERATOR',
name: 'Error',
message: /bad generator/,
};
assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex);
assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex);
}
for (const g of [Buffer.from([]),
Buffer.from([0]),
Buffer.from([1])]) {
const ex = {
code: 'ERR_OSSL_DH_BAD_GENERATOR',
name: 'Error',
message: /bad generator/,
};
assert.throws(() => crypto.createDiffieHellman('abcdef', g), ex);
assert.throws(() => crypto.createDiffieHellman('abcdef', 'hex', g), ex);
}
[
[0x1, 0x2],
() => { },
/abc/,
{},
].forEach((input) => {
assert.throws(
() => crypto.createDiffieHellman(input),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
}
);
});
// Invalid test: curve argument is undefined
assert.throws(
() => crypto.createECDH(),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "curve" argument must be of type string. ' +
'Received undefined'
});
assert.throws(
function() {
crypto.getDiffieHellman('unknown-group');
},
{
name: 'Error',
code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP',
message: 'Unknown DH group'
},
'crypto.getDiffieHellman(\'unknown-group\') ' +
'failed to throw the expected error.'
);
assert.throws(
() => crypto.createDiffieHellman('', true),
{
code: 'ERR_INVALID_ARG_TYPE'
}
);
[true, Symbol(), {}, () => {}, []].forEach((generator) => assert.throws(
() => crypto.createDiffieHellman('', 'base64', generator),
{ code: 'ERR_INVALID_ARG_TYPE' }
));

View file

@ -0,0 +1,50 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
function test() {
const odd = Buffer.alloc(39, 'A');
const c = crypto.createDiffieHellman(common.hasOpenSSL3 ? 1024 : 32);
c.setPrivateKey(odd);
c.generateKeys();
}
// FIPS requires a length of at least 1024
if (!common.hasFipsCrypto) {
test();
} else {
assert.throws(function() { test(); }, /key size too small/);
}

View file

@ -0,0 +1,56 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const domain = require('domain');
const test = (fn) => {
const ex = new Error('BAM');
const d = domain.create();
d.on('error', common.mustCall(function(err) {
assert.strictEqual(err, ex);
}));
const cb = common.mustCall(function() {
throw ex;
});
d.run(cb);
};
test(function(cb) {
crypto.pbkdf2('password', 'salt', 1, 8, cb);
});
test(function(cb) {
crypto.randomBytes(32, cb);
});

View file

@ -0,0 +1,72 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// This is the same as test/simple/test-crypto, but from before the shift
// to use buffers by default.
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const EXTERN_APEX = 0xFBEE9;
// Manually controlled string for checking binary output
let ucs2_control = 'a\u0000';
// Grow the strings to proper length
while (ucs2_control.length <= EXTERN_APEX) {
ucs2_control = ucs2_control.repeat(2);
}
// Check resultant buffer and output string
const b = Buffer.from(ucs2_control + ucs2_control, 'ucs2');
//
// Test updating from birant data
//
{
const datum1 = b.slice(700000);
const hash1_converted = crypto.createHash('sha1')
.update(datum1.toString('base64'), 'base64')
.digest('hex');
const hash1_direct = crypto.createHash('sha1').update(datum1).digest('hex');
assert.strictEqual(hash1_direct, hash1_converted);
const datum2 = b;
const hash2_converted = crypto.createHash('sha1')
.update(datum2.toString('base64'), 'base64')
.digest('hex');
const hash2_direct = crypto.createHash('sha1').update(datum2).digest('hex');
assert.strictEqual(hash2_direct, hash2_converted);
}

View file

@ -0,0 +1,30 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// Test classic Diffie-Hellman key generation.
{
generateKeyPair('dh', {
primeLength: 512
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'dh');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'dh');
}));
}

View file

@ -0,0 +1,50 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// This test makes sure deprecated and new options may be used
// simultaneously so long as they're identical values.
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
saltLength: 16,
hash: 'sha256',
hashAlgorithm: 'sha256',
mgf1Hash: 'sha256',
mgf1HashAlgorithm: 'sha256'
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
});
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
});
}));
}

View file

@ -0,0 +1,36 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// Passing an empty passphrase string should not throw ERR_OSSL_CRYPTO_MALLOC_FAILURE even on OpenSSL 3.
// Regression test for https://github.com/nodejs/node/issues/41428.
generateKeyPair('rsa', {
modulusLength: 1024,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: ''
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert.strictEqual(typeof privateKey, 'string');
}));

View file

@ -0,0 +1,40 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPairSync,
} = require('crypto');
// Test sync key generation with key objects.
{
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
modulusLength: 512
});
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n
});
assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 65537n
});
}

View file

@ -0,0 +1,50 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
generateKeyPairSync,
getCurves,
} = require('crypto');
// This test creates EC key pairs on curves without associated OIDs.
// Specifying a key encoding should not crash.
{
if (process.versions.openssl >= '1.1.1i') {
for (const namedCurve of ['Oakley-EC2N-3', 'Oakley-EC2N-4']) {
if (!getCurves().includes(namedCurve))
continue;
const expectedErrorCode =
common.hasOpenSSL3 ? 'ERR_OSSL_MISSING_OID' : 'ERR_OSSL_EC_MISSING_OID';
const params = {
namedCurve,
publicKeyEncoding: {
format: 'der',
type: 'spki'
}
};
assert.throws(() => {
generateKeyPairSync('ec', params);
}, {
code: expectedErrorCode
});
generateKeyPair('ec', params, common.mustCall((err) => {
assert.strictEqual(err.code, expectedErrorCode);
}));
}
}
}

View file

@ -0,0 +1,42 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPairSync,
} = require('crypto');
// Test sync key generation with key objects with a non-standard
// publicExponent
{
const { publicKey, privateKey } = generateKeyPairSync('rsa', {
publicExponent: 3,
modulusLength: 512
});
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 3n
});
assert.strictEqual(typeof privateKey, 'object');
assert.strictEqual(privateKey.type, 'private');
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa');
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
modulusLength: 512,
publicExponent: 3n
});
}

View file

@ -0,0 +1,39 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// RFC 8017, 9.1.: "Assuming that the mask generation function is based on a
// hash function, it is RECOMMENDED that the hash function be the same as the
// one that is applied to the message."
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha256',
saltLength: 16
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha256',
mgf1HashAlgorithm: 'sha256',
saltLength: 16
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
}

View file

@ -0,0 +1,53 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const {
generateKeyPair,
} = require('crypto');
// RFC 8017, A.2.3.: "For a given hashAlgorithm, the default value of
// saltLength is the octet length of the hash value."
{
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha512'
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha512',
mgf1HashAlgorithm: 'sha512',
saltLength: 64
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
// It is still possible to explicitly set saltLength to 0.
generateKeyPair('rsa-pss', {
modulusLength: 512,
hashAlgorithm: 'sha512',
saltLength: 0
}, common.mustSucceed((publicKey, privateKey) => {
const expectedKeyDetails = {
modulusLength: 512,
publicExponent: 65537n,
hashAlgorithm: 'sha512',
mgf1HashAlgorithm: 'sha512',
saltLength: 0
};
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
}));
}

View file

@ -0,0 +1,43 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const Stream = require('stream');
const hasher1 = crypto.createHash('sha256');
const hasher2 = crypto.createHash('sha256');
// Calculate the expected result.
hasher1.write(Buffer.from('hello world'));
hasher1.end();
const expected = hasher1.read().toString('hex');
class OldStream extends Stream {
constructor() {
super();
this.readable = true;
}
}
const stream = new OldStream();
stream.pipe(hasher2).on('finish', common.mustCall(function() {
const hash = hasher2.read().toString('hex');
assert.strictEqual(hash, expected);
}));
stream.emit('data', Buffer.from('hello'));
stream.emit('data', Buffer.from(' world'));
stream.emit('end');

View file

@ -0,0 +1,45 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasOpenSSL3)
common.skip('this test requires OpenSSL 3.x');
const assert = require('node:assert/strict');
const crypto = require('node:crypto');
if (common.isMainThread) {
// TODO(richardlau): Decide if `crypto.setFips` should error if the
// provider named "fips" is not available.
crypto.setFips(1);
crypto.randomBytes(20, common.mustCall((err) => {
// crypto.randomBytes should either succeed or fail but not hang.
if (err) {
assert.match(err.message, /digital envelope routines::unsupported/);
const expected = /random number generator::unable to fetch drbg/;
assert(err.opensslErrorStack.some((msg) => expected.test(msg)),
`did not find ${expected} in ${err.opensslErrorStack}`);
}
}));
}
{
// Startup test. Should not hang.
const { path } = require('../common/fixtures');
const { spawnSync } = require('node:child_process');
const baseConf = path('openssl3-conf', 'base_only.cnf');
const cp = spawnSync(process.execPath,
[ `--openssl-config=${baseConf}`, '-p', '"hello"' ],
{ encoding: 'utf8' });
assert(common.nodeProcessAborted(cp.status, cp.signal),
`process did not abort, code:${cp.status} signal:${cp.signal}`);
}

View file

@ -0,0 +1,35 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const assert = require('assert');
const { generateKeyPair } = require('crypto');
if (common.isWindows) {
// Remove this conditional once the libuv change is in Node.js.
common.skip('crashing due to https://github.com/libuv/libuv/pull/2983');
}
// Regression test for a race condition: process.exit() might lead to OpenSSL
// cleaning up state from the exit() call via calling its destructor, but
// running OpenSSL operations on another thread might lead to them attempting
// to initialize OpenSSL, leading to a crash.
// This test crashed consistently on x64 Linux on Node v14.9.0.
generateKeyPair('rsa', {
modulusLength: 2048,
privateKeyEncoding: {
type: 'pkcs1',
format: 'pem'
}
}, (err/* , publicKey, privateKey */) => {
assert.ifError(err);
});
setTimeout(() => process.exit(), common.platformTimeout(10));

View file

@ -0,0 +1,67 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const iv = Buffer.from('00000000000000000000000000000000', 'hex');
const key = Buffer.from('0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef', 'hex');
function encrypt(val, pad) {
const c = crypto.createCipheriv('aes256', key, iv);
c.setAutoPadding(pad);
return c.update(val, 'utf8', 'latin1') + c.final('latin1');
}
function decrypt(val, pad) {
const c = crypto.createDecipheriv('aes256', key, iv);
c.setAutoPadding(pad);
return c.update(val, 'latin1', 'utf8') + c.final('utf8');
}
// echo 0123456789abcdef0123456789abcdef \
// | openssl enc -e -aes256 -nopad -K <key> -iv <iv> \
// | openssl enc -d -aes256 -nopad -K <key> -iv <iv>
let plaintext = '0123456789abcdef0123456789abcdef'; // Multiple of block size
let encrypted = encrypt(plaintext, false);
let decrypted = decrypt(encrypted, false);
assert.strictEqual(decrypted, plaintext);
// echo 0123456789abcdef0123456789abcde \
// | openssl enc -e -aes256 -K <key> -iv <iv> \
// | openssl enc -d -aes256 -K <key> -iv <iv>
plaintext = '0123456789abcdef0123456789abcde'; // not a multiple
encrypted = encrypt(plaintext, true);
decrypted = decrypt(encrypted, true);
assert.strictEqual(decrypted, plaintext);

View file

@ -0,0 +1,107 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
// Tests for CVE-2022-21449
// https://neilmadden.blog/2022/04/19/psychic-signatures-in-java/
// Dubbed "Psychic Signatures", these signatures bypassed the ECDSA signature
// verification implementation in Java in 15, 16, 17, and 18. OpenSSL is not
// (and was not) vulnerable so these are a precaution.
const vectors = {
'ieee-p1363': [
Buffer.from('0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
Buffer.from('ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 'hex'),
],
'der': [
Buffer.from('3046022100' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'022100' +
'0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
Buffer.from('3046022100' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551' +
'022100' +
'ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551', 'hex'),
],
};
const keyPair = crypto.generateKeyPairSync('ec', {
namedCurve: 'P-256',
publicKeyEncoding: {
format: 'der',
type: 'spki'
},
});
const data = Buffer.from('Hello!');
for (const [encoding, signatures] of Object.entries(vectors)) {
for (const signature of signatures) {
const key = {
key: keyPair.publicKey,
format: 'der',
type: 'spki',
dsaEncoding: encoding,
};
// one-shot sync
assert.strictEqual(
crypto.verify(
'sha256',
data,
key,
signature,
),
false,
);
// one-shot async
crypto.verify(
'sha256',
data,
key,
signature,
common.mustSucceed((verified) => assert.strictEqual(verified, false)),
);
// stream
assert.strictEqual(
crypto.createVerify('sha256')
.update(data)
.verify(key, signature),
false,
);
// webcrypto
globalThis.crypto.subtle.importKey(
'spki',
keyPair.publicKey,
{ name: 'ECDSA', namedCurve: 'P-256' },
false,
['verify'],
).then((publicKey) => {
return globalThis.crypto.subtle.verify(
{ name: 'ECDSA', hash: 'SHA-256' },
publicKey,
signature,
data,
);
}).then(common.mustCall((verified) => {
assert.strictEqual(verified, false);
}));
}
}

View file

@ -0,0 +1,48 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
// Test for https://github.com/nodejs/node/issues/40814
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.hasOpenSSL3)
common.skip('only openssl3'); // https://github.com/nodejs/node/pull/42793#issuecomment-1107491901
const assert = require('assert');
const crypto = require('crypto');
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-128-ecb',
passphrase: 'abcdef'
}
});
assert.notStrictEqual(privateKey.toString(), '');
const msg = 'The quick brown fox jumps over the lazy dog';
const encryptedString = crypto.privateEncrypt({
key: privateKey,
passphrase: 'abcdef'
}, Buffer.from(msg)).toString('base64');
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, 'base64')).toString();
console.log(`Encrypted: ${encryptedString}`);
console.log(`Decrypted: ${decryptedString}`);
assert.notStrictEqual(encryptedString, '');
assert.strictEqual(decryptedString, msg);

View file

@ -0,0 +1,25 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const { randomFillSync } = require('crypto');
const { notStrictEqual } = require('assert');
const ab = new ArrayBuffer(20);
const buf = Buffer.from(ab, 10);
const before = buf.toString('hex');
randomFillSync(buf);
const after = buf.toString('hex');
notStrictEqual(before, after);

View file

@ -0,0 +1,266 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const { internalBinding } = require('internal/test/binding');
if (typeof internalBinding('crypto').ScryptJob !== 'function')
common.skip('no scrypt support');
const good = [
// Zero-length key is legal, functions as a parameter validation check.
{
pass: '',
salt: '',
keylen: 0,
N: 16,
p: 1,
r: 1,
expected: '',
},
// Test vectors from https://tools.ietf.org/html/rfc7914#page-13 that
// should pass. Note that the test vector with N=1048576 is omitted
// because it takes too long to complete and uses over 1 GiB of memory.
{
pass: '',
salt: '',
keylen: 64,
N: 16,
p: 1,
r: 1,
expected:
'77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442' +
'fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906',
},
{
pass: 'password',
salt: 'NaCl',
keylen: 64,
N: 1024,
p: 16,
r: 8,
expected:
'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
'2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640',
},
{
pass: 'pleaseletmein',
salt: 'SodiumChloride',
keylen: 64,
N: 16384,
p: 1,
r: 8,
expected:
'7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2' +
'd5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887',
},
{
pass: '',
salt: '',
keylen: 64,
cost: 16,
parallelization: 1,
blockSize: 1,
expected:
'77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442' +
'fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906',
},
{
pass: 'password',
salt: 'NaCl',
keylen: 64,
cost: 1024,
parallelization: 16,
blockSize: 8,
expected:
'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' +
'2eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640',
},
{
pass: 'pleaseletmein',
salt: 'SodiumChloride',
keylen: 64,
cost: 16384,
parallelization: 1,
blockSize: 8,
expected:
'7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2' +
'd5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887',
},
];
// Test vectors that should fail.
const bad = [
{ N: 1, p: 1, r: 1 }, // N < 2
{ N: 3, p: 1, r: 1 }, // Not power of 2.
{ N: 1, cost: 1 }, // Both N and cost
{ p: 1, parallelization: 1 }, // Both p and parallelization
{ r: 1, blockSize: 1 }, // Both r and blocksize
];
// Test vectors where 128*N*r exceeds maxmem.
const toobig = [
{ N: 2 ** 16, p: 1, r: 1 }, // N >= 2**(r*16)
{ N: 2, p: 2 ** 30, r: 1 }, // p > (2**30-1)/r
{ N: 2 ** 20, p: 1, r: 8 },
{ N: 2 ** 10, p: 1, r: 8, maxmem: 2 ** 20 },
];
const badargs = [
{
args: [],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"password"/ },
},
{
args: [null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"password"/ },
},
{
args: [''],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"salt"/ },
},
{
args: ['', null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"salt"/ },
},
{
args: ['', ''],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"keylen"/ },
},
{
args: ['', '', null],
expected: { code: 'ERR_INVALID_ARG_TYPE', message: /"keylen"/ },
},
{
args: ['', '', .42],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', -42],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2 ** 31],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2147485780],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
{
args: ['', '', 2 ** 32],
expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ },
},
];
for (const options of good) {
const { pass, salt, keylen, expected } = options;
const actual = crypto.scryptSync(pass, salt, keylen, options);
assert.strictEqual(actual.toString('hex'), expected);
crypto.scrypt(pass, salt, keylen, options, common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), expected);
}));
}
for (const options of bad) {
const expected = {
message: /Invalid scrypt param/,
};
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
expected);
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
expected);
}
for (const options of toobig) {
const expected = {
message: /Invalid scrypt param/
};
assert.throws(() => crypto.scrypt('pass', 'salt', 1, options, () => {}),
expected);
assert.throws(() => crypto.scryptSync('pass', 'salt', 1, options),
expected);
}
{
const defaults = { N: 16384, p: 1, r: 8 };
const expected = crypto.scryptSync('pass', 'salt', 1, defaults);
const actual = crypto.scryptSync('pass', 'salt', 1);
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
crypto.scrypt('pass', 'salt', 1, common.mustSucceed((actual) => {
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
}));
}
for (const { args, expected } of badargs) {
assert.throws(() => crypto.scrypt(...args), expected);
assert.throws(() => crypto.scryptSync(...args), expected);
}
{
const expected = { code: 'ERR_INVALID_ARG_TYPE' };
assert.throws(() => crypto.scrypt('', '', 42, null), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}, null), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}), expected);
assert.throws(() => crypto.scrypt('', '', 42, {}, {}), expected);
}
{
// Values for maxmem that do not fit in 32 bits but that are still safe
// integers should be allowed.
crypto.scrypt('', '', 4, { maxmem: 2 ** 52 },
common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), 'd72c87d0');
}));
// Values that exceed Number.isSafeInteger should not be allowed.
assert.throws(() => crypto.scryptSync('', '', 0, { maxmem: 2 ** 53 }), {
code: 'ERR_OUT_OF_RANGE'
});
}
{
// Regression test for https://github.com/nodejs/node/issues/28836.
function testParameter(name, value) {
let accessCount = 0;
// Find out how often the value is accessed.
crypto.scryptSync('', '', 1, {
get [name]() {
accessCount++;
return value;
}
});
// Try to crash the process on the last access.
assert.throws(() => {
crypto.scryptSync('', '', 1, {
get [name]() {
if (--accessCount === 0)
return '';
return value;
}
});
}, {
code: 'ERR_INVALID_ARG_TYPE'
});
}
[
['N', 16384], ['cost', 16384],
['r', 8], ['blockSize', 8],
['p', 1], ['parallelization', 1],
].forEach((arg) => testParameter(...arg));
}

View file

@ -0,0 +1,46 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { subtle } = globalThis.crypto;
(async () => {
const k = await subtle.importKey(
'raw',
new Uint8Array(32),
{ name: 'AES-GCM' },
false,
[ 'encrypt', 'decrypt' ]);
assert(k instanceof CryptoKey);
const e = await subtle.encrypt({
name: 'AES-GCM',
iv: new Uint8Array(12),
}, k, new Uint8Array(0));
assert(e instanceof ArrayBuffer);
assert.deepStrictEqual(
Buffer.from(e),
Buffer.from([
0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b ]));
const v = await subtle.decrypt({
name: 'AES-GCM',
iv: new Uint8Array(12),
}, k, e);
assert(v instanceof ArrayBuffer);
assert.strictEqual(v.byteLength, 0);
})().then(common.mustCall()).catch((e) => {
assert.ifError(e);
});

View file

@ -0,0 +1,88 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
{
// IPv4 Test
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, common.localhostIPv4);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv4');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
});
socket.bind(0, common.localhostIPv4);
}
if (common.hasIPv6) {
// IPv6 Test
const socket = dgram.createSocket('udp6');
const localhost = '::1';
socket.on('listening', common.mustCall(() => {
const address = socket.address();
assert.strictEqual(address.address, localhost);
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
assert.strictEqual(address.family, 'IPv6');
socket.close();
}));
socket.on('error', (err) => {
socket.close();
assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
});
socket.bind(0, localhost);
}
{
// Verify that address() throws if the socket is not bound.
const socket = dgram.createSocket('udp4');
assert.throws(() => {
socket.address();
}, /^Error: getsockname EBADF$/);
}

View file

@ -0,0 +1,60 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
// Skip test in FreeBSD jails since 0.0.0.0 will resolve to default interface
if (common.inFreeBSDJail)
common.skip('In a FreeBSD jail');
const assert = require('assert');
const dgram = require('dgram');
dgram.createSocket('udp4').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
assert.strictEqual(this.address().address, '0.0.0.0');
this.close();
}));
if (!common.hasIPv6) {
common.printSkipMessage('udp6 part of test, because no IPv6 support');
return;
}
dgram.createSocket('udp6').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
let address = this.address().address;
if (address === '::ffff:0.0.0.0')
address = '::';
assert.strictEqual(address, '::');
this.close();
}));

View file

@ -0,0 +1,34 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const dgram = require('dgram');
// Regression test for https://github.com/nodejs/node/issues/30209
// No warning should be emitted when re-trying `.bind()` on UDP sockets
// repeatedly.
process.on('warning', common.mustNotCall());
const reservePortSocket = dgram.createSocket('udp4');
reservePortSocket.bind(() => {
const { port } = reservePortSocket.address();
const newSocket = dgram.createSocket('udp4');
let errors = 0;
newSocket.on('error', common.mustCall(() => {
if (++errors < 20) {
newSocket.bind(port, common.mustNotCall());
} else {
newSocket.close();
reservePortSocket.close();
}
}, 20));
newSocket.bind(port, common.mustNotCall());
});

View file

@ -0,0 +1,50 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.on('listening', common.mustCall(() => {
assert.throws(() => {
socket.bind();
}, {
code: 'ERR_SOCKET_ALREADY_BOUND',
name: 'Error',
message: /^Socket is already bound$/
});
socket.close();
}));
const result = socket.bind(); // Should not throw.
assert.strictEqual(result, socket); // Should have returned itself.

View file

@ -0,0 +1,46 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const assert = require('assert');
const dgram = require('dgram');
const message = Buffer.from('Some bytes');
const client = dgram.createSocket('udp4');
client.send(
message,
0,
message.length,
41234,
'localhost',
function(err, bytes) {
assert.strictEqual(bytes, message.length);
client.close();
}
);

View file

@ -0,0 +1,33 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// Ensure that if a dgram socket is closed before the sendQueue is drained
// will not crash
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
socket.on('listening', function() {
socket.close();
});
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
// Adds a listener to 'listening' to send the data when
// the socket is available
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
portGetter.close();
}));

View file

@ -0,0 +1,28 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const dgram = require('dgram');
const buf = Buffer.alloc(1024, 42);
const socket = dgram.createSocket('udp4');
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
// If close callback is not function, ignore the argument.
socket.close('bad argument');
portGetter.close();
socket.on('close', common.mustCall());
}));

View file

@ -0,0 +1,63 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// Flags: --expose-internals
'use strict';
// Ensure that if a dgram socket is closed before the DNS lookup completes, it
// won't crash.
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const { kStateSymbol } = require('internal/dgram');
const buf = Buffer.alloc(1024, 42);
let socket = dgram.createSocket('udp4');
const { handle } = socket[kStateSymbol];
// Get a random port for send
const portGetter = dgram.createSocket('udp4')
.bind(0, 'localhost', common.mustCall(() => {
socket.send(buf, 0, buf.length,
portGetter.address().port,
portGetter.address().address);
assert.strictEqual(socket.close(common.mustCall()), socket);
socket.on('close', common.mustCall());
socket = null;
// Verify that accessing handle after closure doesn't throw
setImmediate(function() {
setImmediate(function() {
console.log('Handle fd is: ', handle.fd);
});
});
portGetter.close();
}));

View file

@ -0,0 +1,30 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, offset, len, messageSent);
}));
}));

View file

@ -0,0 +1,27 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
client.bind(0, common.mustCall(() => {
client.connect(client.address().port, common.mustCall(() => {
client.send(buf, onMessage);
}));
}));

View file

@ -0,0 +1,36 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustCall((err, bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(() => {
const port = client.address().port;
client.connect(port, common.mustCall(() => {
client.send([buf1, buf2], messageSent);
}));
}));
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -0,0 +1,55 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const server = dgram.createSocket('udp4');
const toSend = [Buffer.alloc(256, 'x'),
Buffer.alloc(256, 'y'),
Buffer.alloc(256, 'z'),
'hello'];
const received = [];
server.on('listening', common.mustCall(() => {
const port = server.address().port;
client.connect(port, (err) => {
assert.ifError(err);
client.send(toSend[0], 0, toSend[0].length);
client.send(toSend[1]);
client.send([toSend[2]]);
client.send(toSend[3], 0, toSend[3].length);
client.send(new Uint8Array(toSend[0]), 0, toSend[0].length);
client.send(new Uint8Array(toSend[1]));
client.send([new Uint8Array(toSend[2])]);
client.send(new Uint8Array(Buffer.from(toSend[3])),
0, toSend[3].length);
});
}));
server.on('message', common.mustCall((buf, info) => {
received.push(buf.toString());
if (received.length === toSend.length * 2) {
// The replies may arrive out of order -> sort them before checking.
received.sort();
const expected = toSend.concat(toSend).map(String).sort();
assert.deepStrictEqual(received, expected);
client.close();
server.close();
}
}, toSend.length * 2));
server.bind(0);

View file

@ -0,0 +1,29 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.on('message', common.mustCall((buf, info) => {
const expected = Buffer.alloc(0);
assert.ok(buf.equals(expected), `Expected empty message but got ${buf}`);
client.close();
}));
client.on('listening', common.mustCall(() => {
client.connect(client.address().port,
common.localhostIPv4,
common.mustCall(() => client.send([])));
}));
client.bind(0);

View file

@ -0,0 +1,27 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
const port = this.address().port;
client.connect(port, common.mustCall(() => {
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.mustSucceed());
}));
client.on('message', common.mustCall((buffer) => {
assert.strictEqual(buffer.length, 0);
client.close();
}));
}));

View file

@ -0,0 +1,35 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
client.bind(0, common.mustCall(function() {
client.connect(client.address().port, common.mustCall(() => {
client.on('message', common.mustCall(callback));
const buf = Buffer.alloc(1);
const interval = setInterval(function() {
client.send(buf, 0, 0, common.mustCall(callback));
}, 10);
function callback(firstArg) {
// If client.send() callback, firstArg should be null.
// If client.on('message') listener, firstArg should be a 0-length buffer.
if (firstArg instanceof Buffer) {
assert.strictEqual(firstArg.length, 0);
clearInterval(interval);
client.close();
}
}
}));
}));

View file

@ -0,0 +1,36 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const onMessage = common.mustCall(common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
}));
const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', common.mustCall(function() {
const toSend = [buf1, buf2];
client.connect(client.address().port, common.mustCall(() => {
client.send(toSend, onMessage);
}));
}));
client.on('message', common.mustCall(function onMessage(buf, info) {
const expected = Buffer.concat([buf1, buf2]);
assert.ok(buf.equals(expected), 'message was received correctly');
client.close();
}));
client.bind(0);

View file

@ -0,0 +1,24 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const data = ['foo', 'bar', 'baz'];
socket.on('message', common.mustCall((msg, rinfo) => {
socket.close();
assert.deepStrictEqual(msg.toString(), data.join(''));
}));
socket.bind(0, () => {
socket.connect(socket.address().port, common.mustCall(() => {
socket.send(data);
}));
});

View file

@ -0,0 +1,73 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const PORT = 12345;
const client = dgram.createSocket('udp4');
client.connect(PORT, common.mustCall(() => {
const remoteAddr = client.remoteAddress();
assert.strictEqual(remoteAddr.port, PORT);
assert.throws(() => {
client.connect(PORT, common.mustNotCall());
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
client.disconnect();
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
assert.throws(() => {
client.remoteAddress();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
client.once('connect', common.mustCall(() => client.close()));
client.connect(PORT);
}));
assert.throws(() => {
client.connect(PORT);
}, {
name: 'Error',
message: 'Already connected',
code: 'ERR_SOCKET_DGRAM_IS_CONNECTED'
});
assert.throws(() => {
client.disconnect();
}, {
name: 'Error',
message: 'Not connected',
code: 'ERR_SOCKET_DGRAM_NOT_CONNECTED'
});
[ 0, null, 78960, undefined ].forEach((port) => {
assert.throws(() => {
client.connect(port);
}, {
name: 'RangeError',
message: /^Port should be > 0 and < 65536/,
code: 'ERR_SOCKET_BAD_PORT'
});
});

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