diff --git a/src/base_object-inl.h b/src/base_object-inl.h index b15fe428dd2749..ff618f08b5d394 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -73,7 +73,6 @@ T* BaseObject::FromJSObject(v8::Local object) { return static_cast(FromJSObject(object)); } - void BaseObject::OnGCCollect() { delete this; } diff --git a/src/env.cc b/src/env.cc index 79ee0c1f51fe9e..d078491c356d19 100644 --- a/src/env.cc +++ b/src/env.cc @@ -95,8 +95,7 @@ void AsyncHooks::push_async_context(double async_id, } uint32_t offset = fields_[kStackLength]; - if (offset * 2 >= async_ids_stack_.Length()) - grow_async_ids_stack(); + if (offset * 2 >= async_ids_stack_.Length()) grow_async_ids_stack(); async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId]; async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId]; fields_[kStackLength] += 1; @@ -138,8 +137,7 @@ bool AsyncHooks::pop_async_context(double async_id) { if (LIKELY(offset < native_execution_async_resources_.size() && !native_execution_async_resources_[offset].IsEmpty())) { #ifdef DEBUG - for (uint32_t i = offset + 1; - i < native_execution_async_resources_.size(); + for (uint32_t i = offset + 1; i < native_execution_async_resources_.size(); i++) { CHECK(native_execution_async_resources_[i].IsEmpty()); } @@ -167,10 +165,10 @@ void AsyncHooks::clear_async_id_stack() { Isolate* isolate = env()->isolate(); HandleScope handle_scope(isolate); if (!js_execution_async_resources_.IsEmpty()) { - USE(PersistentToLocal::Strong(js_execution_async_resources_)->Set( - env()->context(), - env()->length_string(), - Integer::NewFromUnsigned(isolate, 0))); + USE(PersistentToLocal::Strong(js_execution_async_resources_) + ->Set(env()->context(), + env()->length_string(), + Integer::NewFromUnsigned(isolate, 0))); } native_execution_async_resources_.clear(); native_execution_async_resources_.shrink_to_fit(); @@ -181,19 +179,18 @@ void AsyncHooks::clear_async_id_stack() { } void AsyncHooks::AddContext(Local ctx) { - ctx->SetPromiseHooks( - js_promise_hooks_[0].IsEmpty() ? - Local() : - PersistentToLocal::Strong(js_promise_hooks_[0]), - js_promise_hooks_[1].IsEmpty() ? - Local() : - PersistentToLocal::Strong(js_promise_hooks_[1]), - js_promise_hooks_[2].IsEmpty() ? - Local() : - PersistentToLocal::Strong(js_promise_hooks_[2]), - js_promise_hooks_[3].IsEmpty() ? - Local() : - PersistentToLocal::Strong(js_promise_hooks_[3])); + ctx->SetPromiseHooks(js_promise_hooks_[0].IsEmpty() + ? Local() + : PersistentToLocal::Strong(js_promise_hooks_[0]), + js_promise_hooks_[1].IsEmpty() + ? Local() + : PersistentToLocal::Strong(js_promise_hooks_[1]), + js_promise_hooks_[2].IsEmpty() + ? Local() + : PersistentToLocal::Strong(js_promise_hooks_[2]), + js_promise_hooks_[3].IsEmpty() + ? Local() + : PersistentToLocal::Strong(js_promise_hooks_[3])); size_t id = contexts_.size(); contexts_.resize(id + 1); @@ -209,8 +206,7 @@ void AsyncHooks::RemoveContext(Local ctx) { [&](auto&& el) { return el.IsEmpty(); }), contexts_.end()); for (auto it = contexts_.begin(); it != contexts_.end(); it++) { - Local saved_context = - PersistentToLocal::Weak(isolate, *it); + Local saved_context = PersistentToLocal::Weak(isolate, *it); if (saved_context == ctx) { it->Reset(); contexts_.erase(it); @@ -227,14 +223,14 @@ AsyncHooks::DefaultTriggerAsyncIdScope::DefaultTriggerAsyncIdScope( } old_default_trigger_async_id_ = - async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; + async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = - default_trigger_async_id; + default_trigger_async_id; } AsyncHooks::DefaultTriggerAsyncIdScope::~DefaultTriggerAsyncIdScope() { async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = - old_default_trigger_async_id_; + old_default_trigger_async_id_; } AsyncHooks::DefaultTriggerAsyncIdScope::DefaultTriggerAsyncIdScope( @@ -435,11 +431,11 @@ void TrackingTraceStateObserver::UpdateTraceCategoryState() { void Environment::AssignToContext(Local context, const ContextInfo& info) { - context->SetAlignedPointerInEmbedderData( - ContextEmbedderIndex::kEnvironment, this); + context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kEnvironment, + this); // Used by Environment::GetCurrent to know that we are on a node context. - context->SetAlignedPointerInEmbedderData( - ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr); + context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kContextTag, + Environment::kNodeContextTagPtr); // Used to retrieve bindings context->SetAlignedPointerInEmbedderData( ContextEmbedderIndex::kBindingListIndex, &(this->bindings_)); @@ -452,7 +448,8 @@ void Environment::AssignToContext(Local context, } void Environment::TryLoadAddon( - const char* filename, int flags, + const char* filename, + int flags, const std::function& was_loaded) { loaded_addons_.emplace_back(filename, flags); if (!was_loaded(&loaded_addons_.back())) { @@ -485,8 +482,7 @@ void Environment::add_refs(int64_t diff) { uv_ref(reinterpret_cast(&task_queues_async_)); } -uv_buf_t Environment::allocate_managed_buffer( - const size_t suggested_size) { +uv_buf_t Environment::allocate_managed_buffer(const size_t suggested_size) { NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data()); std::unique_ptr bs = v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size); @@ -528,7 +524,8 @@ void Environment::SetMethod(Local that, v8::FunctionCallback callback) { Local context = isolate()->GetCurrentContext(); Local function = - NewFunctionTemplate(callback, Local(), + NewFunctionTemplate(callback, + Local(), v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect) ->GetFunction(context) @@ -565,7 +562,8 @@ void Environment::SetMethodNoSideEffect(Local that, v8::FunctionCallback callback) { Local context = isolate()->GetCurrentContext(); Local function = - NewFunctionTemplate(callback, Local(), + NewFunctionTemplate(callback, + Local(), v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasNoSideEffect) ->GetFunction(context) @@ -583,7 +581,9 @@ void Environment::SetProtoMethod(Local that, v8::FunctionCallback callback) { Local signature = v8::Signature::New(isolate(), that); Local t = - NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, + NewFunctionTemplate(callback, + signature, + v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; @@ -593,13 +593,14 @@ void Environment::SetProtoMethod(Local that, t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility. } -void Environment::SetProtoMethodNoSideEffect( - Local that, - const char* name, - v8::FunctionCallback callback) { +void Environment::SetProtoMethodNoSideEffect(Local that, + const char* name, + v8::FunctionCallback callback) { Local signature = v8::Signature::New(isolate(), that); Local t = - NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, + NewFunctionTemplate(callback, + signature, + v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasNoSideEffect); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; @@ -614,7 +615,9 @@ void Environment::SetInstanceMethod(Local that, v8::FunctionCallback callback) { Local signature = v8::Signature::New(isolate(), that); Local t = - NewFunctionTemplate(callback, signature, v8::ConstructorBehavior::kThrow, + NewFunctionTemplate(callback, + signature, + v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect); // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; @@ -637,10 +640,8 @@ void Environment::SetConstructorFunction(Local that, SetConstructorFunctionFlag flag) { if (LIKELY(flag == SetConstructorFunctionFlag::SET_CLASS_NAME)) tmpl->SetClassName(name); - that->Set( - context(), - name, - tmpl->GetFunction(context()).ToLocalChecked()).Check(); + that->Set(context(), name, tmpl->GetFunction(context()).ToLocalChecked()) + .Check(); } void Environment::CreateProperties() { @@ -2126,9 +2127,8 @@ BaseObject::BaseObject(Environment* env, Local object) : persistent_handle_(env->isolate(), object), env_(env) { CHECK_EQ(false, object.IsEmpty()); CHECK_GT(object->InternalFieldCount(), 0); - object->SetAlignedPointerInInternalField( - BaseObject::kSlot, - static_cast(this)); + object->SetAlignedPointerInInternalField(BaseObject::kSlot, + static_cast(this)); env->AddCleanupHook(DeleteMe, static_cast(this)); env->modify_base_object_count(1); } @@ -2141,8 +2141,7 @@ BaseObject::~BaseObject() { PointerData* metadata = pointer_data(); CHECK_EQ(metadata->strong_ptr_count, 0); metadata->self = nullptr; - if (metadata->weak_ptr_count == 0) - delete metadata; + if (metadata->weak_ptr_count == 0) delete metadata; } if (persistent_handle_.IsEmpty()) { @@ -2174,7 +2173,8 @@ void BaseObject::MakeWeak() { CHECK_IMPLIES(obj->has_pointer_data(), obj->pointer_data()->strong_ptr_count == 0); obj->OnGCCollect(); - }, WeakCallbackType::kParameter); + }, + WeakCallbackType::kParameter); } void BaseObject::LazilyInitializedJSTemplateConstructor( @@ -2184,13 +2184,12 @@ void BaseObject::LazilyInitializedJSTemplateConstructor( args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); } -Local -BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { +Local BaseObject::MakeLazilyInitializedJSTemplate( + Environment* env) { Local t = env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor); t->Inherit(BaseObject::GetConstructorTemplate(env)); - t->InstanceTemplate()->SetInternalFieldCount( - BaseObject::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(BaseObject::kInternalFieldCount); return t; } diff --git a/src/env.h b/src/env.h index e673799d4715f5..803f10fab182f5 100644 --- a/src/env.h +++ b/src/env.h @@ -742,7 +742,8 @@ class AsyncHooks : public MemoryRetainer { // NB: This call does not take (co-)ownership of `execution_async_resource`. // The lifetime of the `v8::Local<>` pointee must last until // `pop_async_context()` or `clear_async_id_stack()` are called. - void push_async_context(double async_id, double trigger_async_id, + void push_async_context(double async_id, + double trigger_async_id, v8::Local execution_async_resource); bool pop_async_context(double async_id); void clear_async_id_stack(); // Used in fatal exceptions. @@ -1134,7 +1135,8 @@ class Environment : public MemoryRetainer { inline v8::Isolate* isolate() const; inline uv_loop_t* event_loop() const; - void TryLoadAddon(const char* filename, int flags, + void TryLoadAddon(const char* filename, + int flags, const std::function& was_loaded); static inline Environment* from_timer_handle(uv_timer_t* handle);