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