@@ -402,6 +402,34 @@ class JSI_EXPORT Runtime {
402
402
virtual std::u16string utf16 (const String& str);
403
403
virtual std::u16string utf16 (const PropNameID& sym);
404
404
405
+ // / Invokes the provided callback \p cb with the String content in \p str.
406
+ // / The callback must take in three arguments: bool ascii, const void* data,
407
+ // / and size_t num, respectively. \p ascii indicates whether the \p data
408
+ // / passed to the callback should be interpreted as a pointer to a sequence of
409
+ // / \p num ASCII characters or UTF16 characters. Depending on the internal
410
+ // / representation of the string, the function may invoke the callback
411
+ // / multiple times, with a different format on each invocation. The callback
412
+ // / must not access runtime functionality, as any operation on the runtime may
413
+ // / invalidate the data pointers.
414
+ virtual void getStringData (
415
+ const jsi::String& str,
416
+ void * ctx,
417
+ void (*cb)(void * ctx, bool ascii, const void * data, size_t num));
418
+
419
+ // / Invokes the provided callback \p cb with the PropNameID content in \p sym.
420
+ // / The callback must take in three arguments: bool ascii, const void* data,
421
+ // / and size_t num, respectively. \p ascii indicates whether the \p data
422
+ // / passed to the callback should be interpreted as a pointer to a sequence of
423
+ // / \p num ASCII characters or UTF16 characters. Depending on the internal
424
+ // / representation of the string, the function may invoke the callback
425
+ // / multiple times, with a different format on each invocation. The callback
426
+ // / must not access runtime functionality, as any operation on the runtime may
427
+ // / invalidate the data pointers.
428
+ virtual void getPropNameIdData (
429
+ const jsi::PropNameID& sym,
430
+ void * ctx,
431
+ void (*cb)(void * ctx, bool ascii, const void * data, size_t num));
432
+
405
433
// These exist so derived classes can access the private parts of
406
434
// Value, Symbol, String, and Object, which are all friends of Runtime.
407
435
template <typename T>
@@ -509,6 +537,22 @@ class JSI_EXPORT PropNameID : public Pointer {
509
537
return runtime.utf16 (*this );
510
538
}
511
539
540
+ // / Invokes the user provided callback to process the content in PropNameId.
541
+ // / The callback must take in three arguments: bool ascii, const void* data,
542
+ // / and size_t num, respectively. \p ascii indicates whether the \p data
543
+ // / passed to the callback should be interpreted as a pointer to a sequence of
544
+ // / \p num ASCII characters or UTF16 characters. The function may invoke the
545
+ // / callback multiple times, with a different format on each invocation. The
546
+ // / callback must not access runtime functionality, as any operation on the
547
+ // / runtime may invalidate the data pointers.
548
+ template <typename CB>
549
+ void getPropNameIdData (Runtime& runtime, CB& cb) const {
550
+ runtime.getPropNameIdData (
551
+ *this , &cb, [](void * ctx, bool ascii, const void * data, size_t num) {
552
+ (*((CB*)ctx))(ascii, data, num);
553
+ });
554
+ }
555
+
512
556
static bool compare (
513
557
Runtime& runtime,
514
558
const jsi::PropNameID& a,
@@ -664,6 +708,22 @@ class JSI_EXPORT String : public Pointer {
664
708
return runtime.utf16 (*this );
665
709
}
666
710
711
+ // / Invokes the user provided callback to process content in String. The
712
+ // / callback must take in three arguments: bool ascii, const void* data, and
713
+ // / size_t num, respectively. \p ascii indicates whether the \p data passed to
714
+ // / the callback should be interpreted as a pointer to a sequence of \p num
715
+ // / ASCII characters or UTF16 characters. The function may invoke the callback
716
+ // / multiple times, with a different format on each invocation. The callback
717
+ // / must not access runtime functionality, as any operation on the runtime may
718
+ // / invalidate the data pointers.
719
+ template <typename CB>
720
+ void getStringData (Runtime& runtime, CB& cb) const {
721
+ runtime.getStringData (
722
+ *this , &cb, [](void * ctx, bool ascii, const void * data, size_t num) {
723
+ (*((CB*)ctx))(ascii, data, num);
724
+ });
725
+ }
726
+
667
727
friend class Runtime ;
668
728
friend class Value ;
669
729
};
0 commit comments