1. 03 Jan, 2014 1 commit
    • weinig@apple.com's avatar
      Update Promises to the https://github.com/domenic/promises-unwrapping spec · 349af4e4
      weinig@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=120954
      
      Reviewed by Filip Pizlo.
      
      Source/JavaScriptCore: 
      
      Update Promises to the revised spec. Notable changes:
      - JSPromiseResolver is gone.
      - TaskContext has been renamed Microtask and now has a virtual run() function.
      - Instead of using custom InternalFunction subclasses, JSFunctions are used
        with PrivateName properties for internal slots.
      
      * CMakeLists.txt:
      * DerivedSources.make:
      * GNUmakefile.list.am:
      * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
      * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
      * JavaScriptCore.xcodeproj/project.pbxproj:
      * interpreter/CallFrame.h:
      (JSC::ExecState::promiseConstructorTable):
      * runtime/CommonIdentifiers.cpp:
      (JSC::CommonIdentifiers::CommonIdentifiers):
      * runtime/CommonIdentifiers.h:
      * runtime/JSGlobalObject.cpp:
      (JSC::JSGlobalObject::reset):
      (JSC::JSGlobalObject::visitChildren):
      (JSC::JSGlobalObject::queueMicrotask):
      * runtime/JSGlobalObject.h:
      (JSC::JSGlobalObject::promiseConstructor):
      (JSC::JSGlobalObject::promisePrototype):
      (JSC::JSGlobalObject::promiseStructure):
      * runtime/JSPromise.cpp:
      (JSC::JSPromise::create):
      (JSC::JSPromise::JSPromise):
      (JSC::JSPromise::finishCreation):
      (JSC::JSPromise::visitChildren):
      (JSC::JSPromise::reject):
      (JSC::JSPromise::resolve):
      (JSC::JSPromise::appendResolveReaction):
      (JSC::JSPromise::appendRejectReaction):
      (JSC::triggerPromiseReactions):
      * runtime/JSPromise.h:
      (JSC::JSPromise::status):
      (JSC::JSPromise::result):
      (JSC::JSPromise::constructor):
      * runtime/JSPromiseCallback.cpp: Removed.
      * runtime/JSPromiseCallback.h: Removed.
      * runtime/JSPromiseConstructor.cpp:
      (JSC::constructPromise):
      (JSC::JSPromiseConstructor::getCallData):
      (JSC::JSPromiseConstructorFuncCast):
      (JSC::JSPromiseConstructorFuncResolve):
      (JSC::JSPromiseConstructorFuncReject):
      * runtime/JSPromiseConstructor.h:
      * runtime/JSPromiseDeferred.cpp: Added.
      (JSC::JSPromiseDeferred::create):
      (JSC::JSPromiseDeferred::JSPromiseDeferred):
      (JSC::JSPromiseDeferred::finishCreation):
      (JSC::JSPromiseDeferred::visitChildren):
      (JSC::createJSPromiseDeferredFromConstructor):
      (JSC::updateDeferredFromPotentialThenable):
      * runtime/JSPromiseDeferred.h: Added.
      (JSC::JSPromiseDeferred::createStructure):
      (JSC::JSPromiseDeferred::promise):
      (JSC::JSPromiseDeferred::resolve):
      (JSC::JSPromiseDeferred::reject):
      * runtime/JSPromiseFunctions.cpp: Added.
      (JSC::deferredConstructionFunction):
      (JSC::createDeferredConstructionFunction):
      (JSC::identifyFunction):
      (JSC::createIdentifyFunction):
      (JSC::promiseAllCountdownFunction):
      (JSC::createPromiseAllCountdownFunction):
      (JSC::promiseResolutionHandlerFunction):
      (JSC::createPromiseResolutionHandlerFunction):
      (JSC::rejectPromiseFunction):
      (JSC::createRejectPromiseFunction):
      (JSC::resolvePromiseFunction):
      (JSC::createResolvePromiseFunction):
      (JSC::throwerFunction):
      (JSC::createThrowerFunction):
      * runtime/JSPromiseFunctions.h: Added.
      * runtime/JSPromisePrototype.cpp:
      (JSC::JSPromisePrototypeFuncThen):
      (JSC::JSPromisePrototypeFuncCatch):
      * runtime/JSPromiseReaction.cpp: Added.
      (JSC::createExecutePromiseReactionMicroTask):
      (JSC::ExecutePromiseReactionMicroTask::run):
      (JSC::JSPromiseReaction::create):
      (JSC::JSPromiseReaction::JSPromiseReaction):
      (JSC::JSPromiseReaction::finishCreation):
      (JSC::JSPromiseReaction::visitChildren):
      * runtime/JSPromiseReaction.h: Added.
      (JSC::JSPromiseReaction::createStructure):
      (JSC::JSPromiseReaction::deferred):
      (JSC::JSPromiseReaction::handler):
      * runtime/JSPromiseResolver.cpp: Removed.
      * runtime/JSPromiseResolver.h: Removed.
      * runtime/JSPromiseResolverConstructor.cpp: Removed.
      * runtime/JSPromiseResolverConstructor.h: Removed.
      * runtime/JSPromiseResolverPrototype.cpp: Removed.
      * runtime/JSPromiseResolverPrototype.h: Removed.
      * runtime/Microtask.h: Added.
      * runtime/VM.cpp:
      (JSC::VM::VM):
      (JSC::VM::~VM):
      * runtime/VM.h:
      
      Source/WebCore: 
      
      * ForwardingHeaders/runtime/JSPromiseDeferred.h: Added.
      * ForwardingHeaders/runtime/JSPromiseResolver.h: Removed.
      * bindings/js/JSDOMGlobalObjectTask.cpp:
      (WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
      * bindings/js/JSDOMGlobalObjectTask.h:
      * bindings/js/JSDOMPromise.cpp:
      (WebCore::DeferredWrapper::DeferredWrapper):
      (WebCore::DeferredWrapper::promise):
      (WebCore::DeferredWrapper::resolve):
      (WebCore::DeferredWrapper::reject):
      * bindings/js/JSDOMPromise.h:
      (WebCore::DeferredWrapper::resolve):
      (WebCore::DeferredWrapper::reject):
      (WebCore::DeferredWrapper::resolve<String>):
      (WebCore::DeferredWrapper::resolve<bool>):
      (WebCore::char>>):
      (WebCore::DeferredWrapper::reject<String>):
      * bindings/js/JSDOMWindowBase.cpp:
      (WebCore::JSDOMWindowBase::queueTaskToEventLoop):
      * bindings/js/JSDOMWindowBase.h:
      * bindings/js/JSSubtleCryptoCustom.cpp:
      (WebCore::JSSubtleCrypto::encrypt):
      (WebCore::JSSubtleCrypto::decrypt):
      (WebCore::JSSubtleCrypto::sign):
      (WebCore::JSSubtleCrypto::verify):
      (WebCore::JSSubtleCrypto::digest):
      (WebCore::JSSubtleCrypto::generateKey):
      (WebCore::JSSubtleCrypto::importKey):
      (WebCore::JSSubtleCrypto::exportKey):
      (WebCore::JSSubtleCrypto::wrapKey):
      (WebCore::JSSubtleCrypto::unwrapKey):
      * bindings/js/JSWorkerGlobalScopeBase.cpp:
      (WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
      * bindings/js/JSWorkerGlobalScopeBase.h:
      
      LayoutTests: 
      
      * crypto/subtle/argument-conversion.html:
      * crypto/subtle/resources/common.js:
      * crypto/subtle/sha-1.html:
      * crypto/subtle/sha-224.html:
      * crypto/subtle/sha-256.html:
      * crypto/subtle/sha-384.html:
      * crypto/subtle/sha-512.html:
      * js/dom/Promise-already-fulfilled-expected.txt: Removed.
      * js/dom/Promise-already-fulfilled.html: Removed.
      * js/dom/Promise-already-rejected.html:
      * js/dom/Promise-already-resolved.html:
      * js/dom/Promise-catch-expected.txt:
      * js/dom/Promise-catch-in-workers-expected.txt:
      * js/dom/Promise-catch.html:
      * js/dom/Promise-chain.html:
      * js/dom/Promise-exception-expected.txt:
      * js/dom/Promise-exception.html:
      * js/dom/Promise-expected.txt:
      * js/dom/Promise-fulfill-expected.txt: Removed.
      * js/dom/Promise-fulfill-in-workers-expected.txt: Removed.
      * js/dom/Promise-fulfill-in-workers.html: Removed.
      * js/dom/Promise-fulfill.html: Removed.
      * js/dom/Promise-init-callback-receiver-expected.txt: Added.
      * js/dom/Promise-init-callback-receiver.html: Added.
      * js/dom/Promise-init-expected.txt:
      * js/dom/Promise-init-in-workers-expected.txt:
      * js/dom/Promise-init.html:
      * js/dom/Promise-onFulfilled-deep-expected.txt: Added.
      * js/dom/Promise-onFulfilled-deep.html: Added.
      * js/dom/Promise-onRejected-deep-expected.txt: Added.
      * js/dom/Promise-onRejected-deep.html: Added.
      * js/dom/Promise-reject.html:
      * js/dom/Promise-resolve-chain.html:
      * js/dom/Promise-resolve-expected.txt:
      * js/dom/Promise-resolve-in-workers-expected.txt:
      * js/dom/Promise-resolve-state-expected.txt: Added.
      * js/dom/Promise-resolve-state-in-workers-expected.txt: Added.
      * js/dom/Promise-resolve-state-in-workers.html: Added.
      * js/dom/Promise-resolve-state.html: Added.
      * js/dom/Promise-resolve-with-itself-expected.txt: Added.
      * js/dom/Promise-resolve-with-itself.html: Added.
      * js/dom/Promise-resolve-with-then-exception.html:
      * js/dom/Promise-resolve-with-then-fulfill-expected.txt:
      * js/dom/Promise-resolve-with-then-fulfill.html:
      * js/dom/Promise-resolve-with-then-reject-expected.txt:
      * js/dom/Promise-resolve-with-then-reject.html:
      * js/dom/Promise-resolve.html:
      * js/dom/Promise-simple-expected.txt:
      * js/dom/Promise-simple-fulfill-expected.txt: Removed.
      * js/dom/Promise-simple-fulfill-inside-callback-expected.txt: Removed.
      * js/dom/Promise-simple-fulfill-inside-callback.html: Removed.
      * js/dom/Promise-simple-fulfill.html: Removed.
      * js/dom/Promise-simple-in-workers-expected.txt:
      * js/dom/Promise-simple-resolve-expected.txt: Added.
      * js/dom/Promise-simple-resolve.html: Added.
      * js/dom/Promise-simple.html:
      * js/dom/Promise-static-all-expected.txt: Added.
      * js/dom/Promise-static-all.html: Added.
      * js/dom/Promise-static-cast-expected.txt: Added.
      * js/dom/Promise-static-cast.html: Added.
      * js/dom/Promise-static-fulfill-expected.txt: Removed.
      * js/dom/Promise-static-fulfill.html: Removed.
      * js/dom/Promise-static-race-expected.txt: Added.
      * js/dom/Promise-static-race.html: Added.
      * js/dom/Promise-static-resolve.html:
      * js/dom/Promise-then-callback-receiver-expected.txt: Added.
      * js/dom/Promise-then-callback-receiver.html: Added.
      * js/dom/Promise-then-expected.txt:
      * js/dom/Promise-then-in-workers-expected.txt:
      * js/dom/Promise-then-without-callbacks.html:
      * js/dom/Promise-then.html:
      * js/dom/Promise-types-expected.txt:
      * js/dom/Promise-types.html:
      * js/dom/Promise.html:
      * js/resources/Promise-catch-in-workers.js:
      * js/resources/Promise-fulfill-in-workers.js: Removed.
      * js/resources/Promise-init-in-workers.js:
      * js/resources/Promise-reject-in-workers.js:
      * js/resources/Promise-resolve-in-workers.js:
      * js/resources/Promise-resolve-state-in-workers.js: Added.
      * js/resources/Promise-simple-in-workers.js:
      * js/resources/Promise-then-in-workers.js:
      * js/resources/Promise-then-without-callbacks-in-workers.js:
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161241 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      349af4e4
  2. 29 Aug, 2013 1 commit
  3. 26 Aug, 2013 1 commit
    • weinig@apple.com's avatar
      Add support for Promises · bd760697
      weinig@apple.com authored
      https://bugs.webkit.org/show_bug.cgi?id=120260
      
      Reviewed by Darin Adler.
      
      Source/JavaScriptCore: 
      
      Add an initial implementation of Promises - http://dom.spec.whatwg.org/#promises.
      - Despite Promises being defined in the DOM, the implementation is being put in JSC
        in preparation for the Promises eventually being defined in ECMAScript.
      
      * CMakeLists.txt:
      * DerivedSources.make:
      * DerivedSources.pri:
      * GNUmakefile.list.am:
      * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
      * JavaScriptCore.xcodeproj/project.pbxproj:
      * Target.pri:
      Add new files.
      
      * jsc.cpp:
      Update jsc's GlobalObjectMethodTable to stub out the new QueueTaskToEventLoop callback. This mean's
      you can't quite use Promises with with the command line tool yet.
          
      * interpreter/CallFrame.h:
      (JSC::ExecState::promisePrototypeTable):
      (JSC::ExecState::promiseConstructorTable):
      (JSC::ExecState::promiseResolverPrototypeTable):
      * runtime/VM.cpp:
      (JSC::VM::VM):
      (JSC::VM::~VM):
      * runtime/VM.h:
      Add supporting code for the new static lookup tables.
      
      * runtime/CommonIdentifiers.h:
      Add 3 new identifiers, "Promise", "PromiseResolver", and "then".
      
      * runtime/JSGlobalObject.cpp:
      (JSC::JSGlobalObject::reset):
      (JSC::JSGlobalObject::visitChildren):
      Add supporting code Promise and PromiseResolver's constructors and structures.
      
      * runtime/JSGlobalObject.h:
      (JSC::TaskContext::~TaskContext):
      Add a new callback to the GlobalObjectMethodTable to post a task on the embedder's runloop.
      
      (JSC::JSGlobalObject::promisePrototype):
      (JSC::JSGlobalObject::promiseResolverPrototype):
      (JSC::JSGlobalObject::promiseStructure):
      (JSC::JSGlobalObject::promiseResolverStructure):
      (JSC::JSGlobalObject::promiseCallbackStructure):
      (JSC::JSGlobalObject::promiseWrapperCallbackStructure):
      Add supporting code Promise and PromiseResolver's constructors and structures.
      
      * runtime/JSPromise.cpp: Added.
      * runtime/JSPromise.h: Added.
      * runtime/JSPromiseCallback.cpp: Added.
      * runtime/JSPromiseCallback.h: Added.
      * runtime/JSPromiseConstructor.cpp: Added.
      * runtime/JSPromiseConstructor.h: Added.
      * runtime/JSPromisePrototype.cpp: Added.
      * runtime/JSPromisePrototype.h: Added.
      * runtime/JSPromiseResolver.cpp: Added.
      * runtime/JSPromiseResolver.h: Added.
      * runtime/JSPromiseResolverConstructor.cpp: Added.
      * runtime/JSPromiseResolverConstructor.h: Added.
      * runtime/JSPromiseResolverPrototype.cpp: Added.
      * runtime/JSPromiseResolverPrototype.h: Added.
      Add Promise implementation.
      
      Source/WebCore: 
      
      Add an initial implementation of Promises - http://dom.spec.whatwg.org/#promises.
      - Despite Promises being defined in the DOM, the implementation is being put in JSC
        in preparation for the Promises eventually being defined in ECMAScript.
      
      Tests: fast/js/Promise-already-fulfilled.html
             fast/js/Promise-already-rejected.html
             fast/js/Promise-already-resolved.html
             fast/js/Promise-catch-in-workers.html
             fast/js/Promise-catch.html
             fast/js/Promise-chain.html
             fast/js/Promise-exception.html
             fast/js/Promise-fulfill-in-workers.html
             fast/js/Promise-fulfill.html
             fast/js/Promise-init-in-workers.html
             fast/js/Promise-init.html
             fast/js/Promise-reject-in-workers.html
             fast/js/Promise-reject.html
             fast/js/Promise-resolve-chain.html
             fast/js/Promise-resolve-in-workers.html
             fast/js/Promise-resolve-with-then-exception.html
             fast/js/Promise-resolve-with-then-fulfill.html
             fast/js/Promise-resolve-with-then-reject.html
             fast/js/Promise-resolve.html
             fast/js/Promise-simple-fulfill-inside-callback.html
             fast/js/Promise-simple-fulfill.html
             fast/js/Promise-simple-in-workers.html
             fast/js/Promise-simple.html
             fast/js/Promise-static-fulfill.html
             fast/js/Promise-static-reject.html
             fast/js/Promise-static-resolve.html
             fast/js/Promise-then-in-workers.html
             fast/js/Promise-then-without-callbacks-in-workers.html
             fast/js/Promise-then-without-callbacks.html
             fast/js/Promise-then.html
             fast/js/Promise-types.html
             fast/js/Promise.html
      
      * GNUmakefile.list.am:
      * Target.pri:
      * UseJSC.cmake:
      * WebCore.vcxproj/WebCore.vcxproj:
      * WebCore.vcxproj/WebCore.vcxproj.filters:
      * WebCore.xcodeproj/project.pbxproj:
      * bindings/js/JSBindingsAllInOne.cpp:
      Add new files.
      
      * bindings/js/JSDOMGlobalObjectTask.cpp: Added.
      (WebCore::JSGlobalObjectCallback::create):
      (WebCore::JSGlobalObjectCallback::~JSGlobalObjectCallback):
      (WebCore::JSGlobalObjectCallback::call):
      (WebCore::JSGlobalObjectCallback::JSGlobalObjectCallback):
      (WebCore::JSGlobalObjectTask::JSGlobalObjectTask):
      (WebCore::JSGlobalObjectTask::~JSGlobalObjectTask):
      (WebCore::JSGlobalObjectTask::performTask):
      * bindings/js/JSDOMGlobalObjectTask.h: Added.
      (WebCore::JSGlobalObjectTask::create):
      Add a new task type to be used with the GlobalObjectMethodTable's new QueueTaskToEventLoop callback.
      
      * bindings/js/JSDOMWindowBase.cpp:
      (WebCore::JSDOMWindowBase::queueTaskToEventLoop):
      * bindings/js/JSDOMWindowBase.h:
      Implement the GlobalObjectMethodTable callback, QueueTaskToEventLoop. 
      
      * bindings/js/JSMainThreadExecState.h:
      All using JSMainThreadExecState as a simple RAII object.
      
      * bindings/js/JSWorkerGlobalScopeBase.cpp:
      (WebCore::JSWorkerGlobalScopeBase::JSWorkerGlobalScopeBase):
      (WebCore::JSWorkerGlobalScopeBase::allowsAccessFrom):
      (WebCore::JSWorkerGlobalScopeBase::supportsProfiling):
      (WebCore::JSWorkerGlobalScopeBase::supportsRichSourceInfo):
      (WebCore::JSWorkerGlobalScopeBase::shouldInterruptScript):
      (WebCore::JSWorkerGlobalScopeBase::javaScriptExperimentsEnabled):
      (WebCore::JSWorkerGlobalScopeBase::queueTaskToEventLoop):
      * bindings/js/JSWorkerGlobalScopeBase.h:
      Add a GlobalObjectMethodTable and implement QueueTaskToEventLoop. Forward the other callbacks
      to JSGlobalObject so they retain their existing behavior.
      
      LayoutTests: 
      
      Add tests adapted from the Mozilla and Blink projects.
      
      * fast/js/Promise-already-fulfilled-expected.txt: Added.
      * fast/js/Promise-already-fulfilled.html: Added.
      * fast/js/Promise-already-rejected-expected.txt: Added.
      * fast/js/Promise-already-rejected.html: Added.
      * fast/js/Promise-already-resolved-expected.txt: Added.
      * fast/js/Promise-already-resolved.html: Added.
      * fast/js/Promise-catch-expected.txt: Added.
      * fast/js/Promise-catch-in-workers-expected.txt: Added.
      * fast/js/Promise-catch-in-workers.html: Added.
      * fast/js/Promise-catch.html: Added.
      * fast/js/Promise-chain-expected.txt: Added.
      * fast/js/Promise-chain.html: Added.
      * fast/js/Promise-exception-expected.txt: Added.
      * fast/js/Promise-exception.html: Added.
      * fast/js/Promise-expected.txt: Added.
      * fast/js/Promise-fulfill-expected.txt: Added.
      * fast/js/Promise-fulfill-in-workers-expected.txt: Added.
      * fast/js/Promise-fulfill-in-workers.html: Added.
      * fast/js/Promise-fulfill.html: Added.
      * fast/js/Promise-init-expected.txt: Added.
      * fast/js/Promise-init-in-workers-expected.txt: Added.
      * fast/js/Promise-init-in-workers.html: Added.
      * fast/js/Promise-init.html: Added.
      * fast/js/Promise-reject-expected.txt: Added.
      * fast/js/Promise-reject-in-workers-expected.txt: Added.
      * fast/js/Promise-reject-in-workers.html: Added.
      * fast/js/Promise-reject.html: Added.
      * fast/js/Promise-resolve-chain-expected.txt: Added.
      * fast/js/Promise-resolve-chain.html: Added.
      * fast/js/Promise-resolve-expected.txt: Added.
      * fast/js/Promise-resolve-in-workers-expected.txt: Added.
      * fast/js/Promise-resolve-in-workers.html: Added.
      * fast/js/Promise-resolve-with-then-exception-expected.txt: Added.
      * fast/js/Promise-resolve-with-then-exception.html: Added.
      * fast/js/Promise-resolve-with-then-fulfill-expected.txt: Added.
      * fast/js/Promise-resolve-with-then-fulfill.html: Added.
      * fast/js/Promise-resolve-with-then-reject-expected.txt: Added.
      * fast/js/Promise-resolve-with-then-reject.html: Added.
      * fast/js/Promise-resolve.html: Added.
      * fast/js/Promise-simple-expected.txt: Added.
      * fast/js/Promise-simple-fulfill-expected.txt: Added.
      * fast/js/Promise-simple-fulfill-inside-callback-expected.txt: Added.
      * fast/js/Promise-simple-fulfill-inside-callback.html: Added.
      * fast/js/Promise-simple-fulfill.html: Added.
      * fast/js/Promise-simple-in-workers-expected.txt: Added.
      * fast/js/Promise-simple-in-workers.html: Added.
      * fast/js/Promise-simple.html: Added.
      * fast/js/Promise-static-fulfill-expected.txt: Added.
      * fast/js/Promise-static-fulfill.html: Added.
      * fast/js/Promise-static-reject-expected.txt: Added.
      * fast/js/Promise-static-reject.html: Added.
      * fast/js/Promise-static-resolve-expected.txt: Added.
      * fast/js/Promise-static-resolve.html: Added.
      * fast/js/Promise-then-expected.txt: Added.
      * fast/js/Promise-then-in-workers-expected.txt: Added.
      * fast/js/Promise-then-in-workers.html: Added.
      * fast/js/Promise-then-without-callbacks-expected.txt: Added.
      * fast/js/Promise-then-without-callbacks-in-workers-expected.txt: Added.
      * fast/js/Promise-then-without-callbacks-in-workers.html: Added.
      * fast/js/Promise-then-without-callbacks.html: Added.
      * fast/js/Promise-then.html: Added.
      * fast/js/Promise-types-expected.txt: Added.
      * fast/js/Promise-types.html: Added.
      * fast/js/Promise.html: Added.
      * fast/js/resources/Promise-catch-in-workers.js: Added.
      * fast/js/resources/Promise-fulfill-in-workers.js: Added.
      * fast/js/resources/Promise-init-in-workers.js: Added.
      * fast/js/resources/Promise-reject-in-workers.js: Added.
      * fast/js/resources/Promise-resolve-in-workers.js: Added.
      * fast/js/resources/Promise-simple-in-workers.js: Added.
      * fast/js/resources/Promise-then-in-workers.js: Added.
      * fast/js/resources/Promise-then-without-callbacks-in-workers.js: Added.
      
      
      git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154629 268f45cc-cd09-0410-ab3c-d52691b4dbfc
      bd760697