aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigSourceProvider.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-04 08:42:29 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-04 08:42:29 -0700
commitcf5939c425ac72fef23448d0dcd68ae0aa59ef73 (patch)
tree14043a0c10db5530179fcd2c9ea1bba0d3ad91cc /src/bun.js/bindings/ZigSourceProvider.cpp
parentbbcc08dbb44dd28f7141e6f50a7cb5edfb8b4987 (diff)
downloadbun-cf5939c425ac72fef23448d0dcd68ae0aa59ef73.tar.gz
bun-cf5939c425ac72fef23448d0dcd68ae0aa59ef73.tar.zst
bun-cf5939c425ac72fef23448d0dcd68ae0aa59ef73.zip
[jsc] Make JSC own the memory for source code strings
Diffstat (limited to 'src/bun.js/bindings/ZigSourceProvider.cpp')
-rw-r--r--src/bun.js/bindings/ZigSourceProvider.cpp14
1 files changed, 12 insertions, 2 deletions
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> SourceProvider::create(ResolvedSource resolvedSource)
JSC::SourceProviderSourceType sourceType = JSC::SourceProviderSourceType::Module;
+ // JSC owns the memory
+ if (resolvedSource.hash == 1) {
+ Ref<WTF::StringImpl> 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<WTF::ExternalStringImpl> 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> SourceProvider::create(ResolvedSource resolvedSource)
Ref<WTF::ExternalStringImpl> 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));