* throw an error when `Script` is called without new

fix https://github.com/oven-sh/bun/issues/6281

* fix typo in `File` without constructor error

fix https://github.com/oven-sh/bun/issues/6281
This commit is contained in:
Kerem Kat
2023-10-31 06:05:32 +00:00
committed by GitHub
parent e259056bd8
commit 715be35764
4 changed files with 22 additions and 1 deletions

View File

@@ -111,6 +111,11 @@ constructScript(JSGlobalObject* globalObject, CallFrame* callFrame, JSValue newT
if (UNLIKELY(zigGlobalObject->NodeVMScript() != newTarget)) {
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* targetObj = asObject(newTarget);
if (targetObj == nullptr) {
throwTypeError(globalObject, scope, "Class constructor Script cannot be invoked without 'new'"_s);
return {};
}
auto* functionGlobalObject = reinterpret_cast<Zig::GlobalObject*>(getFunctionRealm(globalObject, targetObj));
RETURN_IF_EXCEPTION(scope, {});
structure = InternalFunction::createSubclassStructure(