Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 19 matching lines...) Expand all Loading... | |
| 30 }); | 30 }); |
| 31 | 31 |
| 32 // ------------------------------------------------------------------- | 32 // ------------------------------------------------------------------- |
| 33 | 33 |
| 34 // Status values: 0 = pending, +1 = resolved, -1 = rejected | 34 // Status values: 0 = pending, +1 = resolved, -1 = rejected |
| 35 var lastMicrotaskId = 0; | 35 var lastMicrotaskId = 0; |
| 36 | 36 |
| 37 function CreateResolvingFunctions(promise) { | 37 function CreateResolvingFunctions(promise) { |
| 38 var alreadyResolved = false; | 38 var alreadyResolved = false; |
| 39 | 39 |
| 40 var resolve = function(value) { | 40 var resolve = (0, value => { |
|
adamk
2016/01/07 22:22:28
I'd prefer to leave the "(0," out for now, and lea
| |
| 41 if (alreadyResolved === true) return; | 41 if (alreadyResolved === true) return; |
| 42 alreadyResolved = true; | 42 alreadyResolved = true; |
| 43 PromiseResolve(promise, value); | 43 PromiseResolve(promise, value); |
| 44 }; | 44 }); |
| 45 | 45 |
| 46 var reject = function(reason) { | 46 var reject = (0, reason => { |
| 47 if (alreadyResolved === true) return; | 47 if (alreadyResolved === true) return; |
| 48 alreadyResolved = true; | 48 alreadyResolved = true; |
| 49 PromiseReject(promise, reason); | 49 PromiseReject(promise, reason); |
| 50 }; | 50 }); |
| 51 | 51 |
| 52 return { | 52 return { |
| 53 __proto__: null, | 53 __proto__: null, |
| 54 resolve: resolve, | 54 resolve: resolve, |
| 55 reject: reject | 55 reject: reject |
| 56 }; | 56 }; |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 var GlobalPromise = function Promise(resolver) { | 60 var GlobalPromise = function Promise(resolver) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); | 223 var promise = PromiseInit(new GlobalPromise(promiseRawSymbol)); |
| 224 var callbacks = CreateResolvingFunctions(promise); | 224 var callbacks = CreateResolvingFunctions(promise); |
| 225 return { | 225 return { |
| 226 promise: promise, | 226 promise: promise, |
| 227 resolve: callbacks.resolve, | 227 resolve: callbacks.resolve, |
| 228 reject: callbacks.reject | 228 reject: callbacks.reject |
| 229 }; | 229 }; |
| 230 } | 230 } |
| 231 | 231 |
| 232 var result = {promise: UNDEFINED, resolve: UNDEFINED, reject: UNDEFINED }; | 232 var result = {promise: UNDEFINED, resolve: UNDEFINED, reject: UNDEFINED }; |
| 233 result.promise = new C(function(resolve, reject) { | 233 result.promise = new C((resolve, reject) => { |
| 234 if (!IS_UNDEFINED(result.resolve) || !IS_UNDEFINED(result.reject)) | 234 if (!IS_UNDEFINED(result.resolve) || !IS_UNDEFINED(result.reject)) |
| 235 throw MakeTypeError(kPromiseExecutorAlreadyInvoked); | 235 throw MakeTypeError(kPromiseExecutorAlreadyInvoked); |
| 236 result.resolve = resolve; | 236 result.resolve = resolve; |
| 237 result.reject = reject; | 237 result.reject = reject; |
| 238 }); | 238 }); |
| 239 | 239 |
| 240 if (!IS_CALLABLE(result.resolve)) | 240 if (!IS_CALLABLE(result.resolve)) |
| 241 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Resolve]]"); | 241 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Resolve]]"); |
| 242 if (!IS_CALLABLE(result.reject)) | 242 if (!IS_CALLABLE(result.reject)) |
| 243 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Reject]]"); | 243 throw MakeTypeError(kCalledNonCallable, "promiseCapability.[[Reject]]"); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 if (!IS_RECEIVER(this)) { | 341 if (!IS_RECEIVER(this)) { |
| 342 throw MakeTypeError(kCalledOnNonObject, "Promise.all"); | 342 throw MakeTypeError(kCalledOnNonObject, "Promise.all"); |
| 343 } | 343 } |
| 344 | 344 |
| 345 var deferred = NewPromiseCapability(this); | 345 var deferred = NewPromiseCapability(this); |
| 346 var resolutions = new InternalArray(); | 346 var resolutions = new InternalArray(); |
| 347 var count; | 347 var count; |
| 348 | 348 |
| 349 function CreateResolveElementFunction(index, values, promiseCapability) { | 349 function CreateResolveElementFunction(index, values, promiseCapability) { |
| 350 var alreadyCalled = false; | 350 var alreadyCalled = false; |
| 351 return function(x) { | 351 return (x) => { |
| 352 if (alreadyCalled === true) return; | 352 if (alreadyCalled === true) return; |
| 353 alreadyCalled = true; | 353 alreadyCalled = true; |
| 354 values[index] = x; | 354 values[index] = x; |
| 355 if (--count === 0) { | 355 if (--count === 0) { |
| 356 var valuesArray = []; | 356 var valuesArray = []; |
| 357 %MoveArrayContents(values, valuesArray); | 357 %MoveArrayContents(values, valuesArray); |
| 358 %_Call(promiseCapability.resolve, UNDEFINED, valuesArray); | 358 %_Call(promiseCapability.resolve, UNDEFINED, valuesArray); |
| 359 } | 359 } |
| 360 }; | 360 }; |
| 361 } | 361 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 387 } | 387 } |
| 388 | 388 |
| 389 function PromiseRace(iterable) { | 389 function PromiseRace(iterable) { |
| 390 if (!IS_RECEIVER(this)) { | 390 if (!IS_RECEIVER(this)) { |
| 391 throw MakeTypeError(kCalledOnNonObject, PromiseRace); | 391 throw MakeTypeError(kCalledOnNonObject, PromiseRace); |
| 392 } | 392 } |
| 393 | 393 |
| 394 var deferred = NewPromiseCapability(this); | 394 var deferred = NewPromiseCapability(this); |
| 395 try { | 395 try { |
| 396 for (var value of iterable) { | 396 for (var value of iterable) { |
| 397 var reject = function(r) { deferred.reject(r) }; | 397 var reject = (0, reason => { deferred.reject(reason); }); |
| 398 this.resolve(value).then(function(x) { deferred.resolve(x) }, reject); | 398 this.resolve(value).then((x) => { deferred.resolve(x) }, reject); |
| 399 SET_PRIVATE(reject, promiseCombinedDeferredSymbol, deferred); | 399 SET_PRIVATE(reject, promiseCombinedDeferredSymbol, deferred); |
| 400 } | 400 } |
| 401 } catch (e) { | 401 } catch (e) { |
| 402 deferred.reject(e) | 402 deferred.reject(e) |
| 403 } | 403 } |
| 404 return deferred.promise; | 404 return deferred.promise; |
| 405 } | 405 } |
| 406 | 406 |
| 407 | 407 |
| 408 // Utility for debugger | 408 // Utility for debugger |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 475 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
| 476 fn => %FunctionRemovePrototype(fn)); | 476 fn => %FunctionRemovePrototype(fn)); |
| 477 | 477 |
| 478 utils.Export(function(to) { | 478 utils.Export(function(to) { |
| 479 to.PromiseChain = PromiseChain; | 479 to.PromiseChain = PromiseChain; |
| 480 to.PromiseDeferred = PromiseDeferred; | 480 to.PromiseDeferred = PromiseDeferred; |
| 481 to.PromiseResolved = PromiseResolved; | 481 to.PromiseResolved = PromiseResolved; |
| 482 }); | 482 }); |
| 483 | 483 |
| 484 }) | 484 }) |
| OLD | NEW |