Add StringPrimitive::create for UTF8 strings

Summary:
This is pre-work for adding the v8 stack trace API support.

Changelog: [Internal]

Reviewed By: kodafb

Differential Revision: D34048366

fbshipit-source-id: 9d2b469767f7669cb428c61b215f193894892c03
This commit is contained in:
John Porto 2022-02-10 04:57:09 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 159eb0bdf4
Коммит b467094f18
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -406,6 +406,7 @@ class JSI_EXPORT PropNameID : public Pointer {
}
/// Create a PropNameID from utf8 values. The data is copied.
/// Results are undefined if \p utf8 contains invalid code points.
static PropNameID
forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
return runtime.createPropNameIDFromUtf8(utf8, length);
@ -413,6 +414,7 @@ class JSI_EXPORT PropNameID : public Pointer {
/// Create a PropNameID from utf8-encoded octets stored in a
/// std::string. The string data is transformed and copied.
/// Results are undefined if \p utf8 contains invalid code points.
static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) {
return runtime.createPropNameIDFromUtf8(
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
@ -502,14 +504,16 @@ class JSI_EXPORT String : public Pointer {
}
/// Create a JS string from utf8-encoded octets. The string data is
/// transformed and copied.
/// transformed and copied. Results are undefined if \p utf8 contains invalid
/// code points.
static String
createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
return runtime.createStringFromUtf8(utf8, length);
}
/// Create a JS string from utf8-encoded octets stored in a
/// std::string. The string data is transformed and copied.
/// std::string. The string data is transformed and copied. Results are
/// undefined if \p utf8 contains invalid code points.
static String createFromUtf8(Runtime& runtime, const std::string& utf8) {
return runtime.createStringFromUtf8(
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());