Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e2c7e56a95169145b290ab99d7bf4bf0bfc9c744
      
https://github.com/WebKit/WebKit/commit/e2c7e56a95169145b290ab99d7bf4bf0bfc9c744
  Author: Sosuke Suzuki <[email protected]>
  Date:   2025-10-09 (Thu, 09 Oct 2025)

  Changed paths:
    M JSTests/stress/class-derived-from-null.js
    A JSTests/stress/derived-constructor-return-non-object.js
    M LayoutTests/js/class-syntax-extends-expected.txt
    M LayoutTests/js/script-tests/class-syntax-extends.js
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

  Log Message:
  -----------
  [JSC] Improve error messages for invalid constructor of derived classes
https://bugs.webkit.org/show_bug.cgi?id=300291

Reviewed by Yusuke Suzuki.

Returning non object values from constructor of derived class is invalid:

  class Base {}
  class Derived extends Base {
      constructor() {
          super();
          return 123;
      }
  }
  new Derived();

Current JSC throws a TypeError with the message "Cannot return a non-object
type in the constructor of a derived class."

This patch changes this error message to include the constructor name
for debugging experience.

Test: JSTests/stress/derived-constructor-return-non-object.js
* JSTests/stress/class-derived-from-null.js:
(test6):
* JSTests/stress/derived-constructor-return-non-object.js: Added.
(shouldThrow):
(throw.new.Error):
(throw.new.Error.DerivedReturningNumber):
(DerivedReturningString):
(new.DerivedReturningString.Base):
(new.DerivedReturningString.DerivedReturningBoolean):
(new.DerivedReturningString):
* LayoutTests/js/class-syntax-extends-expected.txt:
* LayoutTests/js/script-tests/class-syntax-extends.js:
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitReturn):

Canonical link: https://commits.webkit.org/301258@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to