summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/weak-ref.tq
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2020-10-15 20:17:08 +0200
committerMichaël Zasso <targos@protonmail.com>2020-10-18 20:16:47 +0200
commita1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce (patch)
treeabc7d41c12f1495b1208fa4449cb2508c92c5e85 /deps/v8/src/builtins/weak-ref.tq
parent089d654dd85f8e548597329f60a41d6029260caa (diff)
downloadnode-new-a1d639ba5de4ff34e34fb575fbb6cc1d41ec3cce.tar.gz
deps: update V8 to 8.6.395
PR-URL: https://github.com/nodejs/node/pull/35415 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/src/builtins/weak-ref.tq')
-rw-r--r--deps/v8/src/builtins/weak-ref.tq59
1 files changed, 59 insertions, 0 deletions
diff --git a/deps/v8/src/builtins/weak-ref.tq b/deps/v8/src/builtins/weak-ref.tq
new file mode 100644
index 0000000000..18385e52db
--- /dev/null
+++ b/deps/v8/src/builtins/weak-ref.tq
@@ -0,0 +1,59 @@
+// Copyright 2020 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+namespace runtime {
+
+extern runtime JSWeakRefAddToKeptObjects(implicit context: Context)(JSReceiver);
+
+} // namespace runtime
+
+namespace weakref {
+
+transitioning javascript builtin
+WeakRefConstructor(
+ js-implicit context: NativeContext, receiver: JSAny, newTarget: JSAny,
+ target: JSFunction)(weakTarget: JSAny): JSWeakRef {
+ // 1. If NewTarget is undefined, throw a TypeError exception.
+ if (newTarget == Undefined) {
+ ThrowTypeError(MessageTemplate::kConstructorNotFunction, 'WeakRef');
+ }
+ // 2. If Type(target) is not Object, throw a TypeError exception.
+ const weakTarget = Cast<JSReceiver>(weakTarget) otherwise
+ ThrowTypeError(
+ MessageTemplate::kWeakRefsWeakRefConstructorTargetMustBeObject);
+ // 3. Let weakRef be ? OrdinaryCreateFromConstructor(NewTarget,
+ // "%WeakRefPrototype%", « [[WeakRefTarget]] »).
+ const map = GetDerivedMap(target, UnsafeCast<JSReceiver>(newTarget));
+ const weakRef = UnsafeCast<JSWeakRef>(AllocateFastOrSlowJSObjectFromMap(map));
+ // 4. Perfom ! AddToKeptObjects(target).
+ runtime::JSWeakRefAddToKeptObjects(weakTarget);
+ // 5. Set weakRef.[[WeakRefTarget]] to target.
+ weakRef.target = weakTarget;
+ // 6. Return weakRef.
+ return weakRef;
+}
+
+transitioning javascript builtin
+WeakRefDeref(js-implicit context: NativeContext, receiver: JSAny)(): JSAny {
+ // 1. Let weakRef be the this value.
+ // 2. Perform ? RequireInternalSlot(weakRef, [[WeakRefTarget]]).
+ const weakRef = Cast<JSWeakRef>(receiver) otherwise
+ ThrowTypeError(
+ MessageTemplate::kIncompatibleMethodReceiver, 'WeakRef.prototype.deref',
+ receiver);
+ // 3. Let target be the value of weakRef.[[WeakRefTarget]].
+ const target = weakRef.target;
+ // 4. If target is not empty,
+ // a. Perform ! AddToKeptObjects(target).
+ // b. Return target.
+ // 5. Return undefined.
+ if (target != Undefined) {
+ // JSWeakRefAddToKeptObjects might allocate and cause a GC, but it
+ // won't clear `target` since we hold it here on the stack.
+ runtime::JSWeakRefAddToKeptObjects(UnsafeCast<JSReceiver>(target));
+ }
+ return target;
+}
+
+} // namespace weakrefs