@@ -1557,10 +1557,10 @@ void v8__base__SetDcheckFunction(void (*func)(const char*, int, const char*)) {
15571557
15581558// Utils
15591559
1560- struct CZigString {
1561- const char *ptr = nullptr ;
1562- uint64_t len = 0 ;
1563- };
1560+ extern " C " typedef struct {
1561+ const char *ptr;
1562+ uint64_t len;
1563+ } CZigString ;
15641564
15651565// / Header for Zig
15661566// / Allocates `bytes` bytes of memory using the allocator.
@@ -1594,34 +1594,20 @@ static inline std::string fromStringView(v8::Isolate* isolate, const v8_inspecto
15941594 return *result;
15951595}
15961596
1597- // / Allocates a string as utf8 on the heap, such that it can be returned to Zig.
1598- // / @param str: The string to return
1599- // / @param allocator: A Zig std.mem.Allocator
1600- // / @returns string pointer with null terminator, null if allocation failed
1601- const char * allocStringWith0 (const v8_inspector::String16& str, const void * allocator) {
1602- std::string utf8_str = str.utf8 (); // Note the data*'s lifetime is tied to utf8_str and this may hold the string data on the stack as an SSO, so we need to copy it onto the heap.
1603- char * heap_str = zigAlloc (allocator, utf8_str.length () + 1 ); // +1 for null terminator, needed to communicate the length to Zig
1604- if (heap_str == nullptr ) {
1605- return nullptr ;
1606- }
1607- strcpy (heap_str, utf8_str.c_str ());
1608- return heap_str;
1609- }
1610-
16111597// / Allocates a string as utf8 on the allocator without \0 terminator, for use in Zig.
16121598// / The strings pointer and length should therefore be returned together
1613- // / @param str : The string contents to allocate
1599+ // / @param input : The string contents to allocate
16141600// / @param allocator: A Zig std.mem.Allocator
1615- // / @param out : Points to the now allocated string on the heap (without sentinel \0), NULL if view was null, invalid if allocation failed
1601+ // / @param output : Points to the now allocated string on the heap (without sentinel \0), NULL if view was null, invalid if allocation failed
16161602// / @returns false if allocation errored
16171603bool allocString (const v8_inspector::StringView& input, const void * allocator, CZigString& output) {
1604+ output.ptr = nullptr ;
1605+ output.len = 0 ;
16181606 if (input.characters8 () == nullptr ) {
1619- output.ptr = nullptr ;
1620- output.len = 0 ;
16211607 return true ;
16221608 }
16231609
1624- std::string utf8_str; // Harmless if not used by 8bit string
1610+ std::string utf8_str;
16251611 if (input.is8Bit ()) {
16261612 output.len = input.length ();
16271613 } else {
@@ -1750,36 +1736,36 @@ void v8_inspector__RemoteObject__DELETE(v8_inspector::protocol::Runtime::RemoteO
17501736}
17511737
17521738// RemoteObject - Type
1753- const char * v8_inspector__RemoteObject__getType (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1739+ bool v8_inspector__RemoteObject__getType (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &out_type ) {
17541740 auto str = self->getType ();
1755- return allocStringWith0 ( str, allocator);
1741+ return allocString ( toStringView ( str) , allocator, out_type );
17561742}
1757- void v8_inspector__RemoteObject__setType (v8_inspector::protocol::Runtime::RemoteObject* self, const char * type, int type_len ) {
1758- self->setType (v8_inspector::String16::fromUTF8 (type, type_len ));
1743+ void v8_inspector__RemoteObject__setType (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString type) {
1744+ self->setType (v8_inspector::String16::fromUTF8 (type. ptr , type. len ));
17591745}
17601746
17611747// RemoteObject - Subtype
17621748bool v8_inspector__RemoteObject__hasSubtype (v8_inspector::protocol::Runtime::RemoteObject* self) {
17631749 return self->hasSubtype ();
17641750}
1765- const char * v8_inspector__RemoteObject__getSubtype (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1751+ bool v8_inspector__RemoteObject__getSubtype (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &subtype ) {
17661752 auto str = self->getSubtype (DEFAULT_STRING);
1767- return allocStringWith0 ( str, allocator);
1753+ return allocString ( toStringView ( str) , allocator, subtype );
17681754}
1769- void v8_inspector__RemoteObject__setSubtype (v8_inspector::protocol::Runtime::RemoteObject* self, const char * subtype, int subtype_len ) {
1770- self->setSubtype (v8_inspector::String16::fromUTF8 (subtype, subtype_len ));
1755+ void v8_inspector__RemoteObject__setSubtype (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString subtype) {
1756+ self->setSubtype (v8_inspector::String16::fromUTF8 (subtype. ptr , subtype. len ));
17711757}
17721758
17731759// RemoteObject - ClassName
17741760bool v8_inspector__RemoteObject__hasClassName (v8_inspector::protocol::Runtime::RemoteObject* self) {
17751761 return self->hasClassName ();
17761762}
1777- const char * v8_inspector__RemoteObject__getClassName (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1763+ bool v8_inspector__RemoteObject__getClassName (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &className ) {
17781764 auto str = self->getClassName (DEFAULT_STRING);
1779- return allocStringWith0 ( str, allocator);
1765+ return allocString ( toStringView ( str) , allocator, className );
17801766}
1781- void v8_inspector__RemoteObject__setClassName (v8_inspector::protocol::Runtime::RemoteObject* self, const char * className, int className_len ) {
1782- self->setClassName (v8_inspector::String16::fromUTF8 (className, className_len ));
1767+ void v8_inspector__RemoteObject__setClassName (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString className) {
1768+ self->setClassName (v8_inspector::String16::fromUTF8 (className. ptr , className. len ));
17831769}
17841770
17851771// RemoteObject - Value
@@ -1793,28 +1779,28 @@ void v8_inspector__RemoteObject__setValue(v8_inspector::protocol::Runtime::Remot
17931779 self->setValue (std::unique_ptr<v8_inspector::protocol::Value>(value));
17941780}
17951781
1796- // RemoteObject - UnserializableValue
1782+ // RemoteObject - UnserializableValue
17971783bool v8_inspector__RemoteObject__hasUnserializableValue (v8_inspector::protocol::Runtime::RemoteObject* self) {
17981784 return self->hasUnserializableValue ();
17991785}
1800- const char * v8_inspector__RemoteObject__getUnserializableValue (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1786+ bool v8_inspector__RemoteObject__getUnserializableValue (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &unserializableValue ) {
18011787 auto str = self->getUnserializableValue (DEFAULT_STRING);
1802- return allocStringWith0 ( str, allocator);
1788+ return allocString ( toStringView ( str) , allocator, unserializableValue );
18031789}
1804- void v8_inspector__RemoteObject__setUnserializableValue (v8_inspector::protocol::Runtime::RemoteObject* self, const char * unserializableValue, int unserializableValue_len ) {
1805- self->setUnserializableValue (v8_inspector::String16::fromUTF8 (unserializableValue, unserializableValue_len ));
1790+ void v8_inspector__RemoteObject__setUnserializableValue (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString unserializableValue) {
1791+ self->setUnserializableValue (v8_inspector::String16::fromUTF8 (unserializableValue. ptr , unserializableValue. len ));
18061792}
18071793
18081794// RemoteObject - Description
18091795bool v8_inspector__RemoteObject__hasDescription (v8_inspector::protocol::Runtime::RemoteObject* self) {
18101796 return self->hasDescription ();
18111797}
1812- const char * v8_inspector__RemoteObject__getDescription (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1798+ bool v8_inspector__RemoteObject__getDescription (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &description ) {
18131799 auto str = self->getDescription (DEFAULT_STRING);
1814- return allocStringWith0 ( str, allocator);
1800+ return allocString ( toStringView ( str) , allocator, description );
18151801}
1816- void v8_inspector__RemoteObject__setDescription (v8_inspector::protocol::Runtime::RemoteObject* self, const char * description, int description_len ) {
1817- self->setDescription (v8_inspector::String16::fromUTF8 (description, description_len ));
1802+ void v8_inspector__RemoteObject__setDescription (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString description) {
1803+ self->setDescription (v8_inspector::String16::fromUTF8 (description. ptr , description. len ));
18181804}
18191805
18201806// RemoteObject - WebDriverValue
@@ -1833,12 +1819,12 @@ bool v8_inspector__RemoteObject__hasObjectId(v8_inspector::protocol::Runtime::Re
18331819 return self->hasObjectId ();
18341820}
18351821
1836- const char * v8_inspector__RemoteObject__getObjectId (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator) {
1822+ bool v8_inspector__RemoteObject__getObjectId (v8_inspector::protocol::Runtime::RemoteObject* self, const void * allocator, CZigString &objectId ) {
18371823 auto str = self->getObjectId (DEFAULT_STRING);
1838- return allocStringWith0 ( str, allocator);
1824+ return allocString ( toStringView ( str) , allocator, objectId );
18391825}
1840- void v8_inspector__RemoteObject__setObjectId (v8_inspector::protocol::Runtime::RemoteObject* self, const char * objectId, int objectId_len ) {
1841- self->setObjectId (v8_inspector::String16::fromUTF8 (objectId, objectId_len ));
1826+ void v8_inspector__RemoteObject__setObjectId (v8_inspector::protocol::Runtime::RemoteObject* self, CZigString objectId) {
1827+ self->setObjectId (v8_inspector::String16::fromUTF8 (objectId. ptr , objectId. len ));
18421828}
18431829
18441830// RemoteObject - Preview
0 commit comments