aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/BunString.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-08-02 16:16:22 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-02 16:16:22 -0700
commit7656b4b17e91f15b58eeab8f45b78c416ec6a045 (patch)
treee9dceff8d8db52855f11431f5011949dc0bf8ea5 /src/bun.js/bindings/BunString.cpp
parent25553e62c1cb8151c901f2e09ccb1a71f6a1e7bd (diff)
downloadbun-7656b4b17e91f15b58eeab8f45b78c416ec6a045.tar.gz
bun-7656b4b17e91f15b58eeab8f45b78c416ec6a045.tar.zst
bun-7656b4b17e91f15b58eeab8f45b78c416ec6a045.zip
Fixes #3931 (#3933)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/BunString.cpp')
-rw-r--r--src/bun.js/bindings/BunString.cpp46
1 files changed, 9 insertions, 37 deletions
diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp
index 7864ee94e..630d9be76 100644
--- a/src/bun.js/bindings/BunString.cpp
+++ b/src/bun.js/bindings/BunString.cpp
@@ -267,47 +267,19 @@ extern "C" EncodedJSValue BunString__createArray(
auto& vm = globalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
- if (length < 64) {
- // We must do this or Bun.gc(true) in a loop creating large arrays of strings will crash due to GC'ing.
- MarkedArgumentBuffer arguments;
-
- arguments.fill(length, [&](JSC::JSValue* value) {
- const BunString* end = ptr + length;
- while (ptr != end) {
- *value++ = Bun::toJS(globalObject, *ptr++);
- }
- });
-
- JSC::ObjectInitializationScope scope(vm);
- GCDeferralContext context(vm);
-
- JSC::JSArray* array = JSC::JSArray::tryCreateUninitializedRestricted(
- scope,
- globalObject->arrayStructureForIndexingTypeDuringAllocation(JSC::ArrayWithContiguous),
- length);
-
- if (array) {
- for (size_t i = 0; i < length; ++i) {
- array->initializeIndex(scope, i, arguments.at(i));
- }
- return JSValue::encode(array);
- }
-
+ // Using tryCreateUninitialized here breaks stuff..
+ // https://github.com/oven-sh/bun/issues/3931
+ JSC::JSArray* array = constructEmptyArray(globalObject, nullptr, length);
+ if (!array) {
JSC::throwOutOfMemoryError(globalObject, throwScope);
RELEASE_AND_RETURN(throwScope, JSValue::encode(JSC::JSValue()));
- } else {
- JSC::JSArray* array = constructEmptyArray(globalObject, nullptr, length);
- if (!array) {
- JSC::throwOutOfMemoryError(globalObject, throwScope);
- RELEASE_AND_RETURN(throwScope, JSValue::encode(JSC::JSValue()));
- }
-
- for (size_t i = 0; i < length; ++i) {
- array->putDirectIndex(globalObject, i, Bun::toJS(globalObject, *ptr++));
- }
+ }
- return JSValue::encode(array);
+ for (size_t i = 0; i < length; ++i) {
+ array->putDirectIndex(globalObject, i, Bun::toJS(globalObject, *ptr++));
}
+
+ return JSValue::encode(array);
}
extern "C" void BunString__toWTFString(BunString* bunString)