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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 (function() { | 38 (function() { |
39 | 39 |
40 var $Promise = function Promise(resolver) { | 40 var $Promise = function Promise(resolver) { |
41 if (resolver === promiseRaw) return; | 41 if (resolver === promiseRaw) return; |
42 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); | 42 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); |
43 if (!IS_SPEC_FUNCTION(resolver)) | 43 if (!IS_SPEC_FUNCTION(resolver)) |
44 throw MakeTypeError('resolver_not_a_function', [resolver]); | 44 throw MakeTypeError('resolver_not_a_function', [resolver]); |
45 var promise = PromiseInit(this); | 45 var promise = PromiseInit(this); |
46 try { | 46 try { |
47 %DebugPushPromise(promise); | 47 %DebugPushPromise(promise, Promise); |
48 resolver(function(x) { PromiseResolve(promise, x) }, | 48 resolver(function(x) { PromiseResolve(promise, x) }, |
49 function(r) { PromiseReject(promise, r) }); | 49 function(r) { PromiseReject(promise, r) }); |
50 } catch (e) { | 50 } catch (e) { |
51 PromiseReject(promise, e); | 51 PromiseReject(promise, e); |
52 } finally { | 52 } finally { |
53 %DebugPopPromise(); | 53 %DebugPopPromise(); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 // Core functionality. | 57 // Core functionality. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 deferred.reject(r); | 103 deferred.reject(r); |
104 } | 104 } |
105 return deferred.promise; | 105 return deferred.promise; |
106 } | 106 } |
107 } | 107 } |
108 return x; | 108 return x; |
109 } | 109 } |
110 | 110 |
111 function PromiseHandle(value, handler, deferred) { | 111 function PromiseHandle(value, handler, deferred) { |
112 try { | 112 try { |
113 %DebugPushPromise(deferred.promise); | 113 %DebugPushPromise(deferred.promise, PromiseHandle); |
114 DEBUG_PREPARE_STEP_IN_IF_STEPPING(handler); | 114 DEBUG_PREPARE_STEP_IN_IF_STEPPING(handler); |
115 var result = handler(value); | 115 var result = handler(value); |
116 if (result === deferred.promise) | 116 if (result === deferred.promise) |
117 throw MakeTypeError('promise_cyclic', [result]); | 117 throw MakeTypeError('promise_cyclic', [result]); |
118 else if (IsPromise(result)) | 118 else if (IsPromise(result)) |
119 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); | 119 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
120 else | 120 else |
121 deferred.resolve(result); | 121 deferred.resolve(result); |
122 } catch (exception) { | 122 } catch (exception) { |
123 try { deferred.reject(exception); } catch (e) { } | 123 try { deferred.reject(exception); } catch (e) { } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 "race", PromiseRace, | 384 "race", PromiseRace, |
385 "resolve", PromiseCast | 385 "resolve", PromiseCast |
386 ]); | 386 ]); |
387 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 387 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
388 "chain", PromiseChain, | 388 "chain", PromiseChain, |
389 "then", PromiseThen, | 389 "then", PromiseThen, |
390 "catch", PromiseCatch | 390 "catch", PromiseCatch |
391 ]); | 391 ]); |
392 | 392 |
393 })(); | 393 })(); |
OLD | NEW |