From c7d16d2ed51afd12581ac4a60435ad202d01a8d9 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 15 Feb 2023 02:51:44 -0800 Subject: ensure we allocate for > 6 arguments --- src/bun.js/bindings/napi.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/bun.js/bindings/napi.cpp') diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index ecae69427..bebdd5134 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -1185,9 +1185,20 @@ static JSC_DEFINE_HOST_FUNCTION(NapiClass_ConstructorFunction, RETURN_IF_EXCEPTION(scope, {}); + size_t count = callFrame->argumentCount(); + MarkedArgumentBuffer args; + + if (count > 6) { + for (size_t i = 6; i < count; i++) { + args.append(callFrame->uncheckedArgument(i)); + } + } + callFrame->setThisValue(prototype->subclass(newTarget)); napi->constructor()(globalObject, callFrame); - size_t count = callFrame->argumentCount(); + RETURN_IF_EXCEPTION(scope, {}); + + JSC::JSValue thisValue = callFrame->thisValue(); switch (count) { case 0: { @@ -1230,15 +1241,11 @@ static JSC_DEFINE_HOST_FUNCTION(NapiClass_ConstructorFunction, JSC::ensureStillAliveHere(callFrame->argument(3)); JSC::ensureStillAliveHere(callFrame->argument(4)); JSC::ensureStillAliveHere(callFrame->argument(5)); - for (int i = 6; i < count; i++) { - JSC::ensureStillAliveHere(callFrame->argument(i)); - } break; } } - RETURN_IF_EXCEPTION(scope, {}); - RELEASE_AND_RETURN(scope, JSValue::encode(callFrame->thisValue())); + RELEASE_AND_RETURN(scope, JSValue::encode(thisValue)); } NapiClass* NapiClass::create(VM& vm, Zig::GlobalObject* globalObject, const char* utf8name, -- cgit v1.2.3