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

Side by Side Diff: src/js/promise.js

Issue 2592933004: [promises] Move Promise.resolve to TF (Closed)
Patch Set: fix rebase Created 3 years, 11 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/builtins/builtins-promise.cc ('k') | no next file » | 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, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return promise; 61 return promise;
62 } else { 62 } else {
63 var promiseCapability = %new_promise_capability(this, true); 63 var promiseCapability = %new_promise_capability(this, true);
64 %_Call(promiseCapability.reject, UNDEFINED, r); 64 %_Call(promiseCapability.reject, UNDEFINED, r);
65 return promiseCapability.promise; 65 return promiseCapability.promise;
66 } 66 }
67 } 67 }
68 68
69 // Combinators. 69 // Combinators.
70 70
71 // ES#sec-promise.resolve
72 // Promise.resolve ( x )
73 function PromiseResolve(x) {
74 if (!IS_RECEIVER(this)) {
75 throw %make_type_error(kCalledOnNonObject, PromiseResolve);
76 }
77 if (%is_promise(x) && x.constructor === this) return x;
78
79 // Avoid creating resolving functions.
80 if (this === GlobalPromise) {
81 var promise = %promise_internal_constructor(UNDEFINED);
82 %promise_resolve(promise, x);
83 return promise;
84 }
85
86 // debugEvent is not so meaningful here as it will be resolved
87 var promiseCapability = %new_promise_capability(this, true);
88 %_Call(promiseCapability.resolve, UNDEFINED, x);
89 return promiseCapability.promise;
90 }
91
92 // ES#sec-promise.all 71 // ES#sec-promise.all
93 // Promise.all ( iterable ) 72 // Promise.all ( iterable )
94 function PromiseAll(iterable) { 73 function PromiseAll(iterable) {
95 if (!IS_RECEIVER(this)) { 74 if (!IS_RECEIVER(this)) {
96 throw %make_type_error(kCalledOnNonObject, "Promise.all"); 75 throw %make_type_error(kCalledOnNonObject, "Promise.all");
97 } 76 }
98 77
99 // false debugEvent so that forwarding the rejection through all does not 78 // false debugEvent so that forwarding the rejection through all does not
100 // trigger redundant ExceptionEvents 79 // trigger redundant ExceptionEvents
101 var deferred = %new_promise_capability(this, false); 80 var deferred = %new_promise_capability(this, false);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 %PromiseMarkAsHandled(promise); 170 %PromiseMarkAsHandled(promise);
192 } 171 }
193 172
194 // ------------------------------------------------------------------- 173 // -------------------------------------------------------------------
195 // Install exported functions. 174 // Install exported functions.
196 175
197 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ 176 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
198 "reject", PromiseReject, 177 "reject", PromiseReject,
199 "all", PromiseAll, 178 "all", PromiseAll,
200 "race", PromiseRace, 179 "race", PromiseRace,
201 "resolve", PromiseResolve
202 ]); 180 ]);
203 181
204 %InstallToContext([ 182 %InstallToContext([
205 "promise_create", PromiseCreate, 183 "promise_create", PromiseCreate,
206 "promise_reject", DoRejectPromise, 184 "promise_reject", DoRejectPromise,
207 // TODO(gsathya): Remove this once we update the promise builtin. 185 // TODO(gsathya): Remove this once we update the promise builtin.
208 "promise_internal_reject", RejectPromise, 186 "promise_internal_reject", RejectPromise,
209 "promise_id_resolve_handler", PromiseIdResolveHandler, 187 "promise_id_resolve_handler", PromiseIdResolveHandler,
210 "promise_id_reject_handler", PromiseIdRejectHandler 188 "promise_id_reject_handler", PromiseIdRejectHandler
211 ]); 189 ]);
212 190
213 // This allows extras to create promises quickly without building extra 191 // This allows extras to create promises quickly without building extra
214 // resolve/reject closures, and allows them to later resolve and reject any 192 // resolve/reject closures, and allows them to later resolve and reject any
215 // promise without having to hold on to those closures forever. 193 // promise without having to hold on to those closures forever.
216 utils.InstallFunctions(extrasUtils, 0, [ 194 utils.InstallFunctions(extrasUtils, 0, [
217 "createPromise", PromiseCreate, 195 "createPromise", PromiseCreate,
218 "rejectPromise", DoRejectPromise, 196 "rejectPromise", DoRejectPromise,
219 "markPromiseAsHandled", MarkPromiseAsHandled 197 "markPromiseAsHandled", MarkPromiseAsHandled
220 ]); 198 ]);
221 199
222 utils.Export(function(to) { 200 utils.Export(function(to) {
223 to.PromiseCreate = PromiseCreate; 201 to.PromiseCreate = PromiseCreate;
224 to.RejectPromise = RejectPromise; 202 to.RejectPromise = RejectPromise;
225 }); 203 });
226 204
227 }) 205 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-promise.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698