@@ -328,6 +328,7 @@ class SerializerDelegate : public ValueSerializer::Delegate {
328
328
if (JSTransferable::IsJSTransferable (env_, context_, object)) {
329
329
BaseObjectPtr<JSTransferable> js_transferable =
330
330
JSTransferable::Wrap (env_, object);
331
+ if (!js_transferable) return Nothing<bool >();
331
332
return WriteHostObject (js_transferable);
332
333
}
333
334
@@ -550,6 +551,7 @@ Maybe<bool> Message::Serialize(Environment* env,
550
551
return Nothing<bool >();
551
552
}
552
553
host_object = JSTransferable::Wrap (env, entry);
554
+ if (!host_object) return Nothing<bool >();
553
555
}
554
556
555
557
if (env->message_port_constructor_template ()->HasInstance (entry) &&
@@ -1245,27 +1247,38 @@ Local<FunctionTemplate> GetMessagePortConstructorTemplate(
1245
1247
BaseObjectPtr<JSTransferable> JSTransferable::Wrap (Environment* env,
1246
1248
Local<Object> target) {
1247
1249
Local<Context> context = env->context ();
1248
- Local<Value> wrapper_val =
1249
- target->GetPrivate (context, env->js_transferable_wrapper_private_symbol ())
1250
- .ToLocalChecked ();
1250
+ Local<Value> wrapper_val;
1251
+ if (!target
1252
+ ->GetPrivate (context, env->js_transferable_wrapper_private_symbol ())
1253
+ .ToLocal (&wrapper_val)) {
1254
+ return {};
1255
+ }
1251
1256
DCHECK (wrapper_val->IsObject () || wrapper_val->IsUndefined ());
1252
1257
BaseObjectPtr<JSTransferable> wrapper;
1253
1258
if (wrapper_val->IsObject ()) {
1254
1259
wrapper =
1255
1260
BaseObjectPtr<JSTransferable>{Unwrap<JSTransferable>(wrapper_val)};
1256
1261
} else {
1257
- Local<Object> wrapper_obj = env->js_transferable_constructor_template ()
1258
- ->GetFunction (context)
1259
- .ToLocalChecked ()
1260
- ->NewInstance (context)
1261
- .ToLocalChecked ();
1262
+ Local<Function> ctor;
1263
+ if (!env->js_transferable_constructor_template ()
1264
+ ->GetFunction (context)
1265
+ .ToLocal (&ctor)) {
1266
+ return {};
1267
+ }
1268
+ Local<Object> wrapper_obj;
1269
+ if (!ctor->NewInstance (context).ToLocal (&wrapper_obj)) {
1270
+ return {};
1271
+ }
1262
1272
// Make sure the JSTransferable wrapper object is not garbage collected
1263
1273
// until the strong BaseObjectPtr's reference count is decreased to 0.
1264
1274
wrapper = MakeDetachedBaseObject<JSTransferable>(env, wrapper_obj, target);
1265
- target
1266
- ->SetPrivate (
1267
- context, env->js_transferable_wrapper_private_symbol (), wrapper_obj)
1268
- .ToChecked ();
1275
+ if (target
1276
+ ->SetPrivate (context,
1277
+ env->js_transferable_wrapper_private_symbol (),
1278
+ wrapper_obj)
1279
+ .IsNothing ()) {
1280
+ return {};
1281
+ }
1269
1282
}
1270
1283
return wrapper;
1271
1284
}
@@ -1396,7 +1409,9 @@ Maybe<BaseObjectPtrList> JSTransferable::NestedTransferables() const {
1396
1409
if (!JSTransferable::IsJSTransferable (env (), context, obj)) {
1397
1410
continue ;
1398
1411
}
1399
- ret.emplace_back (JSTransferable::Wrap (env (), obj));
1412
+ auto wrapped = JSTransferable::Wrap (env (), obj);
1413
+ if (!wrapped) return Nothing<BaseObjectPtrList>();
1414
+ ret.emplace_back (wrapped);
1400
1415
}
1401
1416
return Just (ret);
1402
1417
}
0 commit comments