From 32e2540e56b5ae8392b10ecd75bbee2a3565674c Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Tue, 20 Jan 2026 19:08:00 +0000 Subject: [PATCH] fix(repl): use globalObject instead of globalThis for _ and _error variables The globalThis() method returns a JSGlobalProxy which doesn't expose properties set via putDirect to the global scope. By putting directly on globalObject instead, the _ and _error special REPL variables are now visible when referenced in subsequent expressions. Co-Authored-By: Claude Opus 4.5 --- src/bun.js/bindings/bindings.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 6f179049ae..ae96e56038 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -6141,23 +6141,24 @@ extern "C" JSC::EncodedJSValue Bun__REPL__evaluate( if (evalException) { *exception = JSC::JSValue::encode(evalException->value()); - // Set _error to the exception - globalObject->globalThis()->putDirect(vm, JSC::Identifier::fromString(vm, "_error"_s), evalException->value()); + // Set _error on the globalObject directly (not globalThis proxy) + globalObject->putDirect(vm, JSC::Identifier::fromString(vm, "_error"_s), evalException->value()); scope.clearException(); return JSC::JSValue::encode(JSC::jsUndefined()); } if (scope.exception()) { *exception = JSC::JSValue::encode(scope.exception()->value()); - // Set _error to the exception - globalObject->globalThis()->putDirect(vm, JSC::Identifier::fromString(vm, "_error"_s), scope.exception()->value()); + // Set _error on the globalObject directly (not globalThis proxy) + globalObject->putDirect(vm, JSC::Identifier::fromString(vm, "_error"_s), scope.exception()->value()); scope.clearException(); return JSC::JSValue::encode(JSC::jsUndefined()); } // Set _ to the last result (only if it's not undefined) + // Put directly on globalObject, which is the target of the globalThis proxy if (!result.isUndefined()) { - globalObject->globalThis()->putDirect(vm, JSC::Identifier::fromString(vm, "_"_s), result); + globalObject->putDirect(vm, JSC::Identifier::fromString(vm, "_"_s), result); } return JSC::JSValue::encode(result);