| 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Object = global.Object | 9 // var $Object = global.Object |
| 10 // var $WeakMap = global.WeakMap | 10 // var $WeakMap = global.WeakMap |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 SET_PRIVATE(promise, promiseStatus, status); | 60 SET_PRIVATE(promise, promiseStatus, status); |
| 61 SET_PRIVATE(promise, promiseValue, value); | 61 SET_PRIVATE(promise, promiseValue, value); |
| 62 SET_PRIVATE(promise, promiseOnResolve, onResolve); | 62 SET_PRIVATE(promise, promiseOnResolve, onResolve); |
| 63 SET_PRIVATE(promise, promiseOnReject, onReject); | 63 SET_PRIVATE(promise, promiseOnReject, onReject); |
| 64 if (DEBUG_IS_ACTIVE) { | 64 if (DEBUG_IS_ACTIVE) { |
| 65 %DebugPromiseEvent({ promise: promise, status: status, value: value }); | 65 %DebugPromiseEvent({ promise: promise, status: status, value: value }); |
| 66 } | 66 } |
| 67 return promise; | 67 return promise; |
| 68 } | 68 } |
| 69 | 69 |
| 70 function PromiseCreateAndSet(status, value) { |
| 71 var promise = new $Promise(promiseRaw); |
| 72 // If debug is active, notify about the newly created promise first. |
| 73 if (DEBUG_IS_ACTIVE) PromiseSet(promise, 0, UNDEFINED); |
| 74 return PromiseSet(promise, status, value); |
| 75 } |
| 76 |
| 70 function PromiseInit(promise) { | 77 function PromiseInit(promise) { |
| 71 return PromiseSet( | 78 return PromiseSet( |
| 72 promise, 0, UNDEFINED, new InternalArray, new InternalArray) | 79 promise, 0, UNDEFINED, new InternalArray, new InternalArray) |
| 73 } | 80 } |
| 74 | 81 |
| 75 function PromiseDone(promise, status, value, promiseQueue) { | 82 function PromiseDone(promise, status, value, promiseQueue) { |
| 76 if (GET_PRIVATE(promise, promiseStatus) === 0) { | 83 if (GET_PRIVATE(promise, promiseStatus) === 0) { |
| 77 var tasks = GET_PRIVATE(promise, promiseQueue); | 84 var tasks = GET_PRIVATE(promise, promiseQueue); |
| 78 if (tasks.length) PromiseEnqueue(value, tasks, status); | 85 if (tasks.length) PromiseEnqueue(value, tasks, status); |
| 79 PromiseSet(promise, status, value); | 86 PromiseSet(promise, status, value); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 result.resolve = resolve; | 197 result.resolve = resolve; |
| 191 result.reject = reject; | 198 result.reject = reject; |
| 192 }) | 199 }) |
| 193 return result; | 200 return result; |
| 194 } | 201 } |
| 195 } | 202 } |
| 196 | 203 |
| 197 function PromiseResolved(x) { | 204 function PromiseResolved(x) { |
| 198 if (this === $Promise) { | 205 if (this === $Promise) { |
| 199 // Optimized case, avoid extra closure. | 206 // Optimized case, avoid extra closure. |
| 200 return PromiseSet(new $Promise(promiseRaw), +1, x); | 207 return PromiseCreateAndSet(+1, x); |
| 201 } else { | 208 } else { |
| 202 return new this(function(resolve, reject) { resolve(x) }); | 209 return new this(function(resolve, reject) { resolve(x) }); |
| 203 } | 210 } |
| 204 } | 211 } |
| 205 | 212 |
| 206 function PromiseRejected(r) { | 213 function PromiseRejected(r) { |
| 207 var promise; | 214 var promise; |
| 208 if (this === $Promise) { | 215 if (this === $Promise) { |
| 209 // Optimized case, avoid extra closure. | 216 // Optimized case, avoid extra closure. |
| 210 promise = PromiseSet(new $Promise(promiseRaw), -1, r); | 217 promise = PromiseCreateAndSet(-1, r); |
| 211 // The debug event for this would always be an uncaught promise reject, | 218 // The debug event for this would always be an uncaught promise reject, |
| 212 // which is usually simply noise. Do not trigger that debug event. | 219 // which is usually simply noise. Do not trigger that debug event. |
| 213 %PromiseRejectEvent(promise, r, false); | 220 %PromiseRejectEvent(promise, r, false); |
| 214 } else { | 221 } else { |
| 215 promise = new this(function(resolve, reject) { reject(r) }); | 222 promise = new this(function(resolve, reject) { reject(r) }); |
| 216 } | 223 } |
| 217 return promise; | 224 return promise; |
| 218 } | 225 } |
| 219 | 226 |
| 220 // Simple chaining. | 227 // Simple chaining. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 "race", PromiseOne, | 391 "race", PromiseOne, |
| 385 "resolve", PromiseCast | 392 "resolve", PromiseCast |
| 386 ]); | 393 ]); |
| 387 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 394 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 388 "chain", PromiseChain, | 395 "chain", PromiseChain, |
| 389 "then", PromiseThen, | 396 "then", PromiseThen, |
| 390 "catch", PromiseCatch | 397 "catch", PromiseCatch |
| 391 ]); | 398 ]); |
| 392 | 399 |
| 393 })(); | 400 })(); |
| OLD | NEW |