aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/ZigSourceProvider.cpp5
-rw-r--r--test/js/node/crypto/crypto.test.ts9
2 files changed, 12 insertions, 2 deletions
diff --git a/src/bun.js/bindings/ZigSourceProvider.cpp b/src/bun.js/bindings/ZigSourceProvider.cpp
index d42d6b445..ab3062cd5 100644
--- a/src/bun.js/bindings/ZigSourceProvider.cpp
+++ b/src/bun.js/bindings/ZigSourceProvider.cpp
@@ -59,6 +59,7 @@ Ref<SourceProvider> SourceProvider::create(Zig::GlobalObject* globalObject, Reso
}
}
auto stringImpl = Bun::toWTFString(resolvedSource.source_code);
+ auto sourceURLString = toStringCopy(resolvedSource.source_url);
if (stringImpl.impl()->refCount() > 1)
// Deref because we don't call a destructor for BunString
@@ -67,8 +68,8 @@ Ref<SourceProvider> SourceProvider::create(Zig::GlobalObject* globalObject, Reso
auto provider = adoptRef(*new SourceProvider(
globalObject->isThreadLocalDefaultGlobalObject ? globalObject : nullptr,
resolvedSource, stringImpl.releaseImpl().releaseNonNull(),
- JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))),
- toStringNotConst(resolvedSource.source_url), TextPosition(),
+ JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(sourceURLString)),
+ sourceURLString.impl(), TextPosition(),
sourceType));
if (providerKey) {
diff --git a/test/js/node/crypto/crypto.test.ts b/test/js/node/crypto/crypto.test.ts
index d03940b9f..d8bfe5353 100644
--- a/test/js/node/crypto/crypto.test.ts
+++ b/test/js/node/crypto/crypto.test.ts
@@ -88,6 +88,15 @@ describe("CryptoHasher", () => {
expect(copy.digest("hex")).not.toBe(orig.digest("hex"));
});
+ it(`CryptoHasher ${alg} copy can be used after digest()`, () => {
+ const orig = new CryptoHasher(alg);
+ orig.update("hello");
+ orig.digest("hex");
+ const copy = orig.copy();
+
+ expect(() => copy.digest("hex")).not.toThrow();
+ });
+
it(`CryptoHasher ${alg} copy updates the same`, () => {
const orig = new CryptoHasher(alg);
orig.update("hello");