Skip to content

Constructors of ES classes require new but the runtime doesn't check it #2919

Open
@teppeis

Description

@teppeis

In ES2015+, calling constructors of classes and builtin classes (Map, Set, WeakMap and WeakSet) without new throws TypeError.

Map(); // throws `TypeError`

https://www.ecma-international.org/ecma-262/6.0/#sec-map-iterable

In Closure Compiler ADVANCED mode, JSC_CONSTRUCTOR_NOT_CALLABLE warning is correctly thrown in compile time.
But in SIMPLE or WHITESPACE_ONLY mode, no warnings are detected in compile time and the runtime doesn't throw any errors.

Should the polyfill runtime of Closure Compiler for the constructors throw runtime error for SIMPLE and WHITESPACE_ONLY mode?

I will send a PR if necessary.

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