mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
more child-process (#18688)
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user