diff options
author | 2023-07-09 22:36:24 -0700 | |
---|---|---|
committer | 2023-07-09 22:36:24 -0700 | |
commit | 963d4311e614ac197427104b9cf265bbe2a890af (patch) | |
tree | 4c912420b7ec13e5c2aabbbb51157a0cac0c98ca /src/bun.js/bindings/BunString.cpp | |
parent | 2f5e4fffe9554fcc7afa6980b3af6b33bc3a3a5e (diff) | |
download | bun-963d4311e614ac197427104b9cf265bbe2a890af.tar.gz bun-963d4311e614ac197427104b9cf265bbe2a890af.tar.zst bun-963d4311e614ac197427104b9cf265bbe2a890af.zip |
Fixes #3530 (#3587)
* Fixes #3530
* Handle OOM
* Add test
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/BunString.cpp')
-rw-r--r-- | src/bun.js/bindings/BunString.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bun.js/bindings/BunString.cpp b/src/bun.js/bindings/BunString.cpp index 4c8ff384e..21541d711 100644 --- a/src/bun.js/bindings/BunString.cpp +++ b/src/bun.js/bindings/BunString.cpp @@ -169,6 +169,29 @@ extern "C" JSC::EncodedJSValue BunString__toJS(JSC::JSGlobalObject* globalObject return JSValue::encode(Bun::toJS(globalObject, *bunString)); } +extern "C" BunString BunString__fromUTF16Unitialized(size_t length) +{ + unsigned utf16Length = length; + UChar* ptr; + auto impl = WTF::StringImpl::createUninitialized(utf16Length, ptr); + if (UNLIKELY(!ptr)) + return { BunStringTag::Dead }; + + impl->ref(); + return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } }; +} + +extern "C" BunString BunString__fromLatin1Unitialized(size_t length) +{ + unsigned latin1Length = length; + LChar* ptr; + auto impl = WTF::StringImpl::createUninitialized(latin1Length, ptr); + if (UNLIKELY(!ptr)) + return { BunStringTag::Dead }; + impl->ref(); + return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } }; +} + extern "C" BunString BunString__fromUTF8(const char* bytes, size_t length) { if (simdutf::validate_utf8(bytes, length)) { |