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

Side by Side Diff: src/promise.js

Issue 203453002: Promises: make null a legal argument for .then (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } catch(e) { 203 } catch(e) {
204 // TODO(rossberg): perhaps log uncaught exceptions below. 204 // TODO(rossberg): perhaps log uncaught exceptions below.
205 try { deferred.reject(e) } catch(e) {} 205 try { deferred.reject(e) } catch(e) {}
206 } 206 }
207 } 207 }
208 208
209 209
210 // Multi-unwrapped chaining with thenable coercion. 210 // Multi-unwrapped chaining with thenable coercion.
211 211
212 function PromiseThen(onResolve, onReject) { 212 function PromiseThen(onResolve, onReject) {
213 onResolve = IS_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; 213 onResolve =
214 IS_NULL_OR_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve;
215 onReject =
216 IS_NULL_OR_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject;
214 var that = this; 217 var that = this;
215 var constructor = this.constructor; 218 var constructor = this.constructor;
216 return this.chain( 219 return this.chain(
217 function(x) { 220 function(x) {
218 x = PromiseCoerce(constructor, x); 221 x = PromiseCoerce(constructor, x);
219 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : 222 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) :
220 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); 223 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x);
221 }, 224 },
222 onReject 225 onReject
223 ); 226 );
224 } 227 }
225 228
226 PromiseCoerce.table = new $WeakMap; 229 PromiseCoerce.table = new $WeakMap;
227 230
228 function PromiseCoerce(constructor, x) { 231 function PromiseCoerce(constructor, x) {
229 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { 232 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) {
230 var then; 233 var then;
231 try { 234 try {
232 then = x.then; 235 then = x.then;
233 } catch(e) { 236 } catch(r) {
Sven Panne 2014/03/18 14:46:18 Let me guess why you changed this... :-D
rossberg 2014/03/18 14:48:20 Reg-exps are the null pointers of parsing....
234 var deferred = %_CallFunction(constructor, PromiseDeferred); 237 var promise = %_CallFunction(constructor, r, PromiseRejected);
235 PromiseCoerce.table.set(x, deferred.promise); 238 PromiseCoerce.table.set(x, promise);
236 deferred.reject(e); 239 return promise;
237 return deferred.promise;
238 } 240 }
239 if (typeof then === 'function') { 241 if (typeof then === 'function') {
240 if (PromiseCoerce.table.has(x)) { 242 if (PromiseCoerce.table.has(x)) {
241 return PromiseCoerce.table.get(x); 243 return PromiseCoerce.table.get(x);
242 } else { 244 } else {
243 var deferred = %_CallFunction(constructor, PromiseDeferred); 245 var deferred = %_CallFunction(constructor, PromiseDeferred);
244 PromiseCoerce.table.set(x, deferred.promise); 246 PromiseCoerce.table.set(x, deferred.promise);
245 try { 247 try {
246 %_CallFunction(x, deferred.resolve, deferred.reject, then); 248 %_CallFunction(x, deferred.resolve, deferred.reject, then);
247 } catch(e) { 249 } catch(r) {
248 deferred.reject(e); 250 deferred.reject(r);
249 } 251 }
250 return deferred.promise; 252 return deferred.promise;
251 } 253 }
252 } 254 }
253 } 255 }
254 return x; 256 return x;
255 } 257 }
256 258
257 259
258 // Combinators. 260 // Combinators.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 "cast", PromiseCast 326 "cast", PromiseCast
325 ]); 327 ]);
326 InstallFunctions($Promise.prototype, DONT_ENUM, [ 328 InstallFunctions($Promise.prototype, DONT_ENUM, [
327 "chain", PromiseChain, 329 "chain", PromiseChain,
328 "then", PromiseThen, 330 "then", PromiseThen,
329 "catch", PromiseCatch 331 "catch", PromiseCatch
330 ]); 332 ]);
331 } 333 }
332 334
333 SetUpPromise(); 335 SetUpPromise();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698