Skip to content

Consistency of prototype chain lookup for parameters #43401

@LiviaMedeiros

Description

@LiviaMedeiros

Version

v19.0.0-pre

Platform

any

Subsystem

lib

What steps will reproduce the bug?

import fs from 'node:fs/promises';

const DIR = '/tmp/issue43401';
const defaultDirOptions = { recursive: true };

async function run(dirOptions) {
  await fs.rm(DIR, { recursive: true, force: true });
  console.log('dirOptions.recursive:', dirOptions.recursive);
  try {
    await fs.mkdir(`${DIR}/1/2/3/4`, dirOptions);
    await fs.rm(DIR, dirOptions);
    await fs.stat(DIR);
  } catch(e) {
    console.error(e);
  }
}

await run({});
await run({ recursive: true });
await run(Object.create(defaultDirOptions));

run() tries to create nested directories, then remove them, then access topmost one.

  1. When ran with {}, mkdir must fail with ENOENT because it's not recursive.
  2. When ran with { recursive: true }, stat must fail with ENOENT because directory was deleted.

Depending on if we care that each property is "own", Object.create(defaultDirOptions) should behave either as (1) or as (2).

However, currently rm fails with EISDIR. So, mkdir is recursive but rm is not.

How often does it reproduce? Is there a required condition?

It depends on methods, it depends on version (pretty sure that some of these are changed within semver-patch level).

For some methods is might even depend on which property we access or on something even less related.

What is the expected behavior?

Consistency.

Or a warning somewhere, that only ownProperties are guaranteed to work.

Or an explicit agreement that it's UB "by design".

What do you see instead?

Inconsistency.

Additional information

In most cases, inherited properties are dropped by copying (e.g. { ...options }).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions