|
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"
|
@@ -201,109 +200,6 @@ void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) {
|
201 | 200 | args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer());
|
202 | 201 | }
|
203 | 202 |
|
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_EQ(index, BaseObject::kEmbedderType); |
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_EQ(index, BaseObject::kEmbedderType); |
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 |
| - |
307 | 203 | static uint32_t GetUVHandleTypeCode(const uv_handle_type type) {
|
308 | 204 | // TODO(anonrig): We can use an enum here and then create the array in the
|
309 | 205 | // binding, which will remove the hard-coding in C++ and JS land.
|
@@ -391,10 +287,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
391 | 287 | registry->Register(GetExternalValue);
|
392 | 288 | registry->Register(Sleep);
|
393 | 289 | registry->Register(ArrayBufferViewHasBuffer);
|
394 |
| - registry->Register(WeakReference::New); |
395 |
| - registry->Register(WeakReference::Get); |
396 |
| - registry->Register(WeakReference::IncRef); |
397 |
| - registry->Register(WeakReference::DecRef); |
398 | 290 | registry->Register(GuessHandleType);
|
399 | 291 | registry->Register(FastGuessHandleType);
|
400 | 292 | registry->Register(fast_guess_handle_type_.GetTypeInfo());
|
@@ -508,15 +400,6 @@ void Initialize(Local<Object> target,
|
508 | 400 | env->should_abort_on_uncaught_toggle().GetJSArray())
|
509 | 401 | .FromJust());
|
510 | 402 |
|
511 |
| - Local<FunctionTemplate> weak_ref = |
512 |
| - NewFunctionTemplate(isolate, WeakReference::New); |
513 |
| - weak_ref->InstanceTemplate()->SetInternalFieldCount( |
514 |
| - WeakReference::kInternalFieldCount); |
515 |
| - SetProtoMethod(isolate, weak_ref, "get", WeakReference::Get); |
516 |
| - SetProtoMethod(isolate, weak_ref, "incRef", WeakReference::IncRef); |
517 |
| - SetProtoMethod(isolate, weak_ref, "decRef", WeakReference::DecRef); |
518 |
| - SetConstructorFunction(context, target, "WeakReference", weak_ref); |
519 |
| - |
520 | 403 | SetFastMethodNoSideEffect(context,
|
521 | 404 | target,
|
522 | 405 | "guessHandleType",
|
|
0 commit comments