Fix issues with integer environment variables

This commit is contained in:
Jarred Sumner
2023-12-02 00:56:26 -08:00
parent 3760e5acd5
commit 1052e75910
3 changed files with 27 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;