Changeset 161538 in webkit


Ignore:
Timestamp:
Jan 8, 2014 6:37:58 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[JS] Should be able to create a promise by calling the Promise constructor as a function
https://bugs.webkit.org/show_bug.cgi?id=126561

Patch by Sam Weinig <sam@webkit.org> on 2014-01-08
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • runtime/JSPromiseConstructor.cpp:

(JSC::JSPromiseConstructor::getCallData):
Add support for calling the Promise constructor as a function (e.g. var p = Promise(...), note
the missing "new").

LayoutTests:

  • js/dom/Promise-types-expected.txt:
  • js/dom/Promise-types.html:

Add test for using calling a Promise constructor as a function.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r161532 r161538  
     12014-01-08  Sam Weinig  <sam@webkit.org>
     2
     3        [JS] Should be able to create a promise by calling the Promise constructor as a function
     4        https://bugs.webkit.org/show_bug.cgi?id=126561
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * js/dom/Promise-types-expected.txt:
     9        * js/dom/Promise-types.html:
     10        Add test for using calling a Promise constructor as a function.
     11
    1122014-01-08  Youenn Fablet  <youennf@gmail.com>
    213
  • trunk/LayoutTests/js/dom/Promise-types-expected.txt

    r161241 r161538  
    1616PASS aPromise.catch is an instance of Function
    1717PASS aPromise.catch.length is 1
     18aPromise2 = Promise(...)
     19PASS aPromise2 is an instance of Promise
     20PASS String(aPromise2) is '[object Promise]'
    1821
    1922Promise constructor
     
    2124PASS Promise.length is 1
    2225PASS new Promise() threw exception TypeError: Promise constructor takes a function argument.
     26PASS Promise() threw exception TypeError: Promise constructor takes a function argument.
    2327PASS new Promise(1) threw exception TypeError: Promise constructor takes a function argument.
    2428PASS new Promise('hello') threw exception TypeError: Promise constructor takes a function argument.
     
    2731PASS new Promise(null) threw exception TypeError: Promise constructor takes a function argument.
    2832PASS new Promise(undefined) threw exception TypeError: Promise constructor takes a function argument.
     33PASS Promise(1) threw exception TypeError: Promise constructor takes a function argument.
     34PASS Promise('hello') threw exception TypeError: Promise constructor takes a function argument.
     35PASS Promise([]) threw exception TypeError: Promise constructor takes a function argument.
     36PASS Promise({}) threw exception TypeError: Promise constructor takes a function argument.
     37PASS Promise(null) threw exception TypeError: Promise constructor takes a function argument.
     38PASS Promise(undefined) threw exception TypeError: Promise constructor takes a function argument.
    2939
    3040Promise statics
  • trunk/LayoutTests/js/dom/Promise-types.html

    r161241 r161538  
    2020// Promises should be of type Promise.
    2121
    22 var aPromise = new Promise(function(resolver) { resolver.resolve(1); });
     22var aPromise = new Promise(function(resolve, reject) { resolve(1); });
    2323
    2424debug("aPromise = new Promise(...)")
     
    3333shouldBe("aPromise.catch.length", "1");
    3434
     35var aPromise2 = Promise(function(resolve, reject) { resolve(1); });
     36
     37debug("aPromise2 = Promise(...)")
     38shouldBeType("aPromise2", "Promise");
     39shouldBe("String(aPromise2)", "'[object Promise]'");
    3540
    3641// Promise constructor
     
    4247shouldBe("Promise.length", "1");
    4348shouldThrow("new Promise()");
     49shouldThrow("Promise()");
    4450
    4551// Parameter must be a function.
     
    5056shouldThrow("new Promise(null)", "'TypeError: Promise constructor takes a function argument'");
    5157shouldThrow("new Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");
     58
     59shouldThrow("Promise(1)", "'TypeError: Promise constructor takes a function argument'");
     60shouldThrow("Promise('hello')", "'TypeError: Promise constructor takes a function argument'");
     61shouldThrow("Promise([])", "'TypeError: Promise constructor takes a function argument'");
     62shouldThrow("Promise({})", "'TypeError: Promise constructor takes a function argument'");
     63shouldThrow("Promise(null)", "'TypeError: Promise constructor takes a function argument'");
     64shouldThrow("Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");
    5265
    5366// Promise statics
  • trunk/Source/JavaScriptCore/ChangeLog

    r161498 r161538  
     12014-01-08  Sam Weinig  <sam@webkit.org>
     2
     3        [JS] Should be able to create a promise by calling the Promise constructor as a function
     4        https://bugs.webkit.org/show_bug.cgi?id=126561
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * runtime/JSPromiseConstructor.cpp:
     9        (JSC::JSPromiseConstructor::getCallData):
     10        Add support for calling the Promise constructor as a function (e.g. var p = Promise(...), note
     11        the missing "new").
     12
    1132014-01-08  Dániel Bátyai  <dbatyai.u-szeged@partner.samsung.com>
    214
  • trunk/Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp

    r161365 r161538  
    154154}
    155155
    156 CallType JSPromiseConstructor::getCallData(JSCell*, CallData&)
    157 {
    158     // FIXME: Implement
    159     return CallTypeNone;
     156CallType JSPromiseConstructor::getCallData(JSCell*, CallData& callData)
     157{
     158    callData.native.function = constructPromise;
     159    return CallTypeHost;
    160160}
    161161
Note: See TracChangeset for help on using the changeset viewer.