OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 var p1 = new MyPromise(function(resolve, reject) { resolve(1) }) | 1004 var p1 = new MyPromise(function(resolve, reject) { resolve(1) }) |
1005 var p2 = new MyPromise(function(resolve, reject) { reject(2) }) | 1005 var p2 = new MyPromise(function(resolve, reject) { reject(2) }) |
1006 var d3 = MyPromise.defer() | 1006 var d3 = MyPromise.defer() |
1007 assertTrue(d3.promise instanceof Promise, "subclass/instance") | 1007 assertTrue(d3.promise instanceof Promise, "subclass/instance") |
1008 assertTrue(d3.promise instanceof MyPromise, "subclass/instance-my3") | 1008 assertTrue(d3.promise instanceof MyPromise, "subclass/instance-my3") |
1009 assertTrue(log === "nx1nr2dn", "subclass/create") | 1009 assertTrue(log === "nx1nr2dn", "subclass/create") |
1010 | 1010 |
1011 log = "" | 1011 log = "" |
1012 var p4 = MyPromise.resolve(4) | 1012 var p4 = MyPromise.resolve(4) |
1013 var p5 = MyPromise.reject(5) | 1013 var p5 = MyPromise.reject(5) |
1014 assertTrue(p4 instanceof Promise, "subclass/instance4") | 1014 assertTrue(p4 instanceof MyPromise, "subclass/instance4") |
1015 assertTrue(p4 instanceof MyPromise, "subclass/instance-my4") | 1015 assertTrue(p4 instanceof MyPromise, "subclass/instance-my4") |
1016 assertTrue(p5 instanceof Promise, "subclass/instance5") | 1016 assertTrue(p5 instanceof MyPromise, "subclass/instance5") |
1017 assertTrue(p5 instanceof MyPromise, "subclass/instance-my5") | 1017 assertTrue(p5 instanceof MyPromise, "subclass/instance-my5") |
1018 d3.resolve(3) | 1018 d3.resolve(3) |
1019 assertTrue(log === "nx4nr5x3", "subclass/resolve") | 1019 assertTrue(log === "nx4nr5x3", "subclass/resolve") |
1020 | 1020 |
1021 log = "" | 1021 log = "" |
1022 var d6 = MyPromise.defer() | 1022 var d6 = MyPromise.defer() |
1023 d6.promise.chain(function(x) { | 1023 d6.promise.chain(function(x) { |
1024 return new Promise(function(resolve) { resolve(x) }) | 1024 return new Promise(function(resolve) { resolve(x) }) |
1025 }).chain(function() {}) | 1025 }).chain(function() {}) |
1026 d6.resolve(6) | 1026 d6.resolve(6) |
1027 assertTrue(log === "dncncnx6", "subclass/chain") | 1027 assertTrue(log === "dncncnx6", "subclass/chain") |
1028 | 1028 |
1029 log = "" | 1029 log = "" |
1030 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) | 1030 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) |
1031 assertTrue(log === "nx14n", "subclass/all/arg") | 1031 |
| 1032 assertTrue(log === "nx14", "subclass/all/arg") |
1032 | 1033 |
1033 log = "" | 1034 log = "" |
1034 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) | 1035 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) |
1035 assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") | 1036 assertTrue(log === "nx24nnx21nnnnx23nnnx25nnx26n", "subclass/all/self") |
1036 })(); | 1037 })(); |
1037 | 1038 |
| 1039 (function() { |
| 1040 'use strict'; |
| 1041 |
| 1042 class Pact extends Promise { } |
| 1043 class Vow extends Pact { } |
| 1044 class Oath extends Vow { } |
| 1045 |
| 1046 Oath.constructor = Vow; |
| 1047 |
| 1048 assertTrue(Pact.resolve(Pact.resolve()).constructor === Pact, |
| 1049 "subclass/resolve/own"); |
| 1050 |
| 1051 assertTrue(Pact.resolve(Promise.resolve()).constructor === Pact, |
| 1052 "subclass/resolve/ancestor"); |
| 1053 |
| 1054 assertTrue(Pact.resolve(Vow.resolve()).constructor === Pact, |
| 1055 "subclass/resolve/descendant"); var vow = Vow.resolve(); |
| 1056 |
| 1057 vow.constructor = Oath; |
| 1058 assertTrue(Oath.resolve(vow) === vow, |
| 1059 "subclass/resolve/descendant with transplanted own constructor"); |
| 1060 }()); |
1038 | 1061 |
1039 assertAsyncDone() | 1062 assertAsyncDone() |
OLD | NEW |