summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Value.h
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-01 22:13:29 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-02 10:47:40 +0200
commitf418115f1bba2975d8cf8b086092b0df5ae507c9 (patch)
treebf16e3d655ac9c360ad8155655878bde16da7f66 /Userland/Libraries/LibJS/Runtime/Value.h
parent563712abcef5ca791bdbc09c4a02931fd709c7c9 (diff)
downloadserenity-f418115f1bba2975d8cf8b086092b0df5ae507c9.zip
LibJS: Add initial support for Promises
Almost a year after first working on this, it's finally done: an implementation of Promises for LibJS! :^) The core functionality is working and closely following the spec [1]. I mostly took the pseudo code and transformed it into C++ - if you read and understand it, you will know how the spec implements Promises; and if you read the spec first, the code will look very familiar. Implemented functions are: - Promise() constructor - Promise.prototype.then() - Promise.prototype.catch() - Promise.prototype.finally() - Promise.resolve() - Promise.reject() For the tests I added a new function to test-js's global object, runQueuedPromiseJobs(), which calls vm.run_queued_promise_jobs(). By design, queued jobs normally only run after the script was fully executed, making it improssible to test handlers in individual test() calls by default [2]. Subsequent commits include integrations into LibWeb and js(1) - pretty-printing, running queued promise jobs when necessary. This has an unusual amount of dbgln() statements, all hidden behind the PROMISE_DEBUG flag - I'm leaving them in for now as they've been very useful while debugging this, things can get quite complex with so many asynchronously executed functions. I've not extensively explored use of these APIs for promise-based functionality in LibWeb (fetch(), Notification.requestPermission() etc.), but we'll get there in due time. [1]: https://tc39.es/ecma262/#sec-promise-objects [2]: https://tc39.es/ecma262/#sec-jobs-and-job-queues
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Value.h')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h
index e763cfa0bf..4b8d42431e 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.h
+++ b/Userland/Libraries/LibJS/Runtime/Value.h
@@ -82,6 +82,7 @@ public:
bool is_cell() const { return is_string() || is_accessor() || is_object() || is_bigint() || is_symbol() || is_native_property(); }
bool is_array() const;
bool is_function() const;
+ bool is_constructor() const;
bool is_regexp(GlobalObject& global_object) const;
bool is_nan() const { return is_number() && __builtin_isnan(as_double()); }
@@ -377,6 +378,7 @@ bool same_value_non_numeric(Value lhs, Value rhs);
TriState abstract_relation(GlobalObject&, bool left_first, Value lhs, Value rhs);
Function* get_method(GlobalObject& global_object, Value, const PropertyName&);
size_t length_of_array_like(GlobalObject&, const Object&);
+Object* species_constructor(GlobalObject&, const Object&, Object& default_constructor);
}