Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/promise.js

Issue 182613003: Promise.all and Promise.race reject non-array parameter. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/promises.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // Combinators. 241 // Combinators.
242 242
243 function PromiseCast(x) { 243 function PromiseCast(x) {
244 // TODO(rossberg): cannot do better until we support @@create. 244 // TODO(rossberg): cannot do better until we support @@create.
245 return IsPromise(x) ? x : this.resolve(x); 245 return IsPromise(x) ? x : this.resolve(x);
246 } 246 }
247 247
248 function PromiseAll(values) { 248 function PromiseAll(values) {
249 var deferred = %_CallFunction(this, PromiseDeferred); 249 var deferred = %_CallFunction(this, PromiseDeferred);
250 var resolutions = []; 250 var resolutions = [];
251 if (!%_IsArray(values)) {
252 deferred.reject(MakeTypeError('invalid_argument'));
253 return deferred.promise;
254 }
251 try { 255 try {
252 var count = values.length; 256 var count = values.length;
253 if (count === 0) { 257 if (count === 0) {
254 deferred.resolve(resolutions); 258 deferred.resolve(resolutions);
255 } else { 259 } else {
256 for (var i = 0; i < values.length; ++i) { 260 for (var i = 0; i < values.length; ++i) {
257 this.cast(values[i]).chain( 261 this.cast(values[i]).chain(
258 function(i, x) { 262 function(i, x) {
259 resolutions[i] = x; 263 resolutions[i] = x;
260 if (--count === 0) deferred.resolve(resolutions); 264 if (--count === 0) deferred.resolve(resolutions);
261 }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once available 265 }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once available
262 function(r) { deferred.reject(r) } 266 function(r) { deferred.reject(r) }
263 ); 267 );
264 } 268 }
265 } 269 }
266 } catch (e) { 270 } catch (e) {
267 deferred.reject(e) 271 deferred.reject(e)
268 } 272 }
269 return deferred.promise; 273 return deferred.promise;
270 } 274 }
271 275
272 function PromiseOne(values) { 276 function PromiseOne(values) {
273 var deferred = %_CallFunction(this, PromiseDeferred); 277 var deferred = %_CallFunction(this, PromiseDeferred);
278 if (!%_IsArray(values)) {
279 deferred.reject(MakeTypeError('invalid_argument'));
280 return deferred.promise;
281 }
274 try { 282 try {
275 for (var i = 0; i < values.length; ++i) { 283 for (var i = 0; i < values.length; ++i) {
276 this.cast(values[i]).chain( 284 this.cast(values[i]).chain(
277 function(x) { deferred.resolve(x) }, 285 function(x) { deferred.resolve(x) },
278 function(r) { deferred.reject(r) } 286 function(r) { deferred.reject(r) }
279 ); 287 );
280 } 288 }
281 } catch (e) { 289 } catch (e) {
282 deferred.reject(e) 290 deferred.reject(e)
283 } 291 }
(...skipping 15 matching lines...) Expand all
299 "cast", PromiseCast 307 "cast", PromiseCast
300 ]); 308 ]);
301 InstallFunctions($Promise.prototype, DONT_ENUM, [ 309 InstallFunctions($Promise.prototype, DONT_ENUM, [
302 "chain", PromiseChain, 310 "chain", PromiseChain,
303 "then", PromiseThen, 311 "then", PromiseThen,
304 "catch", PromiseCatch 312 "catch", PromiseCatch
305 ]); 313 ]);
306 } 314 }
307 315
308 SetUpPromise(); 316 SetUpPromise();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/promises.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698