diff options
author | 2023-07-10 21:12:00 +0800 | |
---|---|---|
committer | 2023-07-10 21:12:00 +0800 | |
commit | cc0d9200187de8d405dffcdb23c588e182ceccef (patch) | |
tree | c5fbccb010297f763f2a8bb697c2ab4282a98447 /src/bun.js/bindings/BunString.cpp | |
parent | 438d54f1869a11a7219f6e93c3bb05f6c52ee27b (diff) | |
parent | ec1117031197dbce434473492c85bb2654a91248 (diff) | |
download | bun-cc0d9200187de8d405dffcdb23c588e182ceccef.tar.gz bun-cc0d9200187de8d405dffcdb23c588e182ceccef.tar.zst bun-cc0d9200187de8d405dffcdb23c588e182ceccef.zip |
Merge branch 'main' into fix-http
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)) { |