summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-11 13:55:16 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-12 01:40:56 +0200
commita41d0d23f94464f14b7b48f8cf4ebe0d4b5ba5cb (patch)
tree2a512666d3222a45a359f49b47de486a78f59494 /Userland/Libraries
parentb749194e703a47686dad98834b2aa09cec52bdee (diff)
downloadserenity-a41d0d23f94464f14b7b48f8cf4ebe0d4b5ba5cb.zip
LibJS: Convert Promise.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromisePrototype.h6
2 files changed, 5 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
index c343302266..3ea98179ee 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp
@@ -17,7 +17,7 @@
namespace JS {
PromisePrototype::PromisePrototype(GlobalObject& global_object)
- : Object(*global_object.object_prototype())
+ : PrototypeObject(*global_object.object_prototype())
{
}
@@ -35,22 +35,10 @@ void PromisePrototype::initialize(GlobalObject& global_object)
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Promise.as_string()), Attribute::Configurable);
}
-static Promise* promise_from(VM& vm, GlobalObject& global_object)
-{
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object)
- return nullptr;
- if (!is<Promise>(this_object)) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, vm.names.Promise);
- return nullptr;
- }
- return static_cast<Promise*>(this_object);
-}
-
// 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then
JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::then)
{
- auto* promise = promise_from(vm, global_object);
+ auto* promise = typed_this_object(global_object);
if (!promise)
return {};
auto on_fulfilled = vm.argument(0);
diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.h b/Userland/Libraries/LibJS/Runtime/PromisePrototype.h
index 15c33da171..102c3443cd 100644
--- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.h
@@ -6,12 +6,12 @@
#pragma once
-#include <LibJS/Runtime/Object.h>
+#include <LibJS/Runtime/PrototypeObject.h>
namespace JS {
-class PromisePrototype final : public Object {
- JS_OBJECT(PromisePrototype, Object);
+class PromisePrototype final : public PrototypeObject<PromisePrototype, Promise> {
+ JS_PROTOTYPE_OBJECT(PromisePrototype, Promise, Promise);
public:
PromisePrototype(GlobalObject&);