Skip to content
Permalink
Browse files
[JS] Should be able to create a promise by calling the Promise constr…
…uctor 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.

Canonical link: https://commits.webkit.org/144563@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161538 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Sam Weinig authored and webkit-commit-queue committed Jan 9, 2014
1 parent 33b733b commit f2bb0c2774434c290989fe3cabe0c2b53a867a22
Showing 5 changed files with 50 additions and 4 deletions.
@@ -1,3 +1,14 @@
2014-01-08 Sam Weinig <sam@webkit.org>

[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

Reviewed by Geoffrey Garen.

* js/dom/Promise-types-expected.txt:
* js/dom/Promise-types.html:
Add test for using calling a Promise constructor as a function.

2014-01-08 Youenn Fablet <youennf@gmail.com>

Correctly set XHR loadend event attributes (loaded and total).
@@ -15,17 +15,27 @@ PASS aPromise.then.length is 2
PASS aPromise.catch is defined.
PASS aPromise.catch is an instance of Function
PASS aPromise.catch.length is 1
aPromise2 = Promise(...)
PASS aPromise2 is an instance of Promise
PASS String(aPromise2) is '[object Promise]'

Promise constructor

PASS Promise.length is 1
PASS new Promise() threw exception TypeError: Promise constructor takes a function argument.
PASS Promise() threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise(1) threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise('hello') threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise([]) threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise({}) threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise(null) threw exception TypeError: Promise constructor takes a function argument.
PASS new Promise(undefined) threw exception TypeError: Promise constructor takes a function argument.
PASS Promise(1) threw exception TypeError: Promise constructor takes a function argument.
PASS Promise('hello') threw exception TypeError: Promise constructor takes a function argument.
PASS Promise([]) threw exception TypeError: Promise constructor takes a function argument.
PASS Promise({}) threw exception TypeError: Promise constructor takes a function argument.
PASS Promise(null) threw exception TypeError: Promise constructor takes a function argument.
PASS Promise(undefined) threw exception TypeError: Promise constructor takes a function argument.

Promise statics

@@ -19,7 +19,7 @@

// Promises should be of type Promise.

var aPromise = new Promise(function(resolver) { resolver.resolve(1); });
var aPromise = new Promise(function(resolve, reject) { resolve(1); });

debug("aPromise = new Promise(...)")
shouldBeType("aPromise", "Promise");
@@ -32,6 +32,11 @@
shouldBeType("aPromise.catch", "Function");
shouldBe("aPromise.catch.length", "1");

var aPromise2 = Promise(function(resolve, reject) { resolve(1); });

debug("aPromise2 = Promise(...)")
shouldBeType("aPromise2", "Promise");
shouldBe("String(aPromise2)", "'[object Promise]'");

// Promise constructor
debug("");
@@ -41,6 +46,7 @@
// Need at least one parameter.
shouldBe("Promise.length", "1");
shouldThrow("new Promise()");
shouldThrow("Promise()");

// Parameter must be a function.
shouldThrow("new Promise(1)", "'TypeError: Promise constructor takes a function argument'");
@@ -50,6 +56,13 @@
shouldThrow("new Promise(null)", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("new Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");

shouldThrow("Promise(1)", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("Promise('hello')", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("Promise([])", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("Promise({})", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("Promise(null)", "'TypeError: Promise constructor takes a function argument'");
shouldThrow("Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");

// Promise statics
debug("");
debug("Promise statics");
@@ -1,3 +1,15 @@
2014-01-08 Sam Weinig <sam@webkit.org>

[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

Reviewed by Geoffrey Garen.

* 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").

2014-01-08 Dániel Bátyai <dbatyai.u-szeged@partner.samsung.com>

[EFL] Make FTL buildable
@@ -153,10 +153,10 @@ ConstructType JSPromiseConstructor::getConstructData(JSCell*, ConstructData& con
return ConstructTypeHost;
}

CallType JSPromiseConstructor::getCallData(JSCell*, CallData&)
CallType JSPromiseConstructor::getCallData(JSCell*, CallData& callData)
{
// FIXME: Implement
return CallTypeNone;
callData.native.function = constructPromise;
return CallTypeHost;
}

bool JSPromiseConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)

0 comments on commit f2bb0c2

Please sign in to comment.