diff --git a/src/base-object-inl.h b/src/base-object-inl.h index db0daa1e82f559..87159ffc6838c7 100644 --- a/src/base-object-inl.h +++ b/src/base-object-inl.h @@ -39,7 +39,7 @@ inline Environment* BaseObject::env() const { template inline void BaseObject::WeakCallback( - const v8::WeakCallbackData& data) { + const v8::WeakCallbackInfo& data) { Type* self = data.GetParameter(); self->persistent().Reset(); delete self; @@ -53,7 +53,8 @@ inline void BaseObject::MakeWeak(Type* ptr) { CHECK_GT(handle->InternalFieldCount(), 0); Wrap(handle, ptr); handle_.MarkIndependent(); - handle_.SetWeak(ptr, WeakCallback); + handle_.SetWeak(ptr, WeakCallback, + v8::WeakCallbackType::kParameter); } diff --git a/src/base-object.h b/src/base-object.h index 5a7b95827e8f11..8574a904e71b1a 100644 --- a/src/base-object.h +++ b/src/base-object.h @@ -40,7 +40,7 @@ class BaseObject { template static inline void WeakCallback( - const v8::WeakCallbackData& data); + const v8::WeakCallbackInfo& data); v8::Persistent handle_; Environment* env_; diff --git a/src/node.cc b/src/node.cc index 2a5fe73333913a..10ee9264e3306b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -116,6 +116,7 @@ using v8::Local; using v8::Locker; using v8::MaybeLocal; using v8::Message; +using v8::Name; using v8::Number; using v8::Object; using v8::ObjectTemplate; @@ -2467,7 +2468,7 @@ static void LinkedBinding(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(exports); } -static void ProcessTitleGetter(Local property, +static void ProcessTitleGetter(Local property, const PropertyCallbackInfo& info) { char buffer[512]; uv_get_process_title(buffer, sizeof(buffer)); @@ -2475,7 +2476,7 @@ static void ProcessTitleGetter(Local property, } -static void ProcessTitleSetter(Local property, +static void ProcessTitleSetter(Local property, Local value, const PropertyCallbackInfo& info) { node::Utf8Value title(info.GetIsolate(), value); @@ -2704,13 +2705,13 @@ static Local GetFeatures(Environment* env) { } -static void DebugPortGetter(Local property, +static void DebugPortGetter(Local property, const PropertyCallbackInfo& info) { info.GetReturnValue().Set(debug_port); } -static void DebugPortSetter(Local property, +static void DebugPortSetter(Local property, Local value, const PropertyCallbackInfo& info) { debug_port = value->Int32Value(); @@ -2722,7 +2723,7 @@ static void DebugPause(const FunctionCallbackInfo& args); static void DebugEnd(const FunctionCallbackInfo& args); -void NeedImmediateCallbackGetter(Local property, +void NeedImmediateCallbackGetter(Local property, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); const uv_check_t* immediate_check_handle = env->immediate_check_handle(); @@ -2733,7 +2734,7 @@ void NeedImmediateCallbackGetter(Local property, static void NeedImmediateCallbackSetter( - Local property, + Local property, Local value, const PropertyCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); @@ -2822,10 +2823,12 @@ void SetupProcessObject(Environment* env, Local process = env->process_object(); - process->SetAccessor(env->title_string(), - ProcessTitleGetter, - ProcessTitleSetter, - env->as_external()); + auto maybe = process->SetAccessor(env->context(), + env->title_string(), + ProcessTitleGetter, + ProcessTitleSetter, + env->as_external()); + CHECK(maybe.FromJust()); // process.version READONLY_PROPERTY(process, @@ -2989,10 +2992,12 @@ void SetupProcessObject(Environment* env, READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid())); READONLY_PROPERTY(process, "features", GetFeatures(env)); - process->SetAccessor(env->need_imm_cb_string(), - NeedImmediateCallbackGetter, - NeedImmediateCallbackSetter, - env->as_external()); + maybe = process->SetAccessor(env->context(), + env->need_imm_cb_string(), + NeedImmediateCallbackGetter, + NeedImmediateCallbackSetter, + env->as_external()); + CHECK(maybe.FromJust()); // -e, --eval if (eval_string) { @@ -3067,10 +3072,13 @@ void SetupProcessObject(Environment* env, process->Set(env->exec_path_string(), exec_path_value); delete[] exec_path; - process->SetAccessor(env->debug_port_string(), - DebugPortGetter, - DebugPortSetter, - env->as_external()); + maybe = process->SetAccessor(env->context(), + env->debug_port_string(), + DebugPortGetter, + DebugPortSetter, + env->as_external()); + CHECK(maybe.FromJust()); + // define various internal methods env->SetMethod(process, diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 988e41dbc9aa22..a38bc84b0e70ff 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -72,27 +72,25 @@ using v8::Uint32; using v8::Uint32Array; using v8::Uint8Array; using v8::Value; -using v8::WeakCallbackData; +using v8::WeakCallbackInfo; class CallbackInfo { public: static inline void Free(char* data, void* hint); static inline CallbackInfo* New(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint = 0); - inline void Dispose(Isolate* isolate); - inline Persistent* persistent(); private: - static void WeakCallback(const WeakCallbackData&); - inline void WeakCallback(Isolate* isolate, Local object); + static void WeakCallback(const WeakCallbackInfo&); + inline void WeakCallback(Isolate* isolate, char* const data); inline CallbackInfo(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint); ~CallbackInfo(); - Persistent persistent_; + Persistent persistent_; FreeCallback const callback_; void* const hint_; DISALLOW_COPY_AND_ASSIGN(CallbackInfo); @@ -105,31 +103,29 @@ void CallbackInfo::Free(char* data, void*) { CallbackInfo* CallbackInfo::New(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint) { return new CallbackInfo(isolate, object, callback, hint); } -void CallbackInfo::Dispose(Isolate* isolate) { - WeakCallback(isolate, PersistentToLocal(isolate, persistent_)); -} - - -Persistent* CallbackInfo::persistent() { - return &persistent_; -} - - CallbackInfo::CallbackInfo(Isolate* isolate, - Local object, + Local object, FreeCallback callback, void* hint) : persistent_(isolate, object), callback_(callback), hint_(hint) { - persistent_.SetWeak(this, WeakCallback); + ArrayBuffer::Contents obj_c = object->GetContents(); + char* const data = static_cast(obj_c.Data()); + if (object->ByteLength() != 0) + CHECK_NE(data, nullptr); + + object->SetAlignedPointerInInternalField(kBufferInternalFieldIndex, data); + + persistent_.SetWeak(this, WeakCallback, + v8::WeakCallbackType::kInternalFields); persistent_.SetWrapperClassId(BUFFER_ID); persistent_.MarkIndependent(); isolate->AdjustAmountOfExternalAllocatedMemory(sizeof(*this)); @@ -142,21 +138,15 @@ CallbackInfo::~CallbackInfo() { void CallbackInfo::WeakCallback( - const WeakCallbackData& data) { - data.GetParameter()->WeakCallback(data.GetIsolate(), data.GetValue()); + const WeakCallbackInfo& data) { + data.GetParameter()->WeakCallback( + data.GetIsolate(), + static_cast(data.GetInternalField(kBufferInternalFieldIndex))); } -void CallbackInfo::WeakCallback(Isolate* isolate, Local object) { - CHECK(object->IsArrayBuffer()); - Local buf = object.As(); - ArrayBuffer::Contents obj_c = buf->GetContents(); - char* const obj_data = static_cast(obj_c.Data()); - if (buf->ByteLength() != 0) - CHECK_NE(obj_data, nullptr); - - buf->Neuter(); - callback_(obj_data, hint_); +void CallbackInfo::WeakCallback(Isolate* isolate, char* const data) { + callback_(data, hint_); int64_t change_in_bytes = -static_cast(sizeof(*this)); isolate->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); diff --git a/src/node_buffer.h b/src/node_buffer.h index 503cbb167547a5..2bcf245f3920ad 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -10,6 +10,10 @@ namespace Buffer { static const unsigned int kMaxLength = sizeof(int32_t) == sizeof(intptr_t) ? 0x3fffffff : 0x7fffffff; +// Buffers have two internal fields, the first of which is reserved for use by +// Node. +static const unsigned int kBufferInternalFieldIndex = 0; + NODE_EXTERN typedef void (*FreeCallback)(char* data, void* hint); NODE_EXTERN bool HasInstance(v8::Local val);