From cf5939c425ac72fef23448d0dcd68ae0aa59ef73 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 4 Jul 2022 08:42:29 -0700 Subject: [jsc] Make JSC own the memory for source code strings --- src/bun.js/bindings/ZigSourceProvider.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/bun.js/bindings/ZigSourceProvider.cpp') diff --git a/src/bun.js/bindings/ZigSourceProvider.cpp b/src/bun.js/bindings/ZigSourceProvider.cpp index 4e426b449..c2959a8fa 100644 --- a/src/bun.js/bindings/ZigSourceProvider.cpp +++ b/src/bun.js/bindings/ZigSourceProvider.cpp @@ -36,13 +36,23 @@ Ref SourceProvider::create(ResolvedSource resolvedSource) JSC::SourceProviderSourceType sourceType = JSC::SourceProviderSourceType::Module; + // JSC owns the memory + if (resolvedSource.hash == 1) { + Ref stringImpl_ = WTF::StringImpl::create(resolvedSource.source_code.ptr, resolvedSource.source_code.len); + return adoptRef(*new SourceProvider( + resolvedSource, WTFMove(stringImpl_), + JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), + toStringNotConst(resolvedSource.source_url), TextPosition(), + sourceType)); + } + if (allocator) { Ref stringImpl_ = WTF::ExternalStringImpl::create( resolvedSource.source_code.ptr, resolvedSource.source_code.len, allocator, RefString__free); return adoptRef(*new SourceProvider( - resolvedSource, stringImpl_, + resolvedSource, WTFMove(stringImpl_), JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), toStringNotConst(resolvedSource.source_url), TextPosition(), sourceType)); @@ -50,7 +60,7 @@ Ref SourceProvider::create(ResolvedSource resolvedSource) Ref stringImpl_ = WTF::ExternalStringImpl::createStatic( resolvedSource.source_code.ptr, resolvedSource.source_code.len); return adoptRef(*new SourceProvider( - resolvedSource, stringImpl_, + resolvedSource, WTFMove(stringImpl_), JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), toStringNotConst(resolvedSource.source_url), TextPosition(), sourceType)); -- cgit v1.2.3