Skip to content

Conversation

@BinaryAlley
Copy link

Non-constructor methods and plain object methods were incorrectly treated as constructors when used with "new", resulting in a new Object instance instead of throwing a TypeError. Example:

// ok: class constructor
class OK { constructor() {} }
const ok = new OK();
new ok.constructor;

// should throw: instance method
class FAIL { m() {} }
const fail = new FAIL();
new fail.m;

// should throw: method on object literal
new ({ m() {} }).m;

// should throw: function expression used as object property
new ({ b: function () { this.x = 2; } }).b();

// should throw: extracted class method used with new
const m = class { m() {} }.prototype.m;
new m;

Fixes #6926

Non-constructor methods and plain object methods were incorrectly
treated as constructors when used with new, resulting in a new Object
instance instead of throwing a TypeError.
@gmta
Copy link
Collaborator

gmta commented Dec 8, 2025

Welcome! Can you add some of those examples to a regression test?

@BinaryAlley
Copy link
Author

Thank you! I'll attempt to do so.

@ladybird-bot
Copy link
Collaborator

Hello!

One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

@BinaryAlley BinaryAlley force-pushed the libjs-non-constructor-new-error branch from 6896004 to a03ccef Compare December 9, 2025 08:22
@github-actions github-actions bot added the conflicts Pull request has merge conflicts that need resolution label Dec 10, 2025
@github-actions
Copy link

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

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

Labels

conflicts Pull request has merge conflicts that need resolution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS: non-constructor-methods should not create a new object

3 participants