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

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

Issue 2616673003: [promises] Move various promise reject functions to TF (Closed)
Patch Set: fix build 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/contexts.h ('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 28 matching lines...) Expand all
39 // Only used by async-await.js 39 // Only used by async-await.js
40 function RejectPromise(promise, reason, debugEvent) { 40 function RejectPromise(promise, reason, debugEvent) {
41 %PromiseReject(promise, reason, debugEvent); 41 %PromiseReject(promise, reason, debugEvent);
42 } 42 }
43 43
44 // Export to bindings 44 // Export to bindings
45 function DoRejectPromise(promise, reason) { 45 function DoRejectPromise(promise, reason) {
46 %PromiseReject(promise, reason, true); 46 %PromiseReject(promise, reason, true);
47 } 47 }
48 48
49 // ES#sec-promise.reject
50 // Promise.reject ( x )
51 function PromiseReject(r) {
52 if (!IS_RECEIVER(this)) {
53 throw %make_type_error(kCalledOnNonObject, PromiseReject);
54 }
55 if (this === GlobalPromise) {
56 // Optimized case, avoid extra closure.
57 var promise = %promise_create_and_set(kRejected, r);
58 // Trigger debug events if the debugger is on, as Promise.reject is
59 // equivalent to throwing an exception directly.
60 %PromiseRejectEventFromStack(promise, r);
61 return promise;
62 } else {
63 var promiseCapability = %new_promise_capability(this, true);
64 %_Call(promiseCapability.reject, UNDEFINED, r);
65 return promiseCapability.promise;
66 }
67 }
68
69 // Combinators. 49 // Combinators.
70 50
71 // ES#sec-promise.all 51 // ES#sec-promise.all
72 // Promise.all ( iterable ) 52 // Promise.all ( iterable )
73 function PromiseAll(iterable) { 53 function PromiseAll(iterable) {
74 if (!IS_RECEIVER(this)) { 54 if (!IS_RECEIVER(this)) {
75 throw %make_type_error(kCalledOnNonObject, "Promise.all"); 55 throw %make_type_error(kCalledOnNonObject, "Promise.all");
76 } 56 }
77 57
78 // false debugEvent so that forwarding the rejection through all does not 58 // false debugEvent so that forwarding the rejection through all does not
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 147 }
168 148
169 function MarkPromiseAsHandled(promise) { 149 function MarkPromiseAsHandled(promise) {
170 %PromiseMarkAsHandled(promise); 150 %PromiseMarkAsHandled(promise);
171 } 151 }
172 152
173 // ------------------------------------------------------------------- 153 // -------------------------------------------------------------------
174 // Install exported functions. 154 // Install exported functions.
175 155
176 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ 156 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
177 "reject", PromiseReject,
178 "all", PromiseAll, 157 "all", PromiseAll,
179 "race", PromiseRace, 158 "race", PromiseRace,
180 ]); 159 ]);
181 160
182 %InstallToContext([ 161 %InstallToContext([
183 "promise_create", PromiseCreate, 162 "promise_create", PromiseCreate,
184 "promise_reject", DoRejectPromise, 163 "promise_reject", DoRejectPromise,
185 // TODO(gsathya): Remove this once we update the promise builtin.
186 "promise_internal_reject", RejectPromise,
187 "promise_id_resolve_handler", PromiseIdResolveHandler, 164 "promise_id_resolve_handler", PromiseIdResolveHandler,
188 "promise_id_reject_handler", PromiseIdRejectHandler 165 "promise_id_reject_handler", PromiseIdRejectHandler
189 ]); 166 ]);
190 167
191 // This allows extras to create promises quickly without building extra 168 // This allows extras to create promises quickly without building extra
192 // resolve/reject closures, and allows them to later resolve and reject any 169 // resolve/reject closures, and allows them to later resolve and reject any
193 // promise without having to hold on to those closures forever. 170 // promise without having to hold on to those closures forever.
194 utils.InstallFunctions(extrasUtils, 0, [ 171 utils.InstallFunctions(extrasUtils, 0, [
195 "createPromise", PromiseCreate, 172 "createPromise", PromiseCreate,
196 "rejectPromise", DoRejectPromise, 173 "rejectPromise", DoRejectPromise,
197 "markPromiseAsHandled", MarkPromiseAsHandled 174 "markPromiseAsHandled", MarkPromiseAsHandled
198 ]); 175 ]);
199 176
200 utils.Export(function(to) { 177 utils.Export(function(to) {
201 to.PromiseCreate = PromiseCreate; 178 to.PromiseCreate = PromiseCreate;
202 to.RejectPromise = RejectPromise; 179 to.RejectPromise = RejectPromise;
203 }); 180 });
204 181
205 }) 182 })
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698