From ef65f3c305e989bd7d7fe6f0e73822bdbe0e91dd Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 11 Jun 2023 05:26:37 -0700 Subject: Support using `WTF::StringImpl` from Zig (#3279) * Fix `make headers` * [JS parser] Fix bug with printing non-ascii import paths in ascii mode * Introduce `bun.String` * Add test for non-ascii imports & entry points * Add comment * Fix build issue * Support HTTP server * Make it print the same --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/bindings/helpers.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/bun.js/bindings/helpers.h') diff --git a/src/bun.js/bindings/helpers.h b/src/bun.js/bindings/helpers.h index 8a96a94af..402807f3d 100644 --- a/src/bun.js/bindings/helpers.h +++ b/src/bun.js/bindings/helpers.h @@ -84,7 +84,7 @@ namespace Zig { static const unsigned char* untag(const unsigned char* ptr) { return reinterpret_cast( - ((reinterpret_cast(ptr) & ~(static_cast(1) << 63) & ~(static_cast(1) << 62)) & ~(static_cast(1) << 61))); + (((reinterpret_cast(ptr) & ~(static_cast(1) << 63) & ~(static_cast(1) << 62)) & ~(static_cast(1) << 61)) & ~(static_cast(1) << 60))); } static void* untagVoid(const unsigned char* ptr) @@ -245,6 +245,8 @@ static const JSC::JSValue toJSStringValueGC(ZigString str, JSC::JSGlobalObject* static const ZigString ZigStringEmpty = ZigString { nullptr, 0 }; static const unsigned char __dot_char = '.'; static const ZigString ZigStringCwd = ZigString { &__dot_char, 1 }; +static const BunString BunStringCwd = BunString { BunStringTag::StaticZigString, ZigStringCwd }; +static const BunString BunStringEmpty = BunString { BunStringTag::Empty, nullptr }; static const unsigned char* taggedUTF16Ptr(const UChar* ptr) { @@ -330,6 +332,23 @@ static ZigString toZigString(JSC::JSValue val, JSC::JSGlobalObject* global) return toZigString(str); } +static const WTF::String toStringStatic(ZigString str) +{ + if (str.len == 0 || str.ptr == nullptr) { + return WTF::String(); + } + if (UNLIKELY(isTaggedUTF8Ptr(str.ptr))) { + abort(); + } + + if (isTaggedUTF16Ptr(str.ptr)) { + return WTF::String(WTF::ExternalStringImpl::createStatic(reinterpret_cast(untag(str.ptr)), str.len)); + } + + return WTF::String(WTF::ExternalStringImpl::createStatic( + reinterpret_cast(untag(str.ptr)), str.len)); +} + static JSC::JSValue getErrorInstance(const ZigString* str, JSC__JSGlobalObject* globalObject) { JSC::VM& vm = globalObject->vm(); -- cgit v1.2.3