diff --git a/src/bun.js/RuntimeTranspilerCache.zig b/src/bun.js/RuntimeTranspilerCache.zig index cee2ec7c33..512c9fb746 100644 --- a/src/bun.js/RuntimeTranspilerCache.zig +++ b/src/bun.js/RuntimeTranspilerCache.zig @@ -1,8 +1,10 @@ +// ** Update the version number when any breaking changes are made to the cache format or to the JS parser ** +const expected_version = 1; + const bun = @import("root").bun; const std = @import("std"); const Output = bun.Output; const JSC = bun.JSC; -const expected_version = 1; const debug = Output.scoped(.cache, false); const MINIMUM_CACHE_SIZE = 50 * 1024; diff --git a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp index abf794786c..b23eac87d0 100644 --- a/src/bun.js/bindings/JSEnvironmentVariableMap.cpp +++ b/src/bun.js/bindings/JSEnvironmentVariableMap.cpp @@ -135,7 +135,26 @@ JSValue createEnvironmentVariablesMap(Zig::GlobalObject* globalObject) hasTZ = true; continue; } - object->putDirectCustomAccessor(vm, Identifier::fromString(vm, name), JSC::CustomGetterSetter::create(vm, jsGetterEnvironmentVariable, jsSetterEnvironmentVariable), JSC::PropertyAttribute::CustomAccessor | 0); + ASSERT(len > 0); + + Identifier identifier = Identifier::fromString(vm, name); + + // CustomGetterSetter doesn't support indexed properties yet. + // This causes strange issues when the environment variable name is an integer. + if (UNLIKELY(chars[0] >= '0' && chars[0] <= '9')) { + if (auto index = parseIndex(identifier)) { + ZigString valueString = { nullptr, 0 }; + ZigString nameStr = toZigString(name); + JSValue value = jsUndefined(); + if (Bun__getEnvValue(globalObject, &nameStr, &valueString)) { + value = jsString(vm, Zig::toStringCopy(valueString)); + } + object->putDirectIndex(globalObject, *index, value, 0, PutDirectIndexLikePutDirect); + continue; + } + } + + object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, jsGetterEnvironmentVariable, jsSetterEnvironmentVariable), JSC::PropertyAttribute::CustomAccessor | 0); } unsigned int TZAttrs = JSC::PropertyAttribute::CustomAccessor | 0; diff --git a/src/js_parser.zig b/src/js_parser.zig index acd2201f0f..e25c4c109e 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -1,3 +1,7 @@ +/// ** IMPORTANT ** +/// ** When making changes to the JavaScript Parser that impact runtime behavior or fix bugs ** +/// ** you must also increment the `expected_version` in RuntimeTranspilerCache.zig ** +/// ** IMPORTANT ** pub const std = @import("std"); pub const logger = @import("root").bun.logger; pub const js_lexer = bun.js_lexer;