@@ -41,7 +41,10 @@ namespace {
41
41
// Concatenate multiple ArrayBufferView/ArrayBuffers into a single ArrayBuffer.
42
42
// This method treats all ArrayBufferView types the same.
43
43
void Concat (const FunctionCallbackInfo<Value>& args) {
44
- Environment* env = Environment::GetCurrent (args);
44
+ Isolate* isolate = args.GetIsolate ();
45
+ Local<Context> context = isolate->GetCurrentContext ();
46
+ Environment* env = Environment::GetCurrent (context);
47
+
45
48
CHECK (args[0 ]->IsArray ());
46
49
Local<Array> array = args[0 ].As <Array>();
47
50
@@ -54,9 +57,14 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
54
57
std::vector<View> views;
55
58
size_t total = 0 ;
56
59
57
- for (uint32_t n = 0 ; n < array->Length (); n++) {
58
- Local<Value> val;
59
- if (!array->Get (env->context (), n).ToLocal (&val)) return ;
60
+ std::vector<v8::Global<Value>> buffers;
61
+ if (FromV8Array (context, array, &buffers).IsNothing ()) {
62
+ return ;
63
+ }
64
+
65
+ size_t count = buffers.size ();
66
+ for (uint32_t i = 0 ; i < count; i++) {
67
+ Local<Value> val = buffers[i].Get (isolate);
60
68
if (val->IsArrayBuffer ()) {
61
69
auto ab = val.As <ArrayBuffer>();
62
70
views.push_back (View{ab->GetBackingStore (), ab->ByteLength (), 0 });
@@ -169,21 +177,27 @@ BaseObjectPtr<Blob> Blob::Create(Environment* env,
169
177
}
170
178
171
179
void Blob::New (const FunctionCallbackInfo<Value>& args) {
172
- Environment* env = Environment::GetCurrent (args);
180
+ Isolate* isolate = args.GetIsolate ();
181
+ Local<Context> context = isolate->GetCurrentContext ();
182
+ Environment* env = Environment::GetCurrent (context);
183
+
173
184
CHECK (args[0 ]->IsArray ()); // sources
174
185
175
186
Local<Array> array = args[0 ].As <Array>();
176
187
std::vector<std::unique_ptr<DataQueue::Entry>> entries (array->Length ());
177
188
178
- for (size_t i = 0 ; i < array->Length (); i++) {
179
- Local<Value> entry;
180
- if (!array->Get (env->context (), i).ToLocal (&entry)) {
181
- return ;
182
- }
189
+ std::vector<v8::Global<Value>> sources;
190
+ if (FromV8Array (context, array, &sources).IsNothing ()) {
191
+ return ;
192
+ }
193
+
194
+ size_t count = sources.size ();
195
+ for (size_t i = 0 ; i < count; i++) {
196
+ Local<Value> entry = sources[i].Get (isolate);
183
197
184
- const auto entryFromArrayBuffer = [env ](v8::Local<v8::ArrayBuffer> buf,
185
- size_t byte_length,
186
- size_t byte_offset = 0 ) {
198
+ const auto entryFromArrayBuffer = [isolate ](v8::Local<v8::ArrayBuffer> buf,
199
+ size_t byte_length,
200
+ size_t byte_offset = 0 ) {
187
201
if (buf->IsDetachable ()) {
188
202
std::shared_ptr<BackingStore> store = buf->GetBackingStore ();
189
203
USE (buf->Detach (Local<Value>()));
@@ -193,7 +207,7 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
193
207
194
208
// If the ArrayBuffer is not detachable, we will copy from it instead.
195
209
std::shared_ptr<BackingStore> store =
196
- ArrayBuffer::NewBackingStore (env-> isolate () , byte_length);
210
+ ArrayBuffer::NewBackingStore (isolate, byte_length);
197
211
uint8_t * ptr = static_cast <uint8_t *>(buf->Data ()) + byte_offset;
198
212
std::copy (ptr, ptr + byte_length, static_cast <uint8_t *>(store->Data ()));
199
213
return DataQueue::CreateInMemoryEntryFromBackingStore (
0 commit comments