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

Side by Side Diff: src/promise.js

Issue 1316933002: [es6] Initial steps towards a correct implementation of IsCallable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase again. Created 5 years, 3 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 | « src/objects-printer.cc ('k') | src/proxy.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 12 matching lines...) Expand all
23 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 23 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
24 24
25 // ------------------------------------------------------------------- 25 // -------------------------------------------------------------------
26 26
27 // Status values: 0 = pending, +1 = resolved, -1 = rejected 27 // Status values: 0 = pending, +1 = resolved, -1 = rejected
28 var lastMicrotaskId = 0; 28 var lastMicrotaskId = 0;
29 29
30 var GlobalPromise = function Promise(resolver) { 30 var GlobalPromise = function Promise(resolver) {
31 if (resolver === promiseRawSymbol) return; 31 if (resolver === promiseRawSymbol) return;
32 if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this); 32 if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this);
33 if (!IS_SPEC_FUNCTION(resolver)) 33 if (!IS_CALLABLE(resolver))
34 throw MakeTypeError(kResolverNotAFunction, resolver); 34 throw MakeTypeError(kResolverNotAFunction, resolver);
35 var promise = PromiseInit(this); 35 var promise = PromiseInit(this);
36 try { 36 try {
37 %DebugPushPromise(promise, Promise); 37 %DebugPushPromise(promise, Promise);
38 resolver(function(x) { PromiseResolve(promise, x) }, 38 resolver(function(x) { PromiseResolve(promise, x) },
39 function(r) { PromiseReject(promise, r) }); 39 function(r) { PromiseReject(promise, r) });
40 } catch (e) { 40 } catch (e) {
41 PromiseReject(promise, e); 41 PromiseReject(promise, e);
42 } finally { 42 } finally {
43 %DebugPopPromise(); 43 %DebugPopPromise();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 function PromiseCoerce(constructor, x) { 80 function PromiseCoerce(constructor, x) {
81 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { 81 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) {
82 var then; 82 var then;
83 try { 83 try {
84 then = x.then; 84 then = x.then;
85 } catch(r) { 85 } catch(r) {
86 return %_CallFunction(constructor, r, PromiseRejected); 86 return %_CallFunction(constructor, r, PromiseRejected);
87 } 87 }
88 if (IS_SPEC_FUNCTION(then)) { 88 if (IS_CALLABLE(then)) {
89 var deferred = %_CallFunction(constructor, PromiseDeferred); 89 var deferred = %_CallFunction(constructor, PromiseDeferred);
90 try { 90 try {
91 %_CallFunction(x, deferred.resolve, deferred.reject, then); 91 %_CallFunction(x, deferred.resolve, deferred.reject, then);
92 } catch(r) { 92 } catch(r) {
93 deferred.reject(r); 93 deferred.reject(r);
94 } 94 }
95 return deferred.promise; 95 return deferred.promise;
96 } 96 }
97 } 97 }
98 return x; 98 return x;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return deferred.promise; 252 return deferred.promise;
253 } 253 }
254 254
255 function PromiseCatch(onReject) { 255 function PromiseCatch(onReject) {
256 return this.then(UNDEFINED, onReject); 256 return this.then(UNDEFINED, onReject);
257 } 257 }
258 258
259 // Multi-unwrapped chaining with thenable coercion. 259 // Multi-unwrapped chaining with thenable coercion.
260 260
261 function PromiseThen(onResolve, onReject) { 261 function PromiseThen(onResolve, onReject) {
262 onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve 262 onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler;
263 : PromiseIdResolveHandler; 263 onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler;
264 onReject = IS_SPEC_FUNCTION(onReject) ? onReject
265 : PromiseIdRejectHandler;
266 var that = this; 264 var that = this;
267 var constructor = this.constructor; 265 var constructor = this.constructor;
268 return %_CallFunction( 266 return %_CallFunction(
269 this, 267 this,
270 function(x) { 268 function(x) {
271 x = PromiseCoerce(constructor, x); 269 x = PromiseCoerce(constructor, x);
272 if (x === that) { 270 if (x === that) {
273 DEBUG_PREPARE_STEP_IN_IF_STEPPING(onReject); 271 DEBUG_PREPARE_STEP_IN_IF_STEPPING(onReject);
274 return onReject(MakeTypeError(kPromiseCyclic, x)); 272 return onReject(MakeTypeError(kPromiseCyclic, x));
275 } else if (IsPromise(x)) { 273 } else if (IsPromise(x)) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 "promise_catch", PromiseCatch, 382 "promise_catch", PromiseCatch,
385 "promise_chain", PromiseChain, 383 "promise_chain", PromiseChain,
386 "promise_create", PromiseCreate, 384 "promise_create", PromiseCreate,
387 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 385 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
388 "promise_reject", PromiseReject, 386 "promise_reject", PromiseReject,
389 "promise_resolve", PromiseResolve, 387 "promise_resolve", PromiseResolve,
390 "promise_then", PromiseThen, 388 "promise_then", PromiseThen,
391 ]); 389 ]);
392 390
393 }) 391 })
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | src/proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698