mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { dirname } from "node:path";
|
||||
import { gc } from "harness";
|
||||
import { bunEnv, bunExe, gc } from "harness";
|
||||
import fs, {
|
||||
closeSync,
|
||||
existsSync,
|
||||
@@ -42,6 +42,7 @@ import { join } from "node:path";
|
||||
|
||||
import { ReadStream as ReadStream_, WriteStream as WriteStream_ } from "./export-from.js";
|
||||
import { ReadStream as ReadStreamStar_, WriteStream as WriteStreamStar_ } from "./export-star-from.js";
|
||||
import { spawnSync } from "bun";
|
||||
|
||||
const Buffer = globalThis.Buffer || Uint8Array;
|
||||
|
||||
@@ -67,6 +68,15 @@ it("writeFileSync in append should not truncate the file", () => {
|
||||
expect(readFileSync(path, "utf8")).toBe(str);
|
||||
});
|
||||
|
||||
it("await readdir #3931", async () => {
|
||||
const { exitCode } = spawnSync({
|
||||
cmd: [bunExe(), join(import.meta.dir, "./repro-3931.js")],
|
||||
env: bunEnv,
|
||||
cwd: import.meta.dir,
|
||||
});
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
|
||||
it("writeFileSync NOT in append SHOULD truncate the file", () => {
|
||||
const path = join(tmpdir(), "writeFileSync-should-not-append-" + (Date.now() * 10000).toString(16));
|
||||
|
||||
|
||||
4
test/js/node/fs/repro-3931.js
Normal file
4
test/js/node/fs/repro-3931.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { readdir } from "fs/promises";
|
||||
|
||||
const files = await readdir(`/tmp`, {});
|
||||
console.log(files.map(a => a));
|
||||
Reference in New Issue
Block a user