Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: src/js/weak-collection.js

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/macros.py ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/weak-collection.js
diff --git a/src/js/weak-collection.js b/src/js/weak-collection.js
index f5092d29f59c71678e12d31a74f6c43b0562fb3e..76b43a7a6af0749d262cb1abf0d7e325369bb0d2 100644
--- a/src/js/weak-collection.js
+++ b/src/js/weak-collection.js
@@ -16,6 +16,7 @@ var GetHash;
var GlobalObject = global.Object;
var GlobalWeakMap = global.WeakMap;
var GlobalWeakSet = global.WeakSet;
+var GlobalWeakRef = global.WeakRef;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
@@ -185,4 +186,47 @@ utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [
"delete", WeakSetDelete
]);
+function WeakRefConstructor(target, finalizer, holdings) {
+ if (IS_UNDEFINED(new.target)) {
+ throw %make_type_error(kConstructorNotFunction, "WeakRef");
+ }
+
+ if (typeof target !== 'object') {
+ throw %make_type_error(kInvalidArgument);
+ }
+ if (typeof finalizer !== 'function') {
+ throw %make_type_error(kInvalidArgument);
+ }
+
+ %WeakRefInitialize(this, target, finalizer, holdings);
+}
+
+function WeakRefValue() {
+ if (!IS_WEAKREF(this)) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ 'WeakRef.prototype.value', this);
+ }
+ return %WeakRefValue(this);
+}
+function WeakRefClear() {
+ if (!IS_WEAKREF(this)) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ 'WeakRef.prototype.clear', this);
+ }
+ return %WeakRefClear(this);
+}
+%SetCode(GlobalWeakRef, WeakRefConstructor);
+%FunctionSetLength(GlobalWeakRef, 0);
+%FunctionSetPrototype(GlobalWeakRef, new GlobalObject());
+%AddNamedProperty(GlobalWeakRef.prototype, "constructor", GlobalWeakRef,
+ DONT_ENUM);
+%AddNamedProperty(GlobalWeakRef.prototype, toStringTagSymbol, "WeakRef",
+ DONT_ENUM | READ_ONLY);
+
+// Set up the non-enumerable functions on the WeakSet prototype object.
+utils.InstallFunctions(GlobalWeakRef.prototype, DONT_ENUM, [
+ "get", WeakRefValue,
+ "clear", WeakRefClear
+]);
+
})
« no previous file with comments | « src/js/macros.py ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698