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 "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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 } | 99 } |
| 100 return x; | 100 return x; |
| 101 } | 101 } |
| 102 | 102 |
| 103 function PromiseHandle(value, handler, deferred) { | 103 function PromiseHandle(value, handler, deferred) { |
| 104 try { | 104 try { |
| 105 %DebugPushPromise(deferred.promise); | 105 %DebugPushPromise(deferred.promise); |
| 106 var result = handler(value); | 106 var result = handler(value); |
| 107 if (result === deferred.promise) | 107 if (result === deferred.promise) |
| 108 throw MakeTypeError('promise_cyclic', [result]); | 108 throw MakeTypeError('promise_cyclic', [result]); |
| 109 else if (IsPromise(result)) | 109 else if (IsUnforgedPromise(result)) |
| 110 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); | 110 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
| 111 else | 111 else |
| 112 deferred.resolve(result); | 112 deferred.resolve(result); |
| 113 } catch (exception) { | 113 } catch (exception) { |
| 114 try { deferred.reject(exception); } catch (e) { } | 114 try { deferred.reject(exception); } catch (e) { } |
| 115 } finally { | 115 } finally { |
| 116 %DebugPopPromise(); | 116 %DebugPopPromise(); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 144 | 144 |
| 145 // ------------------------------------------------------------------- | 145 // ------------------------------------------------------------------- |
| 146 // Define exported functions. | 146 // Define exported functions. |
| 147 | 147 |
| 148 // For bootstrapper. | 148 // For bootstrapper. |
| 149 | 149 |
| 150 IsPromise = function IsPromise(x) { | 150 IsPromise = function IsPromise(x) { |
| 151 return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatus); | 151 return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatus); |
| 152 } | 152 } |
| 153 | 153 |
| 154 IsUnforgedPromise = function IsUnforgedPromise(x) { | |
|
arv (Not doing code reviews)
2015/04/17 14:32:06
Does this need to be exported?
yhirano
2015/04/30 05:05:16
Deleted.
| |
| 155 if (!IsPromise(x)) { | |
| 156 return false; | |
| 157 } | |
| 158 try { | |
| 159 return x.then === PromiseThen; | |
|
arv (Not doing code reviews)
2015/04/17 14:32:06
This needs a test to ensure that the getter is inv
arv (Not doing code reviews)
2015/04/17 14:32:06
Which section of the ES6 spec defines this? I cann
yhirano
2015/04/30 05:05:16
Deleted.
yhirano
2015/04/30 05:05:16
Deleted.
| |
| 160 } catch (e) { | |
| 161 return false; | |
| 162 } | |
| 163 } | |
| 164 | |
| 154 PromiseCreate = function PromiseCreate() { | 165 PromiseCreate = function PromiseCreate() { |
| 155 return new $Promise(PromiseNopResolver) | 166 return new $Promise(PromiseNopResolver) |
| 156 } | 167 } |
| 157 | 168 |
| 158 PromiseResolve = function PromiseResolve(promise, x) { | 169 PromiseResolve = function PromiseResolve(promise, x) { |
| 159 PromiseDone(promise, +1, x, promiseOnResolve) | 170 PromiseDone(promise, +1, x, promiseOnResolve) |
| 160 } | 171 } |
| 161 | 172 |
| 162 PromiseReject = function PromiseReject(promise, r) { | 173 PromiseReject = function PromiseReject(promise, r) { |
| 163 // Check promise status to confirm that this reject has an effect. | 174 // Check promise status to confirm that this reject has an effect. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 "race", PromiseOne, | 386 "race", PromiseOne, |
| 376 "resolve", PromiseCast | 387 "resolve", PromiseCast |
| 377 ]); | 388 ]); |
| 378 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 389 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 379 "chain", PromiseChain, | 390 "chain", PromiseChain, |
| 380 "then", PromiseThen, | 391 "then", PromiseThen, |
| 381 "catch", PromiseCatch | 392 "catch", PromiseCatch |
| 382 ]); | 393 ]); |
| 383 | 394 |
| 384 })(); | 395 })(); |
| OLD | NEW |