[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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161538 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7e579012
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 @@ debug("");
// 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 @@ shouldBeDefined("aPromise.catch");
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 @@ debug("");
// 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({})", "'TypeError: Promise constructor takes a function
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");
......
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment