Skip to content

Is a function signature with a parameter type (DOMString or Interface) a footgun? #1604

Description

@saschanaz

What is the issue with the Web IDL Standard?

Context: https://bugzilla.mozilla.org/show_bug.cgi?id=2040944#c10, whatwg/fs#180

The File System PR adds this:

  Promise<undefined> move(USVString newEntryName);
  Promise<undefined> move(FileSystemDirectoryHandle destinationDirectory);
  Promise<undefined> move(FileSystemDirectoryHandle destinationDirectory, USVString newEntryName);

So .move("path as string") or .move(aDirectoryHandle). The problem happens with .move(aFileSystemFileHandle), because it's an interface instance but not a FileSystemDirectoryHandle, the parameter is silently eaten as a string, resulting [object FileSystemFileHandle] without any error.

Implicitly stringification has probably been always a footgun but this is even more footgun as you do expect either a string or a specific typed object here, any other object will cause a silent fire.

The suggested Gecko patch in the bug adds another signature to avoid this:

  // the only role of this signature ... is to throw an exception.
  Promise<undefined> move(FileSystemFileHandle aFileHandle);

I hate this, but can we do any better here?

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