- Revision
- 161538
- Author
- [email protected]
- Date
- 2014-01-08 18:37:58 -0800 (Wed, 08 Jan 2014)
Log 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 <[email protected]> on 2014-01-08
Reviewed by Geoffrey Garen.
Source/_javascript_Core:
* 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.
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (161537 => 161538)
--- trunk/LayoutTests/ChangeLog 2014-01-09 02:21:49 UTC (rev 161537)
+++ trunk/LayoutTests/ChangeLog 2014-01-09 02:37:58 UTC (rev 161538)
@@ -1,3 +1,14 @@
+2014-01-08 Sam Weinig <[email protected]>
+
+ [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 <[email protected]>
Correctly set XHR loadend event attributes (loaded and total).
Modified: trunk/LayoutTests/js/dom/Promise-types-expected.txt (161537 => 161538)
--- trunk/LayoutTests/js/dom/Promise-types-expected.txt 2014-01-09 02:21:49 UTC (rev 161537)
+++ trunk/LayoutTests/js/dom/Promise-types-expected.txt 2014-01-09 02:37:58 UTC (rev 161538)
@@ -15,17 +15,27 @@
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
Modified: trunk/LayoutTests/js/dom/Promise-types.html (161537 => 161538)
--- trunk/LayoutTests/js/dom/Promise-types.html 2014-01-09 02:21:49 UTC (rev 161537)
+++ trunk/LayoutTests/js/dom/Promise-types.html 2014-01-09 02:37:58 UTC (rev 161538)
@@ -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,7 +32,12 @@
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("");
debug("Promise constructor");
@@ -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");
Modified: trunk/Source/_javascript_Core/ChangeLog (161537 => 161538)
--- trunk/Source/_javascript_Core/ChangeLog 2014-01-09 02:21:49 UTC (rev 161537)
+++ trunk/Source/_javascript_Core/ChangeLog 2014-01-09 02:37:58 UTC (rev 161538)
@@ -1,3 +1,15 @@
+2014-01-08 Sam Weinig <[email protected]>
+
+ [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 <[email protected]>
[EFL] Make FTL buildable
Modified: trunk/Source/_javascript_Core/runtime/JSPromiseConstructor.cpp (161537 => 161538)
--- trunk/Source/_javascript_Core/runtime/JSPromiseConstructor.cpp 2014-01-09 02:21:49 UTC (rev 161537)
+++ trunk/Source/_javascript_Core/runtime/JSPromiseConstructor.cpp 2014-01-09 02:37:58 UTC (rev 161538)
@@ -153,10 +153,10 @@
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)