Ignore:
Timestamp:
Jul 5, 2015, 7:01:27 PM (10 years ago)
Author:
Yusuke Suzuki
Message:

[ES6] Implement the latest Promise spec in JS
https://bugs.webkit.org/show_bug.cgi?id=146229

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Updated the Promise implementation to meet to the ES6 spec.
This patch

  1. Implement ES6 Promise and related abstract operations in builtins JS
  2. Expose @enqueueJob private function to JS world to post the microtask

Updated implementation has one-on-one correspondence to the ES6 spec description.
And keep the JSPromiseDeferred because it is the interface used from the WebCore.

(reduce):
(reduceRight):
(every):
(forEach):
(filter):
(map):
(some):
(fill):
(find):
(findIndex):
(includes):
(copyWithin):
ToInteger / ToLength are renamed to toInteger and toLength.

  • builtins/ArrayConstructor.js:

(from):
ToInteger / ToLength are renamed to toInteger and toLength.

  • builtins/GlobalObject.js:

(toInteger):
(toLength):
(isObject):
(ToInteger): Deleted.
(ToLength): Deleted.
ToInteger / ToLength are renamed to toInteger and toLength.
Add new abstract operation, isObject.

  • builtins/Operations.Promise.js: Added.

(isPromise):
(newPromiseReaction):
(newPromiseDeferred):
(newPromiseCapability.executor):
(newPromiseCapability):
(triggerPromiseReactions):
(rejectPromise):
(fulfillPromise):
(createResolvingFunctions.resolve):
(createResolvingFunctions.reject):
(createResolvingFunctions):
(promiseReactionJob):
(promiseResolveThenableJob):
(initializePromise):
Added Promise related abstract operations.

  • builtins/Promise.prototype.js:

(catch):
(.onFulfilled):
(.onRejected):
(then):
Promise#then implementation in JS.

  • builtins/PromiseConstructor.js: Added.

(all.newResolveElement):
(all):
(race):
(reject):
(resolve):
Promise static functions implementations in JS.

  • builtins/StringConstructor.js:

(raw):
ToInteger / ToLength are renamed to toInteger and toLength.

  • inspector/JSInjectedScriptHost.cpp:

(Inspector::JSInjectedScriptHost::getInternalProperties):

  • runtime/CommonIdentifiers.h:
  • runtime/JSGlobalObject.cpp:

(JSC::enqueueJob):
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::initializePromiseFunction):
(JSC::JSGlobalObject::newPromiseDeferredFunction):

  • runtime/JSJob.cpp: Renamed from Source/JavaScriptCore/runtime/JSPromiseReaction.h.

(JSC::createJSJob):
(JSC::JSJobMicrotask::run):

  • runtime/JSJob.h: Renamed from Source/JavaScriptCore/runtime/JSPromiseFunctions.h.
  • runtime/JSPromise.cpp:

(JSC::JSPromise::create):
(JSC::JSPromise::JSPromise):
(JSC::JSPromise::finishCreation):
(JSC::JSPromise::result):
(JSC::JSPromise::destroy): Deleted.
(JSC::JSPromise::visitChildren): Deleted.
(JSC::JSPromise::reject): Deleted.
(JSC::JSPromise::resolve): Deleted.
(JSC::JSPromise::appendResolveReaction): Deleted.
(JSC::JSPromise::appendRejectReaction): Deleted.
(JSC::triggerPromiseReactions): Deleted.

  • runtime/JSPromise.h:

(JSC::JSPromise::status): Deleted.
(JSC::JSPromise::result): Deleted.
(JSC::JSPromise::constructor): Deleted.

  • runtime/JSPromiseConstructor.cpp:

(JSC::constructPromise):
(JSC::JSPromiseConstructorFuncResolve): Deleted.
(JSC::JSPromiseConstructorFuncReject): Deleted.
(JSC::performPromiseRaceLoop): Deleted.
(JSC::JSPromiseConstructorFuncRace): Deleted.
(JSC::performPromiseAll): Deleted.
(JSC::JSPromiseConstructorFuncAll): Deleted.

  • runtime/JSPromiseDeferred.cpp:

(JSC::JSPromiseDeferred::create):
(JSC::createJSPromiseDeferredFromConstructor): Deleted.
(JSC::updateDeferredFromPotentialThenable): Deleted.
(JSC::performDeferredResolve): Deleted.
(JSC::performDeferredReject): Deleted.
(JSC::abruptRejection): Deleted.

  • runtime/JSPromiseDeferred.h:
  • runtime/JSPromiseFunctions.cpp: Removed.

(JSC::deferredConstructionFunction): Deleted.
(JSC::createDeferredConstructionFunction): Deleted.
(JSC::identifyFunction): Deleted.
(JSC::createIdentifyFunction): Deleted.
(JSC::promiseAllCountdownFunction): Deleted.
(JSC::createPromiseAllCountdownFunction): Deleted.
(JSC::promiseResolutionHandlerFunction): Deleted.
(JSC::createPromiseResolutionHandlerFunction): Deleted.
(JSC::rejectPromiseFunction): Deleted.
(JSC::createRejectPromiseFunction): Deleted.
(JSC::resolvePromiseFunction): Deleted.
(JSC::createResolvePromiseFunction): Deleted.
(JSC::throwerFunction): Deleted.
(JSC::createThrowerFunction): Deleted.

  • runtime/JSPromisePrototype.cpp:

(JSC::JSPromisePrototypeFuncThen): Deleted.

  • runtime/JSPromiseReaction.cpp: Removed.

(JSC::createExecutePromiseReactionMicrotask): Deleted.
(JSC::ExecutePromiseReactionMicrotask::run): Deleted.
(JSC::JSPromiseReaction::create): Deleted.
(JSC::JSPromiseReaction::JSPromiseReaction): Deleted.
(JSC::JSPromiseReaction::finishCreation): Deleted.
(JSC::JSPromiseReaction::visitChildren): Deleted.

  • runtime/VM.cpp:

(JSC::VM::VM): Deleted.

  • runtime/VM.h:

LayoutTests:

Add a test to guarantee that Promise.resolve looks up then field synchronously.

  • js/dom/Promise-resolve-lookup-then-expected.txt: Added.
  • js/dom/Promise-resolve-lookup-then.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/builtins/GlobalObject.js

    r184582 r186298  
    2424 */
    2525
    26 function ToInteger(target) {
     26function toInteger(target)
     27{
    2728    "use strict";
    2829
     
    3940}
    4041
    41 function ToLength(target) {
     42function toLength(target)
     43{
    4244    "use strict";
    4345
    4446    var maxSafeInteger = 0x1FFFFFFFFFFFFF;
    45     var length = @ToInteger(target);
     47    var length = @toInteger(target);
    4648    // originally Math.min(Math.max(length, 0), maxSafeInteger));
    4749    return length > 0 ? (length < maxSafeInteger ? length : maxSafeInteger) : 0;
    4850}
     51
     52function isObject(object)
     53{
     54    "use strict";
     55
     56    return (object !== null && typeof object === "object") || typeof object === "function";
     57}
Note: See TracChangeset for help on using the changeset viewer.