31
31
namespace node {
32
32
33
33
using v8::Array;
34
+ using v8::ArrayBuffer;
35
+ using v8::BackingStore;
36
+ using v8::Boolean ;
34
37
using v8::Context;
35
38
using v8::DontDelete;
36
39
using v8::FunctionCallbackInfo;
37
40
using v8::FunctionTemplate;
38
41
using v8::HandleScope;
39
42
using v8::Integer;
43
+ using v8::Isolate;
40
44
using v8::Local;
41
45
using v8::MaybeLocal;
42
46
using v8::Object;
@@ -314,7 +318,7 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
314
318
315
319
CHECK (args[0 ]->IsUint32 ());
316
320
CHECK (args[1 ]->IsBoolean ());
317
- bool is_recv = args[1 ].As <v8:: Boolean >()->Value ();
321
+ bool is_recv = args[1 ].As <Boolean >()->Value ();
318
322
const char * uv_func_name = is_recv ? " uv_recv_buffer_size" :
319
323
" uv_send_buffer_size" ;
320
324
@@ -679,7 +683,7 @@ void UDPWrap::OnAlloc(uv_handle_t* handle,
679
683
}
680
684
681
685
uv_buf_t UDPWrap::OnAlloc (size_t suggested_size) {
682
- return AllocatedBuffer::AllocateManaged ( env (), suggested_size). release ( );
686
+ return env ()-> allocate_managed_buffer (suggested_size );
683
687
}
684
688
685
689
void UDPWrap::OnRecv (uv_udp_t * handle,
@@ -696,27 +700,32 @@ void UDPWrap::OnRecv(ssize_t nread,
696
700
const sockaddr* addr,
697
701
unsigned int flags) {
698
702
Environment* env = this ->env ();
699
- AllocatedBuffer buf (env, buf_);
703
+ Isolate* isolate = env->isolate ();
704
+ std::unique_ptr<BackingStore> bs = env->release_managed_buffer (buf_);
700
705
if (nread == 0 && addr == nullptr ) {
701
706
return ;
702
707
}
703
708
704
- HandleScope handle_scope (env-> isolate () );
709
+ HandleScope handle_scope (isolate);
705
710
Context::Scope context_scope (env->context ());
706
711
707
712
Local<Value> argv[] = {
708
- Integer::New (env-> isolate () , static_cast <int32_t >(nread)),
713
+ Integer::New (isolate, static_cast <int32_t >(nread)),
709
714
object (),
710
- Undefined (env-> isolate () ),
711
- Undefined (env-> isolate () )};
715
+ Undefined (isolate),
716
+ Undefined (isolate)};
712
717
713
718
if (nread < 0 ) {
714
719
MakeCallback (env->onmessage_string (), arraysize (argv), argv);
715
720
return ;
721
+ } else if (nread == 0 ) {
722
+ bs = ArrayBuffer::NewBackingStore (isolate, 0 );
723
+ } else {
724
+ bs = BackingStore::Reallocate (isolate, std::move (bs), nread);
716
725
}
717
726
718
- buf. Resize (nread );
719
- argv[2 ] = buf. ToBuffer ( ).ToLocalChecked ();
727
+ Local<ArrayBuffer> ab = ArrayBuffer::New (isolate, std::move (bs) );
728
+ argv[2 ] = Buffer::New (env, ab, 0 , ab-> ByteLength () ).ToLocalChecked ();
720
729
argv[3 ] = AddressToJS (env, addr);
721
730
MakeCallback (env->onmessage_string (), arraysize (argv), argv);
722
731
}
0 commit comments