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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 | 36 |
37 var $Promise = Promise; | 37 var $Promise = Promise; |
38 | 38 |
39 | 39 |
40 //------------------------------------------------------------------- | 40 //------------------------------------------------------------------- |
41 | 41 |
42 // Core functionality. | 42 // Core functionality. |
43 | 43 |
44 // Status values: 0 = pending, +1 = resolved, -1 = rejected | 44 // Status values: 0 = pending, +1 = resolved, -1 = rejected |
45 var promiseStatus = NEW_PRIVATE("Promise#status"); | 45 var promiseStatus = GLOBAL_PRIVATE("Promise#status"); |
46 var promiseValue = NEW_PRIVATE("Promise#value"); | 46 var promiseValue = GLOBAL_PRIVATE("Promise#value"); |
47 var promiseOnResolve = NEW_PRIVATE("Promise#onResolve"); | 47 var promiseOnResolve = GLOBAL_PRIVATE("Promise#onResolve"); |
48 var promiseOnReject = NEW_PRIVATE("Promise#onReject"); | 48 var promiseOnReject = GLOBAL_PRIVATE("Promise#onReject"); |
49 var promiseRaw = NEW_PRIVATE("Promise#raw"); | 49 var promiseRaw = GLOBAL_PRIVATE("Promise#raw"); |
50 | 50 |
51 function IsPromise(x) { | 51 function IsPromise(x) { |
52 return IS_SPEC_OBJECT(x) && %HasLocalProperty(x, promiseStatus); | 52 return IS_SPEC_OBJECT(x) && %HasLocalProperty(x, promiseStatus); |
53 } | 53 } |
54 | 54 |
55 function Promise(resolver) { | 55 function Promise(resolver) { |
56 if (resolver === promiseRaw) return; | 56 if (resolver === promiseRaw) return; |
57 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); | 57 if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); |
58 if (typeof resolver !== 'function') | 58 if (typeof resolver !== 'function') |
59 throw MakeTypeError('resolver_not_a_function', [resolver]); | 59 throw MakeTypeError('resolver_not_a_function', [resolver]); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 "resolve", PromiseCast | 318 "resolve", PromiseCast |
319 ]); | 319 ]); |
320 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 320 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
321 "chain", PromiseChain, | 321 "chain", PromiseChain, |
322 "then", PromiseThen, | 322 "then", PromiseThen, |
323 "catch", PromiseCatch | 323 "catch", PromiseCatch |
324 ]); | 324 ]); |
325 } | 325 } |
326 | 326 |
327 SetUpPromise(); | 327 SetUpPromise(); |
OLD | NEW |