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 21 matching lines...) Expand all Loading... | |
32 var lastMicrotaskId = 0; | 32 var lastMicrotaskId = 0; |
33 | 33 |
34 (function() { | 34 (function() { |
35 | 35 |
36 var $Promise = function Promise(resolver) { | 36 var $Promise = function Promise(resolver) { |
37 if (resolver === promiseRaw) return; | 37 if (resolver === promiseRaw) return; |
38 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); | 38 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); |
39 if (!IS_SPEC_FUNCTION(resolver)) | 39 if (!IS_SPEC_FUNCTION(resolver)) |
40 throw MakeTypeError('resolver_not_a_function', [resolver]); | 40 throw MakeTypeError('resolver_not_a_function', [resolver]); |
41 var promise = PromiseInit(this); | 41 var promise = PromiseInit(this); |
42 if (DEBUG_IS_ACTIVE) { | |
43 %DebugPromiseEvent({ type : "new", | |
44 promise: this, | |
45 resolver: resolver }); | |
46 } | |
47 try { | 42 try { |
48 %DebugPromiseHandlePrologue(function() { return promise }); | 43 %DebugPromiseHandlePrologue(function() { return promise }); |
49 resolver(function(x) { PromiseResolve(promise, x) }, | 44 resolver(function(x) { PromiseResolve(promise, x) }, |
50 function(r) { PromiseReject(promise, r) }); | 45 function(r) { PromiseReject(promise, r) }); |
51 } catch (e) { | 46 } catch (e) { |
52 PromiseReject(promise, e); | 47 PromiseReject(promise, e); |
53 } finally { | 48 } finally { |
54 %DebugPromiseHandleEpilogue(); | 49 %DebugPromiseHandleEpilogue(); |
55 } | 50 } |
56 } | 51 } |
57 | 52 |
58 // Core functionality. | 53 // Core functionality. |
59 | 54 |
60 function PromiseSet(promise, status, value, onResolve, onReject) { | 55 function PromiseSet(promise, status, value, onResolve, onReject) { |
61 SET_PRIVATE(promise, promiseStatus, status); | 56 SET_PRIVATE(promise, promiseStatus, status); |
62 SET_PRIVATE(promise, promiseValue, value); | 57 SET_PRIVATE(promise, promiseValue, value); |
63 SET_PRIVATE(promise, promiseOnResolve, onResolve); | 58 SET_PRIVATE(promise, promiseOnResolve, onResolve); |
64 SET_PRIVATE(promise, promiseOnReject, onReject); | 59 SET_PRIVATE(promise, promiseOnReject, onReject); |
65 if (DEBUG_IS_ACTIVE && status !== 0) { | 60 if (DEBUG_IS_ACTIVE) { |
66 %DebugPromiseEvent({ type: "update", | 61 var type = status === 0 ? "new" : "update"; |
aandrey
2014/08/01 07:46:18
remove this and the "type". if you really need it,
Alexandra Mikhaylova
2014/08/01 12:23:06
Removed this as we can tell the type of event usin
| |
62 %DebugPromiseEvent({ type: type, | |
67 promise: promise, | 63 promise: promise, |
68 status: status, | 64 status: status, |
69 value: value }); | 65 value: value }); |
70 } | 66 } |
71 return promise; | 67 return promise; |
72 } | 68 } |
73 | 69 |
74 function PromiseInit(promise) { | 70 function PromiseInit(promise) { |
75 return PromiseSet( | 71 return PromiseSet( |
76 promise, 0, UNDEFINED, new InternalArray, new InternalArray) | 72 promise, 0, UNDEFINED, new InternalArray, new InternalArray) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 "race", PromiseOne, | 341 "race", PromiseOne, |
346 "resolve", PromiseCast | 342 "resolve", PromiseCast |
347 ]); | 343 ]); |
348 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 344 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
349 "chain", PromiseChain, | 345 "chain", PromiseChain, |
350 "then", PromiseThen, | 346 "then", PromiseThen, |
351 "catch", PromiseCatch | 347 "catch", PromiseCatch |
352 ]); | 348 ]); |
353 | 349 |
354 })(); | 350 })(); |
OLD | NEW |