@@ -867,68 +867,6 @@ inline void Environment::Free(char* data, size_t size) {
867867 isolate_data ()->allocator ()->Free (data, size);
868868}
869869
870- inline AllocatedBuffer Environment::AllocateManaged (size_t size, bool checked) {
871- char * data = checked ? Allocate (size) : AllocateUnchecked (size);
872- if (data == nullptr ) size = 0 ;
873- return AllocatedBuffer (this , uv_buf_init (data, size));
874- }
875-
876- inline AllocatedBuffer::AllocatedBuffer (Environment* env, uv_buf_t buf)
877- : env_(env), buffer_(buf) {}
878-
879- inline void AllocatedBuffer::Resize (size_t len) {
880- // The `len` check is to make sure we don't end up with `nullptr` as our base.
881- char * new_data = env_->Reallocate (buffer_.base , buffer_.len ,
882- len > 0 ? len : 1 );
883- CHECK_NOT_NULL (new_data);
884- buffer_ = uv_buf_init (new_data, len);
885- }
886-
887- inline uv_buf_t AllocatedBuffer::release () {
888- uv_buf_t ret = buffer_;
889- buffer_ = uv_buf_init (nullptr , 0 );
890- return ret;
891- }
892-
893- inline char * AllocatedBuffer::data () {
894- return buffer_.base ;
895- }
896-
897- inline const char * AllocatedBuffer::data () const {
898- return buffer_.base ;
899- }
900-
901- inline size_t AllocatedBuffer::size () const {
902- return buffer_.len ;
903- }
904-
905- inline AllocatedBuffer::AllocatedBuffer (Environment* env)
906- : env_(env), buffer_(uv_buf_init(nullptr , 0 )) {}
907-
908- inline AllocatedBuffer::AllocatedBuffer (AllocatedBuffer&& other)
909- : AllocatedBuffer() {
910- *this = std::move (other);
911- }
912-
913- inline AllocatedBuffer& AllocatedBuffer::operator =(AllocatedBuffer&& other) {
914- clear ();
915- env_ = other.env_ ;
916- buffer_ = other.release ();
917- return *this ;
918- }
919-
920- inline AllocatedBuffer::~AllocatedBuffer () {
921- clear ();
922- }
923-
924- inline void AllocatedBuffer::clear () {
925- uv_buf_t buf = release ();
926- if (buf.base != nullptr ) {
927- CHECK_NOT_NULL (env_);
928- env_->Free (buf.base , buf.len );
929- }
930- }
931-
932870// It's a bit awkward to define this Buffer::New() overload here, but it
933871// avoids a circular dependency with node_internals.h.
934872namespace Buffer {
@@ -938,32 +876,6 @@ v8::MaybeLocal<v8::Object> New(Environment* env,
938876 bool uses_malloc);
939877}
940878
941- inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer () {
942- CHECK_NOT_NULL (env_);
943- v8::MaybeLocal<v8::Object> obj = Buffer::New (env_, data (), size (), false );
944- if (!obj.IsEmpty ()) release ();
945- return obj;
946- }
947-
948- inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer () {
949- CHECK_NOT_NULL (env_);
950- uv_buf_t buf = release ();
951- auto callback = [](void * data, size_t length, void * deleter_data){
952- CHECK_NOT_NULL (deleter_data);
953-
954- static_cast <v8::ArrayBuffer::Allocator*>(deleter_data)
955- ->Free (data, length);
956- };
957- std::unique_ptr<v8::BackingStore> backing =
958- v8::ArrayBuffer::NewBackingStore (buf.base ,
959- buf.len ,
960- callback,
961- env_->isolate ()
962- ->GetArrayBufferAllocator ());
963- return v8::ArrayBuffer::New (env_->isolate (),
964- std::move (backing));
965- }
966-
967879inline void Environment::ThrowError (const char * errmsg) {
968880 ThrowError (v8::Exception::Error, errmsg);
969881}
0 commit comments