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

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

Issue 2592933004: [promises] Move Promise.resolve to TF (Closed)
Patch Set: throw correct typerror Created 3 years, 12 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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return promise; 137 return promise;
138 } else { 138 } else {
139 var promiseCapability = NewPromiseCapability(this, true); 139 var promiseCapability = NewPromiseCapability(this, true);
140 %_Call(promiseCapability.reject, UNDEFINED, r); 140 %_Call(promiseCapability.reject, UNDEFINED, r);
141 return promiseCapability.promise; 141 return promiseCapability.promise;
142 } 142 }
143 } 143 }
144 144
145 // Combinators. 145 // Combinators.
146 146
147 // ES#sec-promise.resolve
148 // Promise.resolve ( x )
149 function PromiseResolve(x) {
150 if (!IS_RECEIVER(this)) {
151 throw %make_type_error(kCalledOnNonObject, PromiseResolve);
152 }
153 if (%is_promise(x) && x.constructor === this) return x;
154
155 // Avoid creating resolving functions.
156 if (this === GlobalPromise) {
157 var promise = %promise_internal_constructor(UNDEFINED);
158 %promise_resolve(promise, x);
159 return promise;
160 }
161
162 // debugEvent is not so meaningful here as it will be resolved
163 var promiseCapability = NewPromiseCapability(this, true);
164 %_Call(promiseCapability.resolve, UNDEFINED, x);
165 return promiseCapability.promise;
166 }
167
168 // ES#sec-promise.all 147 // ES#sec-promise.all
169 // Promise.all ( iterable ) 148 // Promise.all ( iterable )
170 function PromiseAll(iterable) { 149 function PromiseAll(iterable) {
171 if (!IS_RECEIVER(this)) { 150 if (!IS_RECEIVER(this)) {
172 throw %make_type_error(kCalledOnNonObject, "Promise.all"); 151 throw %make_type_error(kCalledOnNonObject, "Promise.all");
173 } 152 }
174 153
175 // false debugEvent so that forwarding the rejection through all does not 154 // false debugEvent so that forwarding the rejection through all does not
176 // trigger redundant ExceptionEvents 155 // trigger redundant ExceptionEvents
177 var deferred = NewPromiseCapability(this, false); 156 var deferred = NewPromiseCapability(this, false);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 %PromiseMarkAsHandled(promise); 308 %PromiseMarkAsHandled(promise);
330 } 309 }
331 310
332 // ------------------------------------------------------------------- 311 // -------------------------------------------------------------------
333 // Install exported functions. 312 // Install exported functions.
334 313
335 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [ 314 utils.InstallFunctions(GlobalPromise, DONT_ENUM, [
336 "reject", PromiseReject, 315 "reject", PromiseReject,
337 "all", PromiseAll, 316 "all", PromiseAll,
338 "race", PromiseRace, 317 "race", PromiseRace,
339 "resolve", PromiseResolve
340 ]); 318 ]);
341 319
342 %InstallToContext([ 320 %InstallToContext([
343 "promise_create", PromiseCreate, 321 "promise_create", PromiseCreate,
344 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, 322 "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
345 "promise_reject", DoRejectPromise, 323 "promise_reject", DoRejectPromise,
346 // TODO(gsathya): Remove this once we update the promise builtin. 324 // TODO(gsathya): Remove this once we update the promise builtin.
347 "promise_internal_reject", RejectPromise, 325 "promise_internal_reject", RejectPromise,
348 "promise_debug_get_info", PromiseDebugGetInfo, 326 "promise_debug_get_info", PromiseDebugGetInfo,
349 "new_promise_capability", NewPromiseCapability, 327 "new_promise_capability", NewPromiseCapability,
(...skipping 12 matching lines...) Expand all
362 ]); 340 ]);
363 341
364 utils.Export(function(to) { 342 utils.Export(function(to) {
365 to.PromiseCreate = PromiseCreate; 343 to.PromiseCreate = PromiseCreate;
366 344
367 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability; 345 to.CreateInternalPromiseCapability = CreateInternalPromiseCapability;
368 to.RejectPromise = RejectPromise; 346 to.RejectPromise = RejectPromise;
369 }); 347 });
370 348
371 }) 349 })
OLDNEW
« src/builtins/builtins-promise.cc ('K') | « src/builtins/builtins-promise.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698