aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/helpers.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-06-11 05:26:37 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-11 05:26:37 -0700
commitef65f3c305e989bd7d7fe6f0e73822bdbe0e91dd (patch)
tree208a5f55d885c95afe40366bbe7b0e6d4c5f7859 /src/bun.js/bindings/helpers.h
parent02eafd5019150357012ebb7a39f1c264ba73599e (diff)
downloadbun-ef65f3c305e989bd7d7fe6f0e73822bdbe0e91dd.tar.gz
bun-ef65f3c305e989bd7d7fe6f0e73822bdbe0e91dd.tar.zst
bun-ef65f3c305e989bd7d7fe6f0e73822bdbe0e91dd.zip
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>
Diffstat (limited to 'src/bun.js/bindings/helpers.h')
-rw-r--r--src/bun.js/bindings/helpers.h21
1 files changed, 20 insertions, 1 deletions
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<const unsigned char*>(
- ((reinterpret_cast<uintptr_t>(ptr) & ~(static_cast<uint64_t>(1) << 63) & ~(static_cast<uint64_t>(1) << 62)) & ~(static_cast<uint64_t>(1) << 61)));
+ (((reinterpret_cast<uintptr_t>(ptr) & ~(static_cast<uint64_t>(1) << 63) & ~(static_cast<uint64_t>(1) << 62)) & ~(static_cast<uint64_t>(1) << 61)) & ~(static_cast<uint64_t>(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<const UChar*>(untag(str.ptr)), str.len));
+ }
+
+ return WTF::String(WTF::ExternalStringImpl::createStatic(
+ reinterpret_cast<const LChar*>(untag(str.ptr)), str.len));
+}
+
static JSC::JSValue getErrorInstance(const ZigString* str, JSC__JSGlobalObject* globalObject)
{
JSC::VM& vm = globalObject->vm();