Skip to content

feat(engine): include the value type in "not a constructor" errors - #5488

Open
ChrisJr404 wants to merge 1 commit into
boa-dev:mainfrom
ChrisJr404:not-a-constructor-value-type
Open

feat(engine): include the value type in "not a constructor" errors#5488
ChrisJr404 wants to merge 1 commit into
boa-dev:mainfrom
ChrisJr404:not-a-constructor-value-type

Conversation

@ChrisJr404

Copy link
Copy Markdown

This Pull Request closes #1760.

Summary

Right now every "not a constructor" TypeError uses the same bare message, so when you hit one it doesn't tell you anything about what went wrong. This adds the type of the value to the message and makes the wording consistent across the places that throw it.

So new 5() now throws "number is not a constructor", new undefined() throws "undefined is not a constructor", and new (() => {})() throws "function is not a constructor". This matches the style already used for the builtin messages like "Symbol is not a constructor".

Changes

  • The New and NewSpread opcodes prepend the operand's type_of when it isn't an object.
  • non_existent_construct reports "function" or "object" depending on whether the target is callable, which covers callable objects without a [[Construct]] slot (arrow functions, methods, etc.).
  • Updated the two existing tests that asserted the old message and added one covering the new type context.

I left the variable-name idea out for now since the name isn't reliably available at these throw sites, but the type is, and it's the part that's always useful.

@ChrisJr404
ChrisJr404 requested a review from a team as a code owner August 25, 2026 01:02
@github-actions github-actions Bot added Waiting On Review Waiting on reviews from the maintainers C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics C-VM Issues and PRs related to the Boa Virtual Machine. labels Aug 25, 2026
@github-actions github-actions Bot added this to the v1.0.0 milestone Aug 25, 2026
@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,125 53,125 0
Passed 51,073 51,073 0
Ignored 1,482 1,482 0
Failed 570 570 0
Panics 0 0 0
Conformance 96.14% 96.14% 0.00%

Tested main commit: 93a9e31a83bbaa15bbd8b687e61639ffc53bbef1
Tested PR commit: fb9084a36124b6b2e302f9e9777a5e38d716ecef
Compare commits: 93a9e31...fb9084a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add context information to not a constructor TypeError

1 participant