@@ -30,8 +30,10 @@ using v8::HandleScope;
30
30
using v8::Int32;
31
31
using v8::Isolate;
32
32
using v8::Local;
33
+ using v8::NewStringType;
33
34
using v8::Object;
34
35
using v8::ObjectTemplate;
36
+ using v8::SnapshotCreator;
35
37
using v8::String;
36
38
using v8::Uint32;
37
39
using v8::Undefined;
@@ -58,7 +60,7 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
58
60
std::vector<View> views;
59
61
size_t total = 0 ;
60
62
61
- std::vector<v8:: Global<Value>> buffers;
63
+ std::vector<Global<Value>> buffers;
62
64
if (FromV8Array (context, array, &buffers).IsNothing ()) {
63
65
return ;
64
66
}
@@ -108,17 +110,14 @@ void BlobFromFilePath(const FunctionCallbackInfo<Value>& args) {
108
110
std::vector<std::unique_ptr<DataQueue::Entry>> entries;
109
111
entries.push_back (std::move (entry));
110
112
111
- auto blob =
112
- Blob::Create (env, DataQueue::CreateIdempotent (std::move (entries)));
113
-
114
- if (blob) {
115
- auto array = Array::New (env->isolate (), 2 );
116
- USE (array->Set (env->context (), 0 , blob->object ()));
117
- USE (array->Set (env->context (),
118
- 1 ,
119
- Uint32::NewFromUnsigned (env->isolate (), blob->length ())));
120
-
121
- args.GetReturnValue ().Set (array);
113
+ if (auto blob =
114
+ Blob::Create (env, DataQueue::CreateIdempotent (std::move (entries)))) {
115
+ Local<Value> vals[2 ]{
116
+ blob->object (),
117
+ Uint32::NewFromUnsigned (env->isolate (), blob->length ()),
118
+ };
119
+ args.GetReturnValue ().Set (
120
+ Array::New (env->isolate (), &vals[0 ], arraysize (vals)));
122
121
}
123
122
}
124
123
} // namespace
@@ -159,7 +158,7 @@ Local<FunctionTemplate> Blob::GetConstructorTemplate(Environment* env) {
159
158
return tmpl;
160
159
}
161
160
162
- bool Blob::HasInstance (Environment* env, v8:: Local<v8:: Value> object) {
161
+ bool Blob::HasInstance (Environment* env, Local<Value> object) {
163
162
return GetConstructorTemplate (env)->HasInstance (object);
164
163
}
165
164
@@ -188,7 +187,7 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
188
187
Local<Array> array = args[0 ].As <Array>();
189
188
std::vector<std::unique_ptr<DataQueue::Entry>> entries (array->Length ());
190
189
191
- std::vector<v8:: Global<Value>> sources;
190
+ std::vector<Global<Value>> sources;
192
191
if (FromV8Array (context, array, &sources).IsNothing ()) {
193
192
return ;
194
193
}
@@ -197,12 +196,16 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
197
196
for (size_t i = 0 ; i < count; i++) {
198
197
Local<Value> entry = sources[i].Get (isolate);
199
198
200
- const auto entryFromArrayBuffer = [isolate](v8::Local<v8::ArrayBuffer> buf,
201
- size_t byte_length,
202
- size_t byte_offset = 0 ) {
199
+ auto entryFromArrayBuffer =
200
+ [isolate](Local<ArrayBuffer> buf,
201
+ size_t byte_length,
202
+ size_t byte_offset =
203
+ 0 ) mutable -> std::unique_ptr<DataQueue::Entry> {
203
204
if (buf->IsDetachable ()) {
204
205
std::shared_ptr<BackingStore> store = buf->GetBackingStore ();
205
- USE (buf->Detach (Local<Value>()));
206
+ if (buf->Detach (Local<Value>()).IsNothing ()) {
207
+ return nullptr ;
208
+ }
206
209
return DataQueue::CreateInMemoryEntryFromBackingStore (
207
210
store, byte_offset, byte_length);
208
211
}
@@ -227,11 +230,15 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
227
230
// ensuring appropriate spec compliance.
228
231
if (entry->IsArrayBuffer ()) {
229
232
Local<ArrayBuffer> buf = entry.As <ArrayBuffer>();
230
- entries[i] = entryFromArrayBuffer (buf, buf->ByteLength ());
233
+ auto ret = entryFromArrayBuffer (buf, buf->ByteLength ());
234
+ if (!ret) return ;
235
+ entries[i] = std::move (ret);
231
236
} else if (entry->IsArrayBufferView ()) {
232
237
Local<ArrayBufferView> view = entry.As <ArrayBufferView>();
233
- entries[i] = entryFromArrayBuffer (
238
+ auto ret = entryFromArrayBuffer (
234
239
view->Buffer (), view->ByteLength (), view->ByteOffset ());
240
+ if (!ret) return ;
241
+ entries[i] = std::move (ret);
235
242
} else if (Blob::HasInstance (env, entry)) {
236
243
Blob* blob;
237
244
ASSIGN_OR_RETURN_UNWRAP (&blob, entry);
@@ -279,22 +286,22 @@ BaseObjectPtr<Blob> Blob::Slice(Environment* env, size_t start, size_t end) {
279
286
}
280
287
281
288
Blob::Blob (Environment* env,
282
- v8:: Local<v8:: Object> obj,
289
+ Local<Object> obj,
283
290
std::shared_ptr<DataQueue> data_queue)
284
291
: BaseObject(env, obj), data_queue_(data_queue) {
285
292
MakeWeak ();
286
293
}
287
294
288
295
Blob::Reader::Reader (Environment* env,
289
- v8:: Local<v8:: Object> obj,
296
+ Local<Object> obj,
290
297
BaseObjectPtr<Blob> strong_ptr)
291
298
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_BLOBREADER),
292
299
inner_ (strong_ptr->data_queue_->get_reader ()),
293
300
strong_ptr_(std::move(strong_ptr)) {
294
301
MakeWeak ();
295
302
}
296
303
297
- bool Blob::Reader::HasInstance (Environment* env, v8:: Local<v8:: Value> value) {
304
+ bool Blob::Reader::HasInstance (Environment* env, Local<Value> value) {
298
305
return GetConstructorTemplate (env)->HasInstance (value);
299
306
}
300
307
@@ -370,7 +377,7 @@ void Blob::Reader::Pull(const FunctionCallbackInfo<Value>& args) {
370
377
for (size_t n = 0 ; n < count; n++) total += vecs[n].len ;
371
378
372
379
std::shared_ptr<BackingStore> store =
373
- v8:: ArrayBuffer::NewBackingStore (env->isolate (), total);
380
+ ArrayBuffer::NewBackingStore (env->isolate (), total);
374
381
auto ptr = static_cast <uint8_t *>(store->Data ());
375
382
for (size_t n = 0 ; n < count; n++) {
376
383
std::copy (vecs[n].base , vecs[n].base + vecs[n].len , ptr);
@@ -415,7 +422,7 @@ std::unique_ptr<worker::TransferData> Blob::CloneForMessaging() const {
415
422
return std::make_unique<BlobTransferData>(data_queue_);
416
423
}
417
424
418
- void Blob::StoreDataObject (const v8:: FunctionCallbackInfo<v8:: Value>& args) {
425
+ void Blob::StoreDataObject (const FunctionCallbackInfo<Value>& args) {
419
426
Realm* realm = Realm::GetCurrent (args);
420
427
421
428
CHECK (args[0 ]->IsString ()); // ID key
@@ -468,7 +475,7 @@ void Blob::RevokeObjectURL(const FunctionCallbackInfo<Value>& args) {
468
475
}
469
476
}
470
477
471
- void Blob::GetDataObject (const v8:: FunctionCallbackInfo<v8:: Value>& args) {
478
+ void Blob::GetDataObject (const FunctionCallbackInfo<Value>& args) {
472
479
CHECK (args[0 ]->IsString ());
473
480
Realm* realm = Realm::GetCurrent (args);
474
481
BlobBindingData* binding_data = realm->GetBindingData <BlobBindingData>();
@@ -482,7 +489,7 @@ void Blob::GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
482
489
Local<Value> type;
483
490
if (!String::NewFromUtf8 (isolate,
484
491
stored.type .c_str (),
485
- v8:: NewStringType::kNormal ,
492
+ NewStringType::kNormal ,
486
493
static_cast <int >(stored.type .length ()))
487
494
.ToLocal (&type)) {
488
495
return ;
@@ -554,7 +561,7 @@ void BlobBindingData::Deserialize(Local<Context> context,
554
561
}
555
562
556
563
bool BlobBindingData::PrepareForSerialization (Local<Context> context,
557
- v8:: SnapshotCreator* creator) {
564
+ SnapshotCreator* creator) {
558
565
// Stored blob objects are not actually persisted.
559
566
// Return true because we need to maintain the reference to the binding from
560
567
// JS land.
0 commit comments