JSInternalPromise.cpp [plain text]
#include "config.h"
#include "JSInternalPromise.h"
#include "BuiltinNames.h"
#include "JSCInlines.h"
namespace JSC {
const ClassInfo JSInternalPromise::s_info = { "InternalPromise", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSInternalPromise) };
JSInternalPromise* JSInternalPromise::create(VM& vm, Structure* structure)
{
JSInternalPromise* promise = new (NotNull, allocateCell<JSInternalPromise>(vm.heap)) JSInternalPromise(vm, structure);
promise->finishCreation(vm);
return promise;
}
JSInternalPromise* JSInternalPromise::createWithInitialValues(VM& vm, Structure* structure)
{
return create(vm, structure);
}
Structure* JSInternalPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(JSPromiseType, StructureFlags), info());
}
JSInternalPromise::JSInternalPromise(VM& vm, Structure* structure)
: Base(vm, structure)
{
}
JSInternalPromise* JSInternalPromise::then(JSGlobalObject* globalObject, JSFunction* onFulfilled, JSFunction* onRejected)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSObject* function = jsCast<JSObject*>(get(globalObject, vm.propertyNames->builtinNames().thenPublicName()));
RETURN_IF_EXCEPTION(scope, nullptr);
auto callData = JSC::getCallData(vm, function);
ASSERT(callData.type != CallData::Type::None);
MarkedArgumentBuffer arguments;
arguments.append(onFulfilled ? onFulfilled : jsUndefined());
arguments.append(onRejected ? onRejected : jsUndefined());
ASSERT(!arguments.hasOverflowed());
RELEASE_AND_RETURN(scope, jsCast<JSInternalPromise*>(call(globalObject, function, callData, this, arguments)));
}
}