diff options
author | 2023-06-20 17:12:47 -0700 | |
---|---|---|
committer | 2023-06-20 17:12:47 -0700 | |
commit | 83d7ec728f073261176b0bea8451b936c5a376ad (patch) | |
tree | d7cd3c9343ee27bcc04211f8bb394189ed73e900 | |
parent | 9f301e13c5d8f057e6e9308e23cba7ecc27dab09 (diff) | |
download | bun-83d7ec728f073261176b0bea8451b936c5a376ad.tar.gz bun-83d7ec728f073261176b0bea8451b936c5a376ad.tar.zst bun-83d7ec728f073261176b0bea8451b936c5a376ad.zip |
Clone SourceOrigin string
-rw-r--r-- | src/bun.js/bindings/ZigSourceProvider.cpp | 5 | ||||
-rw-r--r-- | test/js/node/crypto/crypto.test.ts | 9 |
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"); |