1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

LibJS: Use OrdinaryCreateFromConstructor() in a bunch of constructors

Resolves various FIXMEs :^)
This commit is contained in:
Linus Groh 2021-06-20 01:09:39 +01:00 committed by Andreas Kling
parent e5753443ae
commit 8f6ac0db1c
16 changed files with 173 additions and 102 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -50,15 +51,21 @@ Value PromiseConstructor::call()
}
// 27.2.3.1 Promise ( executor ), https://tc39.es/ecma262/#sec-promise-executor
Value PromiseConstructor::construct(Function&)
Value PromiseConstructor::construct(Function& new_target)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
auto executor = vm.argument(0);
if (!executor.is_function()) {
vm.throw_exception<TypeError>(global_object(), ErrorType::PromiseExecutorNotAFunction);
vm.throw_exception<TypeError>(global_object, ErrorType::PromiseExecutorNotAFunction);
return {};
}
auto* promise = Promise::create(global_object());
auto* promise = ordinary_create_from_constructor<Promise>(global_object, new_target, &GlobalObject::promise_prototype);
if (vm.exception())
return {};
auto [resolve_function, reject_function] = promise->create_resolving_functions();
auto completion_value = vm.call(executor.as_function(), js_undefined(), &resolve_function, &reject_function);