From a6cadce6f6292b685cc4160052304b5dfc8cd3ad Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:55:02 -0800 Subject: Fix process.env and Bun.env object spread Fixes https://github.com/oven-sh/bun/issues/1512 --- src/bun.js/bindings/ZigGlobalObject.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp') diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index d79048ea3..6d20a63d2 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2462,13 +2462,7 @@ void GlobalObject::finishCreation(VM& vm) m_processEnvObject.initLater( [](const JSC::LazyProperty::Initializer& init) { - auto jsClass = reinterpret_cast(init.owner)->m_dotEnvClassRef; - - JSC::JSCallbackObject* object = JSC::JSCallbackObject::create( - init.owner, init.owner->callbackObjectStructure(), jsClass, nullptr); - if (JSObject* prototype = jsClass->prototype(init.owner)) - object->setPrototypeDirect(init.vm, prototype); - init.set(object); + init.set(Bun::createEnvironmentVariablesMap(reinterpret_cast(init.owner)).getObject()); }); m_processObject.initLater( @@ -3175,6 +3169,16 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm JSC::PropertyAttribute::DontDelete | 0); } + { + + JSC::Identifier identifier = JSC::Identifier::fromString(vm, "env"_s); + object->putDirectCustomAccessor(vm, identifier, + JSC::CustomGetterSetter::create(vm, lazyProcessEnvGetter, lazyProcessEnvSetter), + JSC::PropertyAttribute::DontDelete + | JSC::PropertyAttribute::CustomValue + | 0); + } + { JSC::Identifier identifier = JSC::Identifier::fromString(vm, pathToFileURLString); -- cgit v1.2.3