diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/JSPromise.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSPromise.cpp')
-rw-r--r-- | Source/JavaScriptCore/runtime/JSPromise.cpp | 137 |
1 files changed, 27 insertions, 110 deletions
diff --git a/Source/JavaScriptCore/runtime/JSPromise.cpp b/Source/JavaScriptCore/runtime/JSPromise.cpp index 9f182c954..958d45b0c 100644 --- a/Source/JavaScriptCore/runtime/JSPromise.cpp +++ b/Source/JavaScriptCore/runtime/JSPromise.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2013, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,27 +26,20 @@ #include "config.h" #include "JSPromise.h" -#if ENABLE(PROMISES) - +#include "BuiltinNames.h" #include "Error.h" -#include "JSCJSValueInlines.h" -#include "JSCellInlines.h" +#include "JSCInlines.h" #include "JSPromiseConstructor.h" -#include "JSPromiseReaction.h" #include "Microtask.h" -#include "SlotVisitorInlines.h" -#include "StructureInlines.h" namespace JSC { -static void triggerPromiseReactions(VM&, JSGlobalObject*, Vector<WriteBarrier<JSPromiseReaction>>&, JSValue); - -const ClassInfo JSPromise::s_info = { "Promise", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSPromise) }; +const ClassInfo JSPromise::s_info = { "Promise", &Base::s_info, 0, CREATE_METHOD_TABLE(JSPromise) }; -JSPromise* JSPromise::create(VM& vm, JSGlobalObject* globalObject, JSPromiseConstructor* constructor) +JSPromise* JSPromise::create(VM& vm, Structure* structure) { - JSPromise* promise = new (NotNull, allocateCell<JSPromise>(vm.heap)) JSPromise(vm, globalObject->promiseStructure()); - promise->finishCreation(vm, constructor); + JSPromise* promise = new (NotNull, allocateCell<JSPromise>(vm.heap)) JSPromise(vm, structure); + promise->finishCreation(vm); return promise; } @@ -56,116 +49,40 @@ Structure* JSPromise::createStructure(VM& vm, JSGlobalObject* globalObject, JSVa } JSPromise::JSPromise(VM& vm, Structure* structure) - : JSDestructibleObject(vm, structure) - , m_status(Status::Unresolved) + : Base(vm, structure) { } -void JSPromise::finishCreation(VM& vm, JSPromiseConstructor* constructor) +void JSPromise::finishCreation(VM& vm) { Base::finishCreation(vm); - ASSERT(inherits(info())); - - m_constructor.set(vm, this, constructor); -} - -void JSPromise::destroy(JSCell* cell) -{ - static_cast<JSPromise*>(cell)->JSPromise::~JSPromise(); -} - -void JSPromise::visitChildren(JSCell* cell, SlotVisitor& visitor) -{ - JSPromise* thisObject = jsCast<JSPromise*>(cell); - ASSERT_GC_OBJECT_INHERITS(thisObject, info()); - COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); - ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); - - Base::visitChildren(thisObject, visitor); - - visitor.append(&thisObject->m_result); - visitor.append(&thisObject->m_constructor); - visitor.append(thisObject->m_resolveReactions.begin(), thisObject->m_resolveReactions.end()); - visitor.append(thisObject->m_rejectReactions.begin(), thisObject->m_rejectReactions.end()); -} - -void JSPromise::reject(VM& vm, JSValue reason) -{ - // 1. If the value of promise's internal slot [[PromiseStatus]] is not "unresolved", return. - if (m_status != Status::Unresolved) - return; - - DeferGC deferGC(vm.heap); - - // 2. Let 'reactions' be the value of promise's [[RejectReactions]] internal slot. - Vector<WriteBarrier<JSPromiseReaction>> reactions; - reactions.swap(m_rejectReactions); - - // 3. Set the value of promise's [[Result]] internal slot to reason. - m_result.set(vm, this, reason); - - // 4. Set the value of promise's [[ResolveReactions]] internal slot to undefined. - m_resolveReactions.clear(); - - // 5. Set the value of promise's [[RejectReactions]] internal slot to undefined. - // NOTE: Handled by the swap above. - - // 6. Set the value of promise's [[PromiseStatus]] internal slot to "has-rejection". - m_status = Status::HasRejection; - - // 7. Return the result of calling TriggerPromiseReactions(reactions, reason). - triggerPromiseReactions(vm, globalObject(), reactions, reason); + putDirect(vm, vm.propertyNames->builtinNames().promiseStatePrivateName(), jsNumber(static_cast<unsigned>(Status::Pending))); + putDirect(vm, vm.propertyNames->builtinNames().promiseReactionsPrivateName(), jsUndefined()); + putDirect(vm, vm.propertyNames->builtinNames().promiseResultPrivateName(), jsUndefined()); } -void JSPromise::resolve(VM& vm, JSValue resolution) +void JSPromise::initialize(ExecState* exec, JSGlobalObject* globalObject, JSValue executor) { - // 1. If the value of promise's internal slot [[PromiseStatus]] is not "unresolved", return. - if (m_status != Status::Unresolved) - return; - - DeferGC deferGC(vm.heap); - - // 2. Let 'reactions' be the value of promise's [[ResolveReactions]] internal slot. - Vector<WriteBarrier<JSPromiseReaction>> reactions; - reactions.swap(m_resolveReactions); - - // 3. Set the value of promise's [[Result]] internal slot to resolution. - m_result.set(vm, this, resolution); - - // 4. Set the value of promise's [[ResolveReactions]] internal slot to undefined. - // NOTE: Handled by the swap above. - - // 5. Set the value of promise's [[RejectReactions]] internal slot to undefined. - m_rejectReactions.clear(); - - // 6. Set the value of promise's [[PromiseStatus]] internal slot to "has-resolution". - m_status = Status::HasResolution; - - // 7. Return the result of calling TriggerPromiseReactions(reactions, resolution). - triggerPromiseReactions(vm, globalObject(), reactions, resolution); + JSFunction* initializePromise = globalObject->initializePromiseFunction(); + CallData callData; + CallType callType = JSC::getCallData(initializePromise, callData); + ASSERT(callType != CallType::None); + + MarkedArgumentBuffer arguments; + arguments.append(executor); + call(exec, initializePromise, callType, callData, this, arguments); } -void JSPromise::appendResolveReaction(VM& vm, JSPromiseReaction* reaction) +auto JSPromise::status(VM& vm) const -> Status { - m_resolveReactions.append(WriteBarrier<JSPromiseReaction>(vm, this, reaction)); + JSValue value = getDirect(vm, vm.propertyNames->builtinNames().promiseStatePrivateName()); + ASSERT(value.isUInt32()); + return static_cast<Status>(value.asUInt32()); } -void JSPromise::appendRejectReaction(VM& vm, JSPromiseReaction* reaction) +JSValue JSPromise::result(VM& vm) const { - m_rejectReactions.append(WriteBarrier<JSPromiseReaction>(vm, this, reaction)); -} - -void triggerPromiseReactions(VM& vm, JSGlobalObject* globalObject, Vector<WriteBarrier<JSPromiseReaction>>& reactions, JSValue argument) -{ - // 1. Repeat for each reaction in reactions, in original insertion order - for (auto& reaction : reactions) { - // i. Call QueueMicrotask(ExecutePromiseReaction, (reaction, argument)). - globalObject->queueMicrotask(createExecutePromiseReactionMicrotask(vm, reaction.get(), argument)); - } - - // 2. Return. + return getDirect(vm, vm.propertyNames->builtinNames().promiseResultPrivateName()); } } // namespace JSC - -#endif // ENABLE(PROMISES) |