Handle stack overflow in binary expressions in JS Parser (#7414)

* Fix stack overflow in large files

* Add test for stack overflow

* wip

* Disable cache in debug build

* Remove our extra `captureStackTrace` call

* Update RuntimeTranspilerCache.zig

* Update RuntimeTranspilerCache.zig

* Fix issues with integer environment variables

* Add missing ref

* Add missing null check

* Update bindings.cpp

* Update transpiler-cache.test.ts

* Add version check

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-12-02 12:46:25 +01:00
committed by GitHub
parent ffe447ba5a
commit b2bf3f0dcf
16 changed files with 815 additions and 491 deletions

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;