@@ -26,17 +26,17 @@ using v8::FunctionCallbackInfo;
26
26
using v8::HandleScope;
27
27
using v8::Isolate;
28
28
using v8::Local;
29
- using v8::NewStringType;
30
29
using v8::Object;
31
30
using v8::ObjectTemplate;
31
+ using v8::SnapshotCreator;
32
32
using v8::String;
33
33
using v8::Value;
34
34
35
35
void BindingData::MemoryInfo (MemoryTracker* tracker) const {
36
36
tracker->TrackField (" url_components_buffer" , url_components_buffer_);
37
37
}
38
38
39
- BindingData::BindingData (Realm* realm, v8:: Local<v8:: Object> object)
39
+ BindingData::BindingData (Realm* realm, Local<Object> object)
40
40
: SnapshotableObject(realm, object, type_int),
41
41
url_components_buffer_ (realm->isolate (), kURLComponentsLength) {
42
42
object
@@ -47,8 +47,8 @@ BindingData::BindingData(Realm* realm, v8::Local<v8::Object> object)
47
47
url_components_buffer_.MakeWeak ();
48
48
}
49
49
50
- bool BindingData::PrepareForSerialization (v8:: Local<v8:: Context> context,
51
- v8:: SnapshotCreator* creator) {
50
+ bool BindingData::PrepareForSerialization (Local<Context> context,
51
+ SnapshotCreator* creator) {
52
52
// We'll just re-initialize the buffers in the constructor since their
53
53
// contents can be thrown away once consumed in the previous call.
54
54
url_components_buffer_.Release ();
@@ -64,12 +64,12 @@ InternalFieldInfoBase* BindingData::Serialize(int index) {
64
64
return info;
65
65
}
66
66
67
- void BindingData::Deserialize (v8:: Local<v8:: Context> context,
68
- v8:: Local<v8:: Object> holder,
67
+ void BindingData::Deserialize (Local<Context> context,
68
+ Local<Object> holder,
69
69
int index,
70
70
InternalFieldInfoBase* info) {
71
71
DCHECK_IS_SNAPSHOT_SLOT (index );
72
- v8:: HandleScope scope (context->GetIsolate ());
72
+ HandleScope scope (context->GetIsolate ());
73
73
Realm* realm = Realm::GetCurrent (context);
74
74
BindingData* binding = realm->AddBindingData <BindingData>(holder);
75
75
CHECK_NOT_NULL (binding);
@@ -173,8 +173,11 @@ void BindingData::PathToFileURL(const FunctionCallbackInfo<Value>& args) {
173
173
174
174
binding_data->UpdateComponents (out->get_components (), out->type );
175
175
176
- args.GetReturnValue ().Set (
177
- ToV8Value (realm->context (), out->get_href (), isolate).ToLocalChecked ());
176
+ Local<Value> ret;
177
+ if (ToV8Value (realm->context (), out->get_href (), isolate).ToLocal (&ret))
178
+ [[likely]] {
179
+ args.GetReturnValue ().Set (ret);
180
+ }
178
181
}
179
182
180
183
void BindingData::DomainToASCII (const FunctionCallbackInfo<Value>& args) {
@@ -196,8 +199,12 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {
196
199
return args.GetReturnValue ().Set (String::Empty (env->isolate ()));
197
200
}
198
201
std::string host = out->get_hostname ();
199
- args.GetReturnValue ().Set (
200
- String::NewFromUtf8 (env->isolate (), host.c_str ()).ToLocalChecked ());
202
+
203
+ Local<Value> ret;
204
+ if (ToV8Value (env->context (), host, env->isolate ()).ToLocal (&ret))
205
+ [[likely]] {
206
+ args.GetReturnValue ().Set (ret);
207
+ }
201
208
}
202
209
203
210
void BindingData::DomainToUnicode (const FunctionCallbackInfo<Value>& args) {
@@ -220,14 +227,14 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
220
227
}
221
228
std::string result = ada::idna::to_unicode (out->get_hostname ());
222
229
223
- args. GetReturnValue (). Set ( String::NewFromUtf8 (env-> isolate (),
224
- result. c_str (),
225
- NewStringType:: kNormal ,
226
- result. length ())
227
- . ToLocalChecked ());
230
+ Local<Value> ret;
231
+ if ( ToV8Value (env-> context (), result, env-> isolate ()). ToLocal (&ret))
232
+ [[likely]] {
233
+ args. GetReturnValue (). Set (ret);
234
+ }
228
235
}
229
236
230
- void BindingData::GetOrigin (const v8:: FunctionCallbackInfo<Value>& args) {
237
+ void BindingData::GetOrigin (const FunctionCallbackInfo<Value>& args) {
231
238
CHECK_GE (args.Length (), 1 );
232
239
CHECK (args[0 ]->IsString ()); // input
233
240
@@ -244,11 +251,12 @@ void BindingData::GetOrigin(const v8::FunctionCallbackInfo<Value>& args) {
244
251
}
245
252
246
253
std::string origin = out->get_origin ();
247
- args.GetReturnValue ().Set (String::NewFromUtf8 (env->isolate (),
248
- origin.data (),
249
- NewStringType::kNormal ,
250
- origin.length ())
251
- .ToLocalChecked ());
254
+
255
+ Local<Value> ret;
256
+ if (ToV8Value (env->context (), origin, env->isolate ()).ToLocal (&ret))
257
+ [[likely]] {
258
+ args.GetReturnValue ().Set (ret);
259
+ }
252
260
}
253
261
254
262
void BindingData::CanParse (const FunctionCallbackInfo<Value>& args) {
@@ -328,11 +336,12 @@ void BindingData::Format(const FunctionCallbackInfo<Value>& args) {
328
336
}
329
337
330
338
std::string result = out->get_href ();
331
- args.GetReturnValue ().Set (String::NewFromUtf8 (env->isolate (),
332
- result.data (),
333
- NewStringType::kNormal ,
334
- result.length ())
335
- .ToLocalChecked ());
339
+
340
+ Local<Value> ret;
341
+ if (ToV8Value (env->context (), result, env->isolate ()).ToLocal (&ret))
342
+ [[likely]] {
343
+ args.GetReturnValue ().Set (ret);
344
+ }
336
345
}
337
346
338
347
void BindingData::Parse (const FunctionCallbackInfo<Value>& args) {
@@ -372,8 +381,11 @@ void BindingData::Parse(const FunctionCallbackInfo<Value>& args) {
372
381
373
382
binding_data->UpdateComponents (out->get_components (), out->type );
374
383
375
- args.GetReturnValue ().Set (
376
- ToV8Value (realm->context (), out->get_href (), isolate).ToLocalChecked ());
384
+ Local<Value> ret;
385
+ if (ToV8Value (realm->context (), out->get_href (), isolate).ToLocal (&ret))
386
+ [[likely]] {
387
+ args.GetReturnValue ().Set (ret);
388
+ }
377
389
}
378
390
379
391
void BindingData::Update (const FunctionCallbackInfo<Value>& args) {
@@ -446,8 +458,12 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) {
446
458
}
447
459
448
460
binding_data->UpdateComponents (out->get_components (), out->type );
449
- args.GetReturnValue ().Set (
450
- ToV8Value (realm->context (), out->get_href (), isolate).ToLocalChecked ());
461
+
462
+ Local<Value> ret;
463
+ if (ToV8Value (realm->context (), out->get_href (), isolate).ToLocal (&ret))
464
+ [[likely]] {
465
+ args.GetReturnValue ().Set (ret);
466
+ }
451
467
}
452
468
453
469
void BindingData::UpdateComponents (const ada::url_components& components,
@@ -513,22 +529,21 @@ void ThrowInvalidURL(node::Environment* env,
513
529
514
530
auto err_object = err.As <Object>();
515
531
516
- USE (err_object-> Set (env-> context (),
517
- env->input_string (),
518
- v8::String::NewFromUtf8 (env->isolate (),
519
- input. data (),
520
- v8::NewStringType:: kNormal ,
521
- input. size ())
522
- . ToLocalChecked ()));
532
+ Local<Value> tmp;
533
+ if (! ToV8Value (env-> context (), input, env->isolate ()). ToLocal (&tmp) ||
534
+ err_object-> Set (env->context (), env-> input_string (), tmp). IsNothing ())
535
+ [[unlikely]] {
536
+ // A superseding error has been thrown.
537
+ return ;
538
+ }
523
539
524
540
if (base.has_value ()) {
525
- USE (err_object->Set (env->context (),
526
- env->base_string (),
527
- v8::String::NewFromUtf8 (env->isolate (),
528
- base.value ().c_str (),
529
- v8::NewStringType::kNormal ,
530
- base.value ().size ())
531
- .ToLocalChecked ()));
541
+ if (!ToV8Value (env->context (), base.value (), env->isolate ())
542
+ .ToLocal (&tmp) ||
543
+ err_object->Set (env->context (), env->base_string (), tmp).IsNothing ())
544
+ [[unlikely]] {
545
+ return ;
546
+ }
532
547
}
533
548
534
549
env->isolate ()->ThrowException (err);
0 commit comments