Skip to content

Commit f460362

Browse files
joyeecheungUlisesGascon
authored andcommitted
src: remove C++ WeakReference implementation
PR-URL: #49053 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent c12711e commit f460362

7 files changed

+1
-177
lines changed

node.gyp

-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@
255255
'src/node_stat_watcher.h',
256256
'src/node_union_bytes.h',
257257
'src/node_url.h',
258-
'src/node_util.h',
259258
'src/node_version.h',
260259
'src/node_v8.h',
261260
'src/node_v8_platform-inl.h',

src/base_object_types.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace node {
2828
// The first argument should match what the type passes to
2929
// SET_OBJECT_ID(), the second argument should match the C++ class
3030
// name.
31-
#define SERIALIZABLE_NON_BINDING_TYPES(V) \
32-
V(util_weak_reference, util::WeakReference)
31+
#define SERIALIZABLE_NON_BINDING_TYPES(V)
3332

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

src/inspector/node_string.cc

-1
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

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "node_process.h"
2323
#include "node_snapshot_builder.h"
2424
#include "node_url.h"
25-
#include "node_util.h"
2625
#include "node_v8.h"
2726
#include "node_v8_platform-inl.h"
2827
#include "timers.h"

src/node_util.cc

-119
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"
@@ -17,8 +16,6 @@ using v8::CFunction;
1716
using v8::Context;
1817
using v8::External;
1918
using v8::FunctionCallbackInfo;
20-
using v8::FunctionTemplate;
21-
using v8::HandleScope;
2219
using v8::IndexFilter;
2320
using v8::Integer;
2421
using v8::Isolate;
@@ -201,109 +198,6 @@ void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
201198
args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
202199
}
203200

204-
WeakReference::WeakReference(Realm* realm,
205-
Local<Object> object,
206-
Local<Object> target)
207-
: WeakReference(realm, object, target, 0) {}
208-
209-
WeakReference::WeakReference(Realm* realm,
210-
Local<Object> object,
211-
Local<Object> target,
212-
uint64_t reference_count)
213-
: SnapshotableObject(realm, object, type_int),
214-
reference_count_(reference_count) {
215-
MakeWeak();
216-
if (!target.IsEmpty()) {
217-
target_.Reset(realm->isolate(), target);
218-
if (reference_count_ == 0) {
219-
target_.SetWeak();
220-
}
221-
}
222-
}
223-
224-
bool WeakReference::PrepareForSerialization(Local<Context> context,
225-
v8::SnapshotCreator* creator) {
226-
if (target_.IsEmpty()) {
227-
target_index_ = 0;
228-
return true;
229-
}
230-
231-
// Users can still hold strong references to target in addition to the
232-
// reference that we manage here, and they could expect that the referenced
233-
// object remains the same as long as that external strong reference
234-
// is alive. Since we have no way to know if there is any other reference
235-
// keeping the target alive, the best we can do to maintain consistency is to
236-
// simply save a reference to the target in the snapshot (effectively making
237-
// it strong) during serialization, and restore it during deserialization.
238-
// If there's no known counted reference from our side, we'll make the
239-
// reference here weak upon deserialization so that it can be GC'ed if users
240-
// do not hold additional references to it.
241-
Local<Object> target = target_.Get(context->GetIsolate());
242-
target_index_ = creator->AddData(context, target);
243-
DCHECK_NE(target_index_, 0);
244-
target_.Reset();
245-
return true;
246-
}
247-
248-
InternalFieldInfoBase* WeakReference::Serialize(int index) {
249-
DCHECK_IS_SNAPSHOT_SLOT(index);
250-
InternalFieldInfo* info =
251-
InternalFieldInfoBase::New<InternalFieldInfo>(type());
252-
info->target = target_index_;
253-
info->reference_count = reference_count_;
254-
return info;
255-
}
256-
257-
void WeakReference::Deserialize(Local<Context> context,
258-
Local<Object> holder,
259-
int index,
260-
InternalFieldInfoBase* info) {
261-
DCHECK_IS_SNAPSHOT_SLOT(index);
262-
HandleScope scope(context->GetIsolate());
263-
264-
InternalFieldInfo* weak_info = reinterpret_cast<InternalFieldInfo*>(info);
265-
Local<Object> target;
266-
if (weak_info->target != 0) {
267-
target = context->GetDataFromSnapshotOnce<Object>(weak_info->target)
268-
.ToLocalChecked();
269-
}
270-
new WeakReference(
271-
Realm::GetCurrent(context), holder, target, weak_info->reference_count);
272-
}
273-
274-
void WeakReference::New(const FunctionCallbackInfo<Value>& args) {
275-
Realm* realm = Realm::GetCurrent(args);
276-
CHECK(args.IsConstructCall());
277-
CHECK(args[0]->IsObject());
278-
new WeakReference(realm, args.This(), args[0].As<Object>());
279-
}
280-
281-
void WeakReference::Get(const FunctionCallbackInfo<Value>& args) {
282-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
283-
Isolate* isolate = args.GetIsolate();
284-
if (!weak_ref->target_.IsEmpty())
285-
args.GetReturnValue().Set(weak_ref->target_.Get(isolate));
286-
}
287-
288-
void WeakReference::IncRef(const FunctionCallbackInfo<Value>& args) {
289-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
290-
weak_ref->reference_count_++;
291-
if (weak_ref->target_.IsEmpty()) return;
292-
if (weak_ref->reference_count_ == 1) weak_ref->target_.ClearWeak();
293-
args.GetReturnValue().Set(
294-
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
295-
}
296-
297-
void WeakReference::DecRef(const FunctionCallbackInfo<Value>& args) {
298-
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
299-
CHECK_GE(weak_ref->reference_count_, 1);
300-
weak_ref->reference_count_--;
301-
if (weak_ref->target_.IsEmpty()) return;
302-
if (weak_ref->reference_count_ == 0) weak_ref->target_.SetWeak();
303-
args.GetReturnValue().Set(
304-
v8::Number::New(args.GetIsolate(), weak_ref->reference_count_));
305-
}
306-
307201
static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
308202
// TODO(anonrig): We can use an enum here and then create the array in the
309203
// binding, which will remove the hard-coding in C++ and JS land.
@@ -391,10 +285,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
391285
registry->Register(GetExternalValue);
392286
registry->Register(Sleep);
393287
registry->Register(ArrayBufferViewHasBuffer);
394-
registry->Register(WeakReference::New);
395-
registry->Register(WeakReference::Get);
396-
registry->Register(WeakReference::IncRef);
397-
registry->Register(WeakReference::DecRef);
398288
registry->Register(GuessHandleType);
399289
registry->Register(FastGuessHandleType);
400290
registry->Register(fast_guess_handle_type_.GetTypeInfo());
@@ -494,15 +384,6 @@ void Initialize(Local<Object> target,
494384
env->should_abort_on_uncaught_toggle().GetJSArray())
495385
.FromJust());
496386

497-
Local<FunctionTemplate> weak_ref =
498-
NewFunctionTemplate(isolate, WeakReference::New);
499-
weak_ref->InstanceTemplate()->SetInternalFieldCount(
500-
WeakReference::kInternalFieldCount);
501-
SetProtoMethod(isolate, weak_ref, "get", WeakReference::Get);
502-
SetProtoMethod(isolate, weak_ref, "incRef", WeakReference::IncRef);
503-
SetProtoMethod(isolate, weak_ref, "decRef", WeakReference::DecRef);
504-
SetConstructorFunction(context, target, "WeakReference", weak_ref);
505-
506387
SetFastMethodNoSideEffect(context,
507388
target,
508389
"guessHandleType",

src/node_util.h

-52
This file was deleted.

src/util.cc

-1
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)