Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/jsc/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2431,16 +2431,19 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
RETURN_IF_EXCEPTION(scope, {});
}

header->putDirect(vm, JSC::Identifier::fromString(vm, "commandLine"_s), JSValue::decode(Bun__Process__createExecArgv(globalObject)), 0);
JSValue commandLine = JSValue::decode(Bun__Process__createExecArgv(globalObject));
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, JSC::Identifier::fromString(vm, "commandLine"_s), commandLine, 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "nodejsVersion"_s), JSC::jsString(vm, String::fromLatin1(REPORTED_NODEJS_VERSION)), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "wordSize"_s), JSC::jsNumber(64), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "arch"_s), constructArch(vm, header), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "platform"_s), constructPlatform(vm, header), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "componentVersions"_s), constructVersions(vm, header), 0);
JSValue componentVersions = constructVersions(vm, header);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, JSC::Identifier::fromString(vm, "release"_s), constructProcessReleaseObject(vm, header), 0);
header->putDirect(vm, JSC::Identifier::fromString(vm, "componentVersions"_s), componentVersions, 0);
JSValue release = constructProcessReleaseObject(vm, header);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, JSC::Identifier::fromString(vm, "release"_s), release, 0);

{
// uname
Expand Down Expand Up @@ -2474,10 +2477,12 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
#endif
#endif

header->putDirect(vm, Identifier::fromString(vm, "cpus"_s), JSC::constructEmptyArray(globalObject, nullptr), 0);
auto* cpusArray = JSC::constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, Identifier::fromString(vm, "networkInterfaces"_s), JSC::constructEmptyArray(globalObject, nullptr), 0);
header->putDirect(vm, Identifier::fromString(vm, "cpus"_s), cpusArray, 0);
auto* networkInterfacesArray = JSC::constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, Identifier::fromString(vm, "networkInterfaces"_s), networkInterfacesArray, 0);

return header;
};
Expand Down Expand Up @@ -2653,32 +2658,45 @@ static JSValue constructReportObjectComplete(VM& vm, Zig::GlobalObject* globalOb
JSC::JSObject* report = JSC::constructEmptyObject(globalObject, globalObject->objectPrototype(), 19);
RETURN_IF_EXCEPTION(scope, {});

report->putDirect(vm, JSC::Identifier::fromString(vm, "header"_s), constructHeader(), 0);
JSValue header = constructHeader();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "javascriptStack"_s), constructJavaScriptStack(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "header"_s), header, 0);
JSValue javascriptStack = constructJavaScriptStack();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "javascriptHeap"_s), constructJavaScriptHeap(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "javascriptStack"_s), javascriptStack, 0);
JSValue javascriptHeap = constructJavaScriptHeap();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "nativeStack"_s), constructNativeStack(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "javascriptHeap"_s), javascriptHeap, 0);
JSValue nativeStack = constructNativeStack();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "resourceUsage"_s), constructResourceUsage(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "nativeStack"_s), nativeStack, 0);
JSValue resourceUsage = constructResourceUsage();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "uvthreadResourceUsage"_s), constructUVThreadResourceUsage(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "resourceUsage"_s), resourceUsage, 0);
JSValue uvthreadResourceUsage = constructUVThreadResourceUsage();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "libuv"_s), constructLibUV(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "uvthreadResourceUsage"_s), uvthreadResourceUsage, 0);
JSValue libuv = constructLibUV();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "workers"_s), constructWorkers(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "libuv"_s), libuv, 0);
JSValue workers = constructWorkers();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "environmentVariables"_s), constructEnvironmentVariables(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "workers"_s), workers, 0);
JSValue environmentVariables = constructEnvironmentVariables();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "userLimits"_s), constructUserLimits(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "environmentVariables"_s), environmentVariables, 0);
JSValue userLimits = constructUserLimits();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "sharedObjects"_s), constructSharedObjects(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "userLimits"_s), userLimits, 0);
JSValue sharedObjects = constructSharedObjects();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "cpus"_s), constructCpus(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "sharedObjects"_s), sharedObjects, 0);
JSValue cpus = constructCpus();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "networkInterfaces"_s), constructNetworkInterfaces(), 0);
report->putDirect(vm, JSC::Identifier::fromString(vm, "cpus"_s), cpus, 0);
JSValue networkInterfaces = constructNetworkInterfaces();
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, JSC::Identifier::fromString(vm, "networkInterfaces"_s), networkInterfaces, 0);

return report;
}
Expand Down
20 changes: 14 additions & 6 deletions src/jsc/bindings/BunProcessReportObjectWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ JSValue constructReportObjectWindows(VM& vm, Zig::GlobalObject* globalObject, Pr
}

// Command line
header->putDirect(vm, Identifier::fromString(vm, "commandLine"_s), JSValue::decode(Bun__Process__createExecArgv(globalObject)), 0);
JSValue commandLine = JSValue::decode(Bun__Process__createExecArgv(globalObject));
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, Identifier::fromString(vm, "commandLine"_s), commandLine, 0);

// Node version
header->putDirect(vm, Identifier::fromString(vm, "nodejsVersion"_s), jsString(vm, String::fromLatin1(REPORTED_NODEJS_VERSION)), 0);
Expand Down Expand Up @@ -177,7 +178,9 @@ JSValue constructReportObjectWindows(VM& vm, Zig::GlobalObject* globalObject, Pr
}
header->putDirect(vm, Identifier::fromString(vm, "cpus"_s), cpuArray, 0);
} else {
header->putDirect(vm, Identifier::fromString(vm, "cpus"_s), constructEmptyArray(globalObject, nullptr), 0);
JSArray* emptyCpus = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, Identifier::fromString(vm, "cpus"_s), emptyCpus, 0);
}
RETURN_IF_EXCEPTION(scope, {});

Expand Down Expand Up @@ -231,7 +234,9 @@ JSValue constructReportObjectWindows(VM& vm, Zig::GlobalObject* globalObject, Pr
}
header->putDirect(vm, Identifier::fromString(vm, "networkInterfaces"_s), interfacesArray, 0);
} else {
header->putDirect(vm, Identifier::fromString(vm, "networkInterfaces"_s), constructEmptyArray(globalObject, nullptr), 0);
JSArray* emptyInterfaces = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
header->putDirect(vm, Identifier::fromString(vm, "networkInterfaces"_s), emptyInterfaces, 0);
}

report->putDirect(vm, Identifier::fromString(vm, "header"_s), header, 0);
Expand Down Expand Up @@ -384,16 +389,19 @@ JSValue constructReportObjectWindows(VM& vm, Zig::GlobalObject* globalObject, Pr
}

// Native stack (empty for now)
report->putDirect(vm, Identifier::fromString(vm, "nativeStack"_s), constructEmptyArray(globalObject, nullptr), 0);
JSArray* nativeStack = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, Identifier::fromString(vm, "nativeStack"_s), nativeStack, 0);

// libuv (empty for now)
report->putDirect(vm, Identifier::fromString(vm, "libuv"_s), constructEmptyArray(globalObject, nullptr), 0);
JSArray* libuvArray = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, Identifier::fromString(vm, "libuv"_s), libuvArray, 0);

// Workers (empty for now)
report->putDirect(vm, Identifier::fromString(vm, "workers"_s), constructEmptyArray(globalObject, nullptr), 0);
JSArray* workersArray = constructEmptyArray(globalObject, nullptr);
RETURN_IF_EXCEPTION(scope, {});
report->putDirect(vm, Identifier::fromString(vm, "workers"_s), workersArray, 0);

// Environment variables
report->putDirect(vm, Identifier::fromString(vm, "environmentVariables"_s), globalObject->processEnvObject(), 0);
Expand Down
5 changes: 4 additions & 1 deletion src/jsc/bindings/NodeVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ JSC_DEFINE_HOST_FUNCTION(jsNodeVmModuleGetModuleRequests, (JSC::JSGlobalObject *
RETURN_IF_EXCEPTION(scope, {});

for (unsigned i = 0; const NodeVMModuleRequest& request : requests) {
array->putDirectIndex(globalObject, i++, request.toJS(globalObject));
// toJS's RETURN_IF_EXCEPTION services VM traps, so termination can surface there as a null return.
auto* requestValue = request.toJS(globalObject);
RETURN_IF_EXCEPTION(scope, {});
array->putDirectIndex(globalObject, i++, requestValue);
RETURN_IF_EXCEPTION(scope, {});
}

Expand Down
15 changes: 7 additions & 8 deletions src/jsc/bindings/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,14 @@ JSC::JSValue createNodePathBinding(Zig::GlobalObject* globalObject)
auto scope = DECLARE_THROW_SCOPE(vm);
auto binding = constructEmptyArray(globalObject, nullptr, 2);
RETURN_IF_EXCEPTION(scope, {});
binding->putDirectIndex(
globalObject,
(unsigned)0,
Zig::createPath(globalObject, false));
// createPath's RETURN_IF_EXCEPTION services VM traps, so worker termination can surface there as a null return.
auto* posixPath = Zig::createPath(globalObject, false);
RETURN_IF_EXCEPTION(scope, {});
binding->putDirectIndex(
globalObject,
(unsigned)1,
Zig::createPath(globalObject, true));
binding->putDirectIndex(globalObject, (unsigned)0, posixPath);
RETURN_IF_EXCEPTION(scope, {});
auto* windowsPath = Zig::createPath(globalObject, true);
RETURN_IF_EXCEPTION(scope, {});
binding->putDirectIndex(globalObject, (unsigned)1, windowsPath);
RETURN_IF_EXCEPTION(scope, {});
Comment thread
robobun marked this conversation as resolved.
return binding;
}
Expand Down
2 changes: 2 additions & 0 deletions src/jsc/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5179,12 +5179,14 @@ void JSC__VM__ensureTerminationExceptionPending(JSC::VM* arg0)
JSC::VM& vm = *arg0;
if (vm.hasPendingTerminationException())
return;
auto scope = DECLARE_TOP_EXCEPTION_SCOPE(vm);
if (!vm.hasTerminationRequest() && !vm.traps().needHandling(JSC::VMTraps::NeedTermination))
vm.notifyNeedTermination();
if (vm.hasTerminationRequest())
vm.throwTerminationException();
else
vm.traps().handleTraps(JSC::VMTraps::NeedTermination);
scope.releaseAssertNoExceptionExceptTermination();
}

// These may be called concurrently from another thread.
Expand Down
Loading