|
@@ -18,6 +18,8 @@ void WeakRefPrototype::initialize(GlobalObject& global_object)
|
|
|
auto& vm = this->vm();
|
|
|
Object::initialize(global_object);
|
|
|
|
|
|
+ define_native_function(vm.names.deref, deref, 0, Attribute::Writable | Attribute::Configurable);
|
|
|
+
|
|
|
define_property(vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakRef), Attribute::Configurable);
|
|
|
}
|
|
|
|
|
@@ -25,4 +27,19 @@ WeakRefPrototype::~WeakRefPrototype()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+// 26.1.3.2 WeakRef.prototype.deref ( ), https://tc39.es/ecma262/#sec-weak-ref.prototype.deref
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(WeakRefPrototype::deref)
|
|
|
+{
|
|
|
+ auto* this_object = vm.this_value(global_object).to_object(global_object);
|
|
|
+ if (!this_object)
|
|
|
+ return {};
|
|
|
+ if (!is<WeakRef>(this_object)) {
|
|
|
+ vm.throw_exception<TypeError>(global_object, ErrorType::NotA, "WeakRef");
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+ auto& weak_ref = static_cast<WeakRef&>(*this_object);
|
|
|
+ weak_ref.update_execution_generation();
|
|
|
+ return weak_ref.value() ?: js_undefined();
|
|
|
+}
|
|
|
+
|
|
|
}
|