Commit b7b40e2b authored by rossberg@chromium.org's avatar rossberg@chromium.org

Remove Promise.cast

...as per January meeting. Renames 'cast' to 'resolve'. We rename the prior 'resolve' to 'accept', to keep the chain API usable.

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/200763012

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20040 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2e555d28
...@@ -261,7 +261,7 @@ function PromiseCoerce(constructor, x) { ...@@ -261,7 +261,7 @@ function PromiseCoerce(constructor, x) {
function PromiseCast(x) { function PromiseCast(x) {
// TODO(rossberg): cannot do better until we support @@create. // TODO(rossberg): cannot do better until we support @@create.
return IsPromise(x) ? x : this.resolve(x); return IsPromise(x) ? x : new this(function(resolve) { resolve(x) });
} }
function PromiseAll(values) { function PromiseAll(values) {
...@@ -277,7 +277,7 @@ function PromiseAll(values) { ...@@ -277,7 +277,7 @@ function PromiseAll(values) {
deferred.resolve(resolutions); deferred.resolve(resolutions);
} else { } else {
for (var i = 0; i < values.length; ++i) { for (var i = 0; i < values.length; ++i) {
this.cast(values[i]).then( this.resolve(values[i]).then(
function(i, x) { function(i, x) {
resolutions[i] = x; resolutions[i] = x;
if (--count === 0) deferred.resolve(resolutions); if (--count === 0) deferred.resolve(resolutions);
...@@ -300,7 +300,7 @@ function PromiseOne(values) { ...@@ -300,7 +300,7 @@ function PromiseOne(values) {
} }
try { try {
for (var i = 0; i < values.length; ++i) { for (var i = 0; i < values.length; ++i) {
this.cast(values[i]).then( this.resolve(values[i]).then(
function(x) { deferred.resolve(x) }, function(x) { deferred.resolve(x) },
function(r) { deferred.reject(r) } function(r) { deferred.reject(r) }
); );
...@@ -319,11 +319,11 @@ function SetUpPromise() { ...@@ -319,11 +319,11 @@ function SetUpPromise() {
global_receiver.Promise = $Promise; global_receiver.Promise = $Promise;
InstallFunctions($Promise, DONT_ENUM, [ InstallFunctions($Promise, DONT_ENUM, [
"defer", PromiseDeferred, "defer", PromiseDeferred,
"resolve", PromiseResolved, "accept", PromiseResolved,
"reject", PromiseRejected, "reject", PromiseRejected,
"all", PromiseAll, "all", PromiseAll,
"race", PromiseOne, "race", PromiseOne,
"cast", PromiseCast "resolve", PromiseCast
]); ]);
InstallFunctions($Promise.prototype, DONT_ENUM, [ InstallFunctions($Promise.prototype, DONT_ENUM, [
"chain", PromiseChain, "chain", PromiseChain,
......
This diff is collapsed.
Test Promise.cast Test Promise.resolve as cast
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
...@@ -23,23 +23,23 @@ ...@@ -23,23 +23,23 @@
// Flags: --harmony // Flags: --harmony
'use strict'; 'use strict';
description('Test Promise.cast'); description('Test Promise.resolve as cast');
var result = undefined; var result = undefined;
var result2 = undefined; var result2 = undefined;
var resolve; var resolve;
var value = new Promise(function (r) { resolve = r;} ); var value = new Promise(function (r) { resolve = r;} );
var promise = Promise.cast(value); var promise = Promise.resolve(value);
// If [[IsPromise]] is true, Promise.cast simply returns argument. // If [[IsPromise]] is true, Promise.resolve simply returns argument.
shouldBe('promise', 'value'); shouldBe('promise', 'value');
promise.then(function(res) { promise.then(function(res) {
result = res; result = res;
shouldBeEqualToString('result', 'hello'); shouldBeEqualToString('result', 'hello');
return Promise.cast(42).then(function (res) { return Promise.resolve(42).then(function (res) {
result2 = res; result2 = res;
shouldBe('result2', '42'); shouldBe('result2', '42');
}); });
......
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