| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 break; | 166 break; |
| 167 } | 167 } |
| 168 return deferred.promise; | 168 return deferred.promise; |
| 169 } | 169 } |
| 170 | 170 |
| 171 function PromiseCatch(onReject) { | 171 function PromiseCatch(onReject) { |
| 172 return this.then(UNDEFINED, onReject); | 172 return this.then(UNDEFINED, onReject); |
| 173 } | 173 } |
| 174 | 174 |
| 175 function PromiseEnqueue(value, tasks) { | 175 function PromiseEnqueue(value, tasks) { |
| 176 GetMicrotaskQueue().push(function() { | 176 EnqueueMicrotask(function() { |
| 177 for (var i = 0; i < tasks.length; i += 2) { | 177 for (var i = 0; i < tasks.length; i += 2) { |
| 178 PromiseHandle(value, tasks[i], tasks[i + 1]) | 178 PromiseHandle(value, tasks[i], tasks[i + 1]) |
| 179 } | 179 } |
| 180 }); | 180 }); |
| 181 | |
| 182 %SetMicrotaskPending(true); | |
| 183 } | 181 } |
| 184 | 182 |
| 185 function PromiseHandle(value, handler, deferred) { | 183 function PromiseHandle(value, handler, deferred) { |
| 186 try { | 184 try { |
| 187 var result = handler(value); | 185 var result = handler(value); |
| 188 if (result === deferred.promise) | 186 if (result === deferred.promise) |
| 189 throw MakeTypeError('promise_cyclic', [result]); | 187 throw MakeTypeError('promise_cyclic', [result]); |
| 190 else if (IsPromise(result)) | 188 else if (IsPromise(result)) |
| 191 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); | 189 %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); |
| 192 else | 190 else |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 "resolve", PromiseCast | 316 "resolve", PromiseCast |
| 319 ]); | 317 ]); |
| 320 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 318 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 321 "chain", PromiseChain, | 319 "chain", PromiseChain, |
| 322 "then", PromiseThen, | 320 "then", PromiseThen, |
| 323 "catch", PromiseCatch | 321 "catch", PromiseCatch |
| 324 ]); | 322 ]); |
| 325 } | 323 } |
| 326 | 324 |
| 327 SetUpPromise(); | 325 SetUpPromise(); |
| OLD | NEW |