@@ -213,20 +213,6 @@ inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
213213 .ToLocalChecked ();
214214}
215215
216- v8::MaybeLocal<v8::String> StringViewToV8String (
217- v8::Isolate* isolate, v8_inspector::StringView string) {
218- if (string.is8Bit ()) {
219- return v8::String::NewFromOneByte (isolate,
220- string.characters8 (),
221- v8::NewStringType::kNormal ,
222- string.length ());
223- }
224- return v8::String::NewFromTwoByte (isolate,
225- string.characters16 (),
226- v8::NewStringType::kNormal ,
227- string.length ());
228- }
229-
230216void SwapBytes16 (char * data, size_t nbytes) {
231217 CHECK_EQ (nbytes % 2 , 0 );
232218
@@ -454,6 +440,31 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
454440 .FromMaybe (v8::Local<v8::String>());
455441}
456442
443+ v8::MaybeLocal<v8::Value> ToV8Value (v8::Local<v8::Context> context,
444+ v8_inspector::StringView str,
445+ v8::Isolate* isolate) {
446+ if (isolate == nullptr ) isolate = context->GetIsolate ();
447+ if (UNLIKELY (str.length () >= static_cast <size_t >(v8::String::kMaxLength ))) {
448+ // V8 only has a TODO comment about adding an exception when the maximum
449+ // string size is exceeded.
450+ ThrowErrStringTooLong (isolate);
451+ return v8::MaybeLocal<v8::Value>();
452+ }
453+
454+ if (str.is8Bit ()) {
455+ return v8::String::NewFromOneByte (isolate,
456+ str.characters8 (),
457+ v8::NewStringType::kNormal ,
458+ str.length ())
459+ .FromMaybe (v8::Local<v8::String>());
460+ }
461+ return v8::String::NewFromTwoByte (isolate,
462+ str.characters16 (),
463+ v8::NewStringType::kNormal ,
464+ str.length ())
465+ .FromMaybe (v8::Local<v8::String>());
466+ }
467+
457468template <typename T>
458469v8::MaybeLocal<v8::Value> ToV8Value (v8::Local<v8::Context> context,
459470 const std::vector<T>& vec,
0 commit comments