@@ -883,68 +883,6 @@ inline void Environment::Free(char* data, size_t size) {
883883 isolate_data ()->allocator ()->Free (data, size);
884884}
885885
886- inline AllocatedBuffer Environment::AllocateManaged (size_t size, bool checked) {
887- char * data = checked ? Allocate (size) : AllocateUnchecked (size);
888- if (data == nullptr ) size = 0 ;
889- return AllocatedBuffer (this , uv_buf_init (data, size));
890- }
891-
892- inline AllocatedBuffer::AllocatedBuffer (Environment* env, uv_buf_t buf)
893- : env_(env), buffer_(buf) {}
894-
895- inline void AllocatedBuffer::Resize (size_t len) {
896- // The `len` check is to make sure we don't end up with `nullptr` as our base.
897- char * new_data = env_->Reallocate (buffer_.base , buffer_.len ,
898- len > 0 ? len : 1 );
899- CHECK_NOT_NULL (new_data);
900- buffer_ = uv_buf_init (new_data, len);
901- }
902-
903- inline uv_buf_t AllocatedBuffer::release () {
904- uv_buf_t ret = buffer_;
905- buffer_ = uv_buf_init (nullptr , 0 );
906- return ret;
907- }
908-
909- inline char * AllocatedBuffer::data () {
910- return buffer_.base ;
911- }
912-
913- inline const char * AllocatedBuffer::data () const {
914- return buffer_.base ;
915- }
916-
917- inline size_t AllocatedBuffer::size () const {
918- return buffer_.len ;
919- }
920-
921- inline AllocatedBuffer::AllocatedBuffer (Environment* env)
922- : env_(env), buffer_(uv_buf_init(nullptr , 0 )) {}
923-
924- inline AllocatedBuffer::AllocatedBuffer (AllocatedBuffer&& other)
925- : AllocatedBuffer() {
926- *this = std::move (other);
927- }
928-
929- inline AllocatedBuffer& AllocatedBuffer::operator =(AllocatedBuffer&& other) {
930- clear ();
931- env_ = other.env_ ;
932- buffer_ = other.release ();
933- return *this ;
934- }
935-
936- inline AllocatedBuffer::~AllocatedBuffer () {
937- clear ();
938- }
939-
940- inline void AllocatedBuffer::clear () {
941- uv_buf_t buf = release ();
942- if (buf.base != nullptr ) {
943- CHECK_NOT_NULL (env_);
944- env_->Free (buf.base , buf.len );
945- }
946- }
947-
948886// It's a bit awkward to define this Buffer::New() overload here, but it
949887// avoids a circular dependency with node_internals.h.
950888namespace Buffer {
@@ -954,32 +892,6 @@ v8::MaybeLocal<v8::Object> New(Environment* env,
954892 bool uses_malloc);
955893}
956894
957- inline v8::MaybeLocal<v8::Object> AllocatedBuffer::ToBuffer () {
958- CHECK_NOT_NULL (env_);
959- v8::MaybeLocal<v8::Object> obj = Buffer::New (env_, data (), size (), false );
960- if (!obj.IsEmpty ()) release ();
961- return obj;
962- }
963-
964- inline v8::Local<v8::ArrayBuffer> AllocatedBuffer::ToArrayBuffer () {
965- CHECK_NOT_NULL (env_);
966- uv_buf_t buf = release ();
967- auto callback = [](void * data, size_t length, void * deleter_data){
968- CHECK_NOT_NULL (deleter_data);
969-
970- static_cast <v8::ArrayBuffer::Allocator*>(deleter_data)
971- ->Free (data, length);
972- };
973- std::unique_ptr<v8::BackingStore> backing =
974- v8::ArrayBuffer::NewBackingStore (buf.base ,
975- buf.len ,
976- callback,
977- env_->isolate ()
978- ->GetArrayBufferAllocator ());
979- return v8::ArrayBuffer::New (env_->isolate (),
980- std::move (backing));
981- }
982-
983895inline void Environment::ThrowError (const char * errmsg) {
984896 ThrowError (v8::Exception::Error, errmsg);
985897}
0 commit comments