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 20 matching lines...) Expand all Loading... | |
31 var promiseRaw = GLOBAL_PRIVATE("Promise#raw"); | 31 var promiseRaw = GLOBAL_PRIVATE("Promise#raw"); |
32 | 32 |
33 (function() { | 33 (function() { |
34 | 34 |
35 var $Promise = function Promise(resolver) { | 35 var $Promise = function Promise(resolver) { |
36 if (resolver === promiseRaw) return; | 36 if (resolver === promiseRaw) return; |
37 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); | 37 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); |
38 if (!IS_SPEC_FUNCTION(resolver)) | 38 if (!IS_SPEC_FUNCTION(resolver)) |
39 throw MakeTypeError('resolver_not_a_function', [resolver]); | 39 throw MakeTypeError('resolver_not_a_function', [resolver]); |
40 var promise = PromiseInit(this); | 40 var promise = PromiseInit(this); |
41 if (DEBUG_IS_ACTIVE) { | |
42 %DebugPromiseEvent({ type : "new Promise", | |
43 promise: this, | |
aandrey
2014/06/29 12:16:00
this -> promise?
Yang
2014/06/30 11:11:59
Done.
| |
44 resolver: resolver }); | |
45 } | |
41 try { | 46 try { |
42 %DebugPromiseHandlePrologue(function() { return promise }); | 47 %DebugPromiseHandlePrologue(function() { return promise }); |
43 resolver(function(x) { PromiseResolve(promise, x) }, | 48 resolver(function(x) { PromiseResolve(promise, x) }, |
44 function(r) { PromiseReject(promise, r) }); | 49 function(r) { PromiseReject(promise, r) }); |
45 } catch (e) { | 50 } catch (e) { |
46 PromiseReject(promise, e); | 51 PromiseReject(promise, e); |
47 } finally { | 52 } finally { |
48 %DebugPromiseHandleEpilogue(); | 53 %DebugPromiseHandleEpilogue(); |
49 } | 54 } |
50 } | 55 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 "race", PromiseOne, | 313 "race", PromiseOne, |
309 "resolve", PromiseCast | 314 "resolve", PromiseCast |
310 ]); | 315 ]); |
311 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 316 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
312 "chain", PromiseChain, | 317 "chain", PromiseChain, |
313 "then", PromiseThen, | 318 "then", PromiseThen, |
314 "catch", PromiseCatch | 319 "catch", PromiseCatch |
315 ]); | 320 ]); |
316 | 321 |
317 })(); | 322 })(); |
OLD | NEW |