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 15 matching lines...) Expand all Loading... | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // Make sure we don't rely on functions patchable by monkeys. | 30 // Make sure we don't rely on functions patchable by monkeys. |
31 var call = Function.prototype.call.call.bind(Function.prototype.call) | 31 var call = Function.prototype.call.call.bind(Function.prototype.call) |
32 var observe = Object.observe; | 32 var observe = Object.observe; |
33 var getOwnPropertyNames = Object.getOwnPropertyNames | 33 var getOwnPropertyNames = Object.getOwnPropertyNames |
34 var defineProperty = Object.defineProperty | 34 var defineProperty = Object.defineProperty |
35 | 35 |
36 | |
36 function clear(o) { | 37 function clear(o) { |
37 if (o === null || (typeof o !== 'object' && typeof o !== 'function')) return | 38 if (o === null || (typeof o !== 'object' && typeof o !== 'function')) return |
38 clear(o.__proto__) | 39 clear(o.__proto__) |
39 var properties = getOwnPropertyNames(o) | 40 var properties = getOwnPropertyNames(o) |
40 for (var i in properties) { | 41 for (var i in properties) { |
41 clearProp(o, properties[i]) | 42 clearProp(o, properties[i]) |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 function clearProp(o, name) { | 46 function clearProp(o, name) { |
46 var poisoned = {caller: 0, callee: 0, arguments: 0} | 47 var poisoned = {caller: 0, callee: 0, arguments: 0} |
47 try { | 48 try { |
48 var x = o[name] | 49 var x = o[name] |
49 o[name] = undefined | 50 o[name] = undefined |
50 clear(x) | 51 clear(x) |
51 } catch(e) {} // assertTrue(name in poisoned) } | 52 } catch(e) {} // assertTrue(name in poisoned) } |
52 } | 53 } |
53 | 54 |
54 // Find intrinsics and null them out. | 55 // Find intrinsics and null them out. |
55 var globals = Object.getOwnPropertyNames(this) | 56 var globals = Object.getOwnPropertyNames(this) |
56 var whitelist = {Promise: true, TypeError: true} | 57 var whitelist = {Promise: true, TypeError: true} |
57 for (var i in globals) { | 58 for (var i in globals) { |
58 var name = globals[i] | 59 var name = globals[i] |
59 if (name in whitelist || name[0] === name[0].toLowerCase()) delete globals[i] | 60 if (name in whitelist || name[0] === name[0].toLowerCase()) delete globals[i] |
60 } | 61 } |
62 | |
63 | |
64 (function() { | |
rossberg
2014/10/17 11:19:30
Move this to line 36.
| |
65 // Test before clearing global (fails otherwise) | |
66 assertEquals("[object Promise]", | |
67 Object.prototype.toString.call(new Promise(function() {}))); | |
68 })(); | |
69 | |
70 | |
61 for (var i in globals) { | 71 for (var i in globals) { |
62 if (globals[i]) clearProp(this, globals[i]) | 72 if (globals[i]) clearProp(this, globals[i]) |
63 } | 73 } |
64 | 74 |
65 | 75 |
66 var asyncAssertsExpected = 0; | 76 var asyncAssertsExpected = 0; |
67 | 77 |
68 function assertAsyncRan() { ++asyncAssertsExpected } | 78 function assertAsyncRan() { ++asyncAssertsExpected } |
69 | 79 |
70 function assertAsync(b, s) { | 80 function assertAsync(b, s) { |
(...skipping 14 matching lines...) Expand all Loading... | |
85 assertAsync(true, "all") | 95 assertAsync(true, "all") |
86 else if (iteration > 10) // Shouldn't take more. | 96 else if (iteration > 10) // Shouldn't take more. |
87 assertAsync(false, "all") | 97 assertAsync(false, "all") |
88 else | 98 else |
89 assertAsyncDone(iteration + 1) | 99 assertAsyncDone(iteration + 1) |
90 } | 100 } |
91 ) | 101 ) |
92 dummy.dummy = dummy | 102 dummy.dummy = dummy |
93 } | 103 } |
94 | 104 |
95 | |
96 (function() { | 105 (function() { |
97 assertThrows(function() { Promise(function() {}) }, TypeError) | 106 assertThrows(function() { Promise(function() {}) }, TypeError) |
98 })(); | 107 })(); |
99 | 108 |
100 (function() { | 109 (function() { |
101 assertTrue(new Promise(function() {}) instanceof Promise) | 110 assertTrue(new Promise(function() {}) instanceof Promise) |
102 })(); | 111 })(); |
103 | 112 |
104 (function() { | 113 (function() { |
105 assertThrows(function() { new Promise(5) }, TypeError) | 114 assertThrows(function() { new Promise(5) }, TypeError) |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) | 861 Promise.all([11, Promise.accept(12), 13, MyPromise.accept(14), 15, 16]) |
853 assertTrue(log === "nx14n", "subclass/all/arg") | 862 assertTrue(log === "nx14n", "subclass/all/arg") |
854 | 863 |
855 log = "" | 864 log = "" |
856 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) | 865 MyPromise.all([21, Promise.accept(22), 23, MyPromise.accept(24), 25, 26]) |
857 assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") | 866 assertTrue(log === "nx24nnx21nnx23nnnx25nnx26n", "subclass/all/self") |
858 })(); | 867 })(); |
859 | 868 |
860 | 869 |
861 assertAsyncDone() | 870 assertAsyncDone() |
OLD | NEW |