more child-process (#18688)

Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
This commit is contained in:
pfg
2025-05-06 22:12:24 -07:00
committed by GitHub
parent d291b56f8b
commit 00a3cbd977
70 changed files with 2990 additions and 917 deletions

View File

@@ -141,6 +141,7 @@ extern "C" uint8_t Bun__getExitCode(void*);
extern "C" uint8_t Bun__setExitCode(void*, uint8_t);
extern "C" bool Bun__closeChildIPC(JSGlobalObject*);
extern "C" bool Bun__GlobalObject__connectedIPC(JSGlobalObject*);
extern "C" bool Bun__GlobalObject__hasIPC(JSGlobalObject*);
extern "C" bool Bun__ensureProcessIPCInitialized(JSGlobalObject*);
extern "C" const char* Bun__githubURL;
@@ -1460,7 +1461,7 @@ JSC_DEFINE_CUSTOM_GETTER(processConnected, (JSC::JSGlobalObject * lexicalGlobalO
return JSValue::encode(jsUndefined());
}
return JSValue::encode(jsBoolean(Bun__GlobalObject__hasIPC(process->globalObject())));
return JSValue::encode(jsBoolean(Bun__GlobalObject__connectedIPC(process->globalObject())));
}
JSC_DEFINE_CUSTOM_SETTER(setProcessConnected, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue value, JSC::PropertyName))
{
@@ -2274,26 +2275,16 @@ static JSValue constructProcessSend(VM& vm, JSObject* processObject)
}
}
JSC_DEFINE_HOST_FUNCTION(processDisonnectFinish, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
Bun__closeChildIPC(globalObject);
return JSC::JSValue::encode(jsUndefined());
}
JSC_DEFINE_HOST_FUNCTION(Bun__Process__disconnect, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = JSC::getVM(globalObject);
auto global = jsCast<GlobalObject*>(globalObject);
if (!Bun__GlobalObject__hasIPC(globalObject)) {
if (!Bun__GlobalObject__connectedIPC(globalObject)) {
Process__emitErrorEvent(global, JSValue::encode(createError(globalObject, ErrorCode::ERR_IPC_DISCONNECTED, "IPC channel is already disconnected"_s)));
return JSC::JSValue::encode(jsUndefined());
}
auto finishFn = JSC::JSFunction::create(vm, globalObject, 0, String("finish"_s), processDisonnectFinish, ImplementationVisibility::Public);
auto process = jsCast<Process*>(global->processObject());
process->queueNextTick(globalObject, finishFn);
Bun__closeChildIPC(globalObject);
return JSC::JSValue::encode(jsUndefined());
}
@@ -3618,7 +3609,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionLoadBuiltinModule, (JSGlobalObject * gl
RELEASE_AND_RETURN(scope, JSValue::encode(jsUndefined()));
}
extern "C" void Process__emitMessageEvent(Zig::GlobalObject* global, EncodedJSValue value)
extern "C" void Process__emitMessageEvent(Zig::GlobalObject* global, EncodedJSValue value, EncodedJSValue handle)
{
auto* process = static_cast<Process*>(global->processObject());
auto& vm = JSC::getVM(global);
@@ -3627,6 +3618,7 @@ extern "C" void Process__emitMessageEvent(Zig::GlobalObject* global, EncodedJSVa
if (process->wrapped().hasEventListeners(ident)) {
JSC::MarkedArgumentBuffer args;
args.append(JSValue::decode(value));
args.append(JSValue::decode(handle));
process->wrapped().emit(ident, args);
}
}