Boa: Calling "new" on a primitive value does not throw an error

Created on 5 Oct 2020  路  2Comments  路  Source: boa-dev/boa

Describe the bug
Calling new on a primitive value (or, in other words, calling a primitive value as a constructor) does not error.

To Reproduce

const a = "";
new a();

Expected behavior
A TypeError is supposed to be raised. The spec can be found here (step 7). Chrome implements this properly:
image

Build environment (please complete the following information):

  • OS: Windows 10
  • Version: Version 1909 (OS Build 18363.1082)
  • Target triple: x86_64-pc-windows-msvc
  • Rustc version: rustc 1.46.0 (04488afe3 2020-08-24)

Additional context
MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
Spec: https://tc39.es/ecma262/#sec-evaluatenew

bug good first issue Hacktoberfest E-Easy execution

Most helpful comment

Hey @HalidOdat , I want to do this.
Thanks.

All 2 comments

The problem is here boa/src/syntax/ast/node/new/mod.rs:58 we should throw a TypeError (with .throw_type_error()), but instead we are returning undefined

Hey @HalidOdat , I want to do this.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings