Skip to content

Commit 07ea1d6

Browse files
committed
src: remove C++ WeakReference implementation
1 parent 896367a commit 07ea1d6

File tree

7 files changed

+0
-174
lines changed

7 files changed

+0
-174
lines changed

node.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@
253253
'src/node_stat_watcher.h',
254254
'src/node_union_bytes.h',
255255
'src/node_url.h',
256-
'src/node_util.h',
257256
'src/node_version.h',
258257
'src/node_v8.h',
259258
'src/node_v8_platform-inl.h',

src/base_object_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace node {
2929
// SET_OBJECT_ID(), the second argument should match the C++ class
3030
// name.
3131
#define SERIALIZABLE_NON_BINDING_TYPES(V) \
32-
V(util_weak_reference, util::WeakReference)
3332

3433
// Helper list of all binding data wrapper types.
3534
#define BINDING_TYPES(V) \

src/inspector/node_string.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "node_string.h"
22
#include "node/inspector/protocol/Protocol.h"
3-
#include "node_util.h"
43
#include "simdutf.h"
54
#include "util-inl.h"
65

src/node_snapshotable.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "node_process.h"
2222
#include "node_snapshot_builder.h"
2323
#include "node_url.h"
24-
#include "node_util.h"
2524
#include "node_v8.h"
2625
#include "node_v8_platform-inl.h"
2726
#include "timers.h"

src/node_util.cc

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "node_util.h"
21
#include "base_object-inl.h"
32
#include "node_errors.h"
43
#include "node_external_reference.h"
@@ -181,109 +180,6 @@ void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
181180
args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
182181
}
183182

184-
WeakReference::WeakReference(Realm* realm,
185-
Local<Object> object,
186-
Local<Object> target)
187-
: WeakReference(realm, object, target, 0) {}
188-
189-
WeakReference::WeakReference(Realm* realm,
190-
Local<Object> object,
191-
Local<Object> target,
192-
uint64_t reference_count)
193-
: SnapshotableObject(realm, object, type_int),
194-
reference_count_(reference_count) {
195-
MakeWeak();
196-
if (!target.IsEmpty()) {
197-
target_.Reset(realm->isolate(), target);
198-
if (reference_count_ == 0) {
199-
target_.SetWeak();
200-
}
201-
}
202-
}
203-
204-
bool WeakReference::PrepareForSerialization(Local<Context> context,
205-
v8::SnapshotCreator* creator) {
206-
if (target_.IsEmpty()) {
207-
target_index_ = 0;
208-
return true;
209-
}
210-
211-
// Users can still hold strong references to target in addition to the
212-
// reference that we manage here, and they could expect that the referenced
213-
// object remains the same as long as that external strong reference
214-
// is alive. Since we have no way to know if there is any other reference
215-
// keeping the target alive, the best we can do to maintain consistency is to
216-
// simply save a reference to the target in the snapshot (effectively making
217-
// it strong) during serialization, and restore it during deserialization.
218-
// If there's no known counted reference from our side, we'll make the
219-
// reference here weak upon deserialization so that it can be GC'ed if users
220-
// do not hold additional references to it.
221-
Local<Object> target = target_.Get(context->GetIsolate());
222-
target_index_ = creator->AddData(context, target);
223-
DCHECK_NE(target_index_, 0);
224-
target_.Reset();
225-
return true;
226-
}
227-
228-
InternalFieldInfoBase* WeakReference::Serialize(int index) {
229-
DCHECK_EQ(index, BaseObject::kEmbedderType);
230-
InternalFieldInfo* info =
231-
InternalFieldInfoBase::New<InternalFieldInfo>(type());
232-
info->target = target_index_;
233-
info->reference_count = reference_count_;
234-
return info;
235-
}
236-
237-
void WeakReference::Deserialize(Local<Context> context,
238-
Local<Object> holder,
239-
int index,
240-
InternalFieldInfoBase* info) {
241-
DCHECK_EQ(index, BaseObject::kEmbedderType);
242-
HandleScope scope(context->GetIsolate());
243-
244-
InternalFieldInfo* weak_info = reinterpret_cast<InternalFieldInfo*>(info);
245-
Local<Object> target;
246-
if (weak_info->target != 0) {
247-
target = context->GetDataFromSnapshotOnce<Object>(weak_info->target)
248-
.ToLocalChecked();
249-
}
250-
new WeakReference(
251-
Realm::GetCurrent(context), holder, target, weak_info->reference_count);
252-
}
253-
254-
void WeakReference::New(const FunctionCallbackInfo<Value>& args) {
255-
Realm* realm = Realm::GetCurrent(args);
256-
CHECK(args.IsConstructCall());
257-
CHECK(args[0]->IsObject());
258-
new WeakReference(realm, args.This(), args[0].As<Object>());
259-
}
260-
261-
void WeakReference::Get(const FunctionCallbackInfo<Value>& args) {
262-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
263-
Isolate* isolate = args.GetIsolate();
264-
if (!weak_ref->target_.IsEmpty())
265-
args.GetReturnValue().Set(weak_ref->target_.Get(isolate));
266-
}
267-
268-
void WeakReference::IncRef(const FunctionCallbackInfo<Value>& args) {
269-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
270-
weak_ref->reference_count_++;
271-
if (weak_ref->target_.IsEmpty()) return;
272-
if (weak_ref->reference_count_ == 1) weak_ref->target_.ClearWeak();
273-
args.GetReturnValue().Set(
274-
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
275-
}
276-
277-
void WeakReference::DecRef(const FunctionCallbackInfo<Value>& args) {
278-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
279-
CHECK_GE(weak_ref->reference_count_, 1);
280-
weak_ref->reference_count_--;
281-
if (weak_ref->target_.IsEmpty()) return;
282-
if (weak_ref->reference_count_ == 0) weak_ref->target_.SetWeak();
283-
args.GetReturnValue().Set(
284-
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
285-
}
286-
287183
static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
288184
Environment* env = Environment::GetCurrent(args);
289185
int fd;
@@ -400,10 +296,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
400296
registry->Register(GetExternalValue);
401297
registry->Register(Sleep);
402298
registry->Register(ArrayBufferViewHasBuffer);
403-
registry->Register(WeakReference::New);
404-
registry->Register(WeakReference::Get);
405-
registry->Register(WeakReference::IncRef);
406-
registry->Register(WeakReference::DecRef);
407299
registry->Register(GuessHandleType);
408300
registry->Register(FastGuessHandleType);
409301
registry->Register(fast_guess_handle_type_.GetTypeInfo());
@@ -515,15 +407,6 @@ void Initialize(Local<Object> target,
515407
env->should_abort_on_uncaught_toggle().GetJSArray())
516408
.FromJust());
517409

518-
Local<FunctionTemplate> weak_ref =
519-
NewFunctionTemplate(isolate, WeakReference::New);
520-
weak_ref->InstanceTemplate()->SetInternalFieldCount(
521-
WeakReference::kInternalFieldCount);
522-
SetProtoMethod(isolate, weak_ref, "get", WeakReference::Get);
523-
SetProtoMethod(isolate, weak_ref, "incRef", WeakReference::IncRef);
524-
SetProtoMethod(isolate, weak_ref, "decRef", WeakReference::DecRef);
525-
SetConstructorFunction(context, target, "WeakReference", weak_ref);
526-
527410
SetFastMethodNoSideEffect(context,
528411
target,
529412
"guessHandleType",

src/node_util.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/util.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "node_buffer.h"
2828
#include "node_errors.h"
2929
#include "node_internals.h"
30-
#include "node_util.h"
3130
#include "node_v8_platform-inl.h"
3231
#include "string_bytes.h"
3332
#include "uv.h"

0 commit comments

Comments
 (0)