aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/javascript/jsc/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/javascript/jsc/bindings/ZigGlobalObject.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
index 3717c85d4..3a7a8e72b 100644
--- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp
+++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
@@ -303,18 +303,17 @@ JSC_DEFINE_CUSTOM_GETTER(property_lazyProcessGetter,
JSC::PropertyName))
{
Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(_globalObject);
- if (LIKELY(globalObject->m_process))
- return JSValue::encode(JSC::JSValue(globalObject->m_process));
JSC::VM& vm = globalObject->vm();
+ auto clientData = Bun::clientData(vm);
+ JSC::JSValue processPrivate = globalObject->getIfPropertyExists(globalObject, clientData->builtinNames().processPrivateName());
+ if (LIKELY(processPrivate)) {
+ return JSC::JSValue::encode(processPrivate);
+ }
- globalObject->m_process = Zig::Process::create(
+ auto* process = Zig::Process::create(
vm, Zig::Process::createStructure(vm, globalObject, globalObject->objectPrototype()));
- // We must either:
- // - GC it and re-create it
- // - keep it alive forever
- // I think it is more correct to keep it alive forever
- JSC::gcProtect(globalObject->m_process);
+
{
auto jsClass = dot_env_class_ref;
@@ -323,14 +322,16 @@ JSC_DEFINE_CUSTOM_GETTER(property_lazyProcessGetter,
if (JSObject* prototype = jsClass->prototype(globalObject))
object->setPrototypeDirect(vm, prototype);
- globalObject->m_process->putDirect(vm, JSC::Identifier::fromString(vm, "env"),
+ process->putDirect(vm, JSC::Identifier::fromString(vm, "env"),
JSC::JSValue(object),
JSC::PropertyAttribute::DontDelete | 0);
JSC::gcProtect(JSC::JSValue(object));
}
+ globalObject->putDirect(vm, clientData->builtinNames().processPrivateName(), JSC::JSValue(process), 0);
+ JSC::gcProtect(JSC::JSValue(process));
- return JSC::JSValue::encode(JSC::JSValue(globalObject->m_process));
+ return JSC::JSValue::encode(JSC::JSValue(process));
}
static JSC_DECLARE_HOST_FUNCTION(functionQueueMicrotask);
@@ -697,7 +698,7 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count)
putDirectCustomAccessor(
vm(), clientData->builtinNames().processPublicName(),
JSC::CustomGetterSetter::create(vm(), property_lazyProcessGetter, property_lazyProcessSetter),
- JSC::PropertyAttribute::CustomValue | 0);
+ PropertyAttribute::DontDelete | JSC::PropertyAttribute::CustomAccessor | 0);
extraStaticGlobals.releaseBuffer();
}