|
1 |
| -#include "node_util.h" |
2 | 1 | #include "base_object-inl.h"
|
3 | 2 | #include "node_errors.h"
|
4 | 3 | #include "node_external_reference.h"
|
@@ -181,109 +180,6 @@ void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
|
181 | 180 | args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
|
182 | 181 | }
|
183 | 182 |
|
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 |
| - |
287 | 183 | static void GuessHandleType(const FunctionCallbackInfo<Value>& args) {
|
288 | 184 | Environment* env = Environment::GetCurrent(args);
|
289 | 185 | int fd;
|
@@ -400,10 +296,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
400 | 296 | registry->Register(GetExternalValue);
|
401 | 297 | registry->Register(Sleep);
|
402 | 298 | registry->Register(ArrayBufferViewHasBuffer);
|
403 |
| - registry->Register(WeakReference::New); |
404 |
| - registry->Register(WeakReference::Get); |
405 |
| - registry->Register(WeakReference::IncRef); |
406 |
| - registry->Register(WeakReference::DecRef); |
407 | 299 | registry->Register(GuessHandleType);
|
408 | 300 | registry->Register(FastGuessHandleType);
|
409 | 301 | registry->Register(fast_guess_handle_type_.GetTypeInfo());
|
@@ -515,15 +407,6 @@ void Initialize(Local<Object> target,
|
515 | 407 | env->should_abort_on_uncaught_toggle().GetJSArray())
|
516 | 408 | .FromJust());
|
517 | 409 |
|
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 |
| - |
527 | 410 | SetFastMethodNoSideEffect(context,
|
528 | 411 | target,
|
529 | 412 | "guessHandleType",
|
|
0 commit comments