OLD | NEW |
1 // Run all the code in a local scope. | 1 // * |globalObject| should be the global (usually |this|). |
2 (function(globalObject) { | 2 // * |propertyNamesInGlobal| should be a list of properties captured before |
| 3 // other scripts are loaded, using: Object.getOwnPropertyNames(this); |
| 4 // * |outputFunc| is called back with each line of output. |
3 | 5 |
4 // Save the list of property names of the global object before loading other scr
ipts. | 6 function globalInterfaceListing(globalObject, propertyNamesInGlobal, outputFunc)
{ |
5 var propertyNamesInGlobal = globalObject.propertyNamesInGlobal || Object.getOwnP
ropertyNames(globalObject); | |
6 | |
7 if (self.importScripts) { | |
8 importScripts('../../resources/js-test.js'); | |
9 | |
10 if (!self.postMessage) { | |
11 // Shared worker. Make postMessage send to the newest client, which in | |
12 // our tests is the only client. | |
13 | |
14 // Store messages for sending until we have somewhere to send them. | |
15 self.postMessage = function(message) { | |
16 if (typeof self.pendingMessages === "undefined") | |
17 self.pendingMessages = []; | |
18 self.pendingMessages.push(message); | |
19 }; | |
20 self.onconnect = function(event) { | |
21 self.postMessage = function(message) { | |
22 event.ports[0].postMessage(message); | |
23 }; | |
24 // Offload any stored messages now that someone has connected to us. | |
25 if (typeof self.pendingMessages === "undefined") | |
26 return; | |
27 while (self.pendingMessages.length) | |
28 event.ports[0].postMessage(self.pendingMessages.shift()); | |
29 }; | |
30 } | |
31 } | |
32 | 7 |
33 // List of builtin JS constructors; Blink is not controlling what properties the
se | 8 // List of builtin JS constructors; Blink is not controlling what properties the
se |
34 // objects have, so exercising them in a Blink test doesn't make sense. | 9 // objects have, so exercising them in a Blink test doesn't make sense. |
35 // | 10 // |
36 // If new builtins are added, please update this list along with the one in | 11 // If new builtins are added, please update this list along with the one in |
37 // LayoutTests/http/tests/serviceworker/webexposed/resources/global-interface-li
sting-worker.js | 12 // LayoutTests/http/tests/serviceworker/webexposed/resources/global-interface-li
sting-worker.js |
38 var jsBuiltins = new Set([ | 13 var jsBuiltins = new Set([ |
39 'Array', | 14 'Array', |
40 'ArrayBuffer', | 15 'ArrayBuffer', |
41 'Boolean', | 16 'Boolean', |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 110 } |
136 | 111 |
137 function collectPropertyKeys(object) { | 112 function collectPropertyKeys(object) { |
138 if (Object.prototype.hasOwnProperty.call(object, 'prototype')) { | 113 if (Object.prototype.hasOwnProperty.call(object, 'prototype')) { |
139 // Skip properties that aren't static (e.g. consts), or are inherited. | 114 // Skip properties that aren't static (e.g. consts), or are inherited. |
140 // TODO(caitp): Don't exclude non-enumerable properties | 115 // TODO(caitp): Don't exclude non-enumerable properties |
141 var protoProperties = new Set(Object.keys(object.prototype).concat( | 116 var protoProperties = new Set(Object.keys(object.prototype).concat( |
142 Object.keys(object.__proto__), | 117 Object.keys(object.__proto__), |
143 ownEnumerableSymbols(object.prototype), | 118 ownEnumerableSymbols(object.prototype), |
144 ownEnumerableSymbols(object.__proto__))); | 119 ownEnumerableSymbols(object.__proto__))); |
145 return propertyKeys = Object.keys(object). | 120 return Object.keys(object). |
146 concat(ownEnumerableSymbols(object)). | 121 concat(ownEnumerableSymbols(object)). |
147 filter(function(name) { | 122 filter(function(name) { |
148 return !protoProperties.has(name); | 123 return !protoProperties.has(name); |
149 }); | 124 }); |
150 } | 125 } |
151 return Object.getOwnPropertyNames(object).concat(Object.getOwnPropertySymbols
(object)); | 126 return Object.getOwnPropertyNames(object).concat(Object.getOwnPropertySymbols
(object)); |
152 } | 127 } |
153 | 128 |
154 // FIXME: List interfaces with NoInterfaceObject specified in their IDL file. | 129 // FIXME: List interfaces with NoInterfaceObject specified in their IDL file. |
155 debug('[INTERFACES]'); | 130 outputFunc('[INTERFACES]'); |
156 var interfaceNames = Object.getOwnPropertyNames(this).filter(isWebIDLConstructor
); | 131 var interfaceNames = Object.getOwnPropertyNames(this).filter(isWebIDLConstructor
); |
157 interfaceNames.sort(); | 132 interfaceNames.sort(); |
158 interfaceNames.forEach(function(interfaceName) { | 133 interfaceNames.forEach(function(interfaceName) { |
159 var inheritsFrom = this[interfaceName].__proto__.name; | 134 var inheritsFrom = this[interfaceName].__proto__.name; |
160 if (inheritsFrom) | 135 if (inheritsFrom) |
161 debug('interface ' + interfaceName + ' : ' + inheritsFrom); | 136 outputFunc('interface ' + interfaceName + ' : ' + inheritsFrom); |
162 else | 137 else |
163 debug('interface ' + interfaceName); | 138 outputFunc('interface ' + interfaceName); |
164 // List static properties then prototype properties. | 139 // List static properties then prototype properties. |
165 [this[interfaceName], this[interfaceName].prototype].forEach(function(object
) { | 140 [this[interfaceName], this[interfaceName].prototype].forEach(function(object
) { |
166 var propertyKeys = collectPropertyKeys(object); | 141 var propertyKeys = collectPropertyKeys(object); |
167 var propertyStrings = []; | 142 var propertyStrings = []; |
168 propertyKeys.forEach(function(propertyKey) { | 143 propertyKeys.forEach(function(propertyKey) { |
169 collectPropertyInfo(object, propertyKey, propertyStrings); | 144 collectPropertyInfo(object, propertyKey, propertyStrings); |
170 }); | 145 }); |
171 propertyStrings.sort().forEach(debug); | 146 propertyStrings.sort().forEach(outputFunc); |
172 }); | 147 }); |
173 }); | 148 }); |
174 | 149 |
175 debug('[GLOBAL OBJECT]'); | 150 outputFunc('[GLOBAL OBJECT]'); |
176 var propertyStrings = []; | 151 var propertyStrings = []; |
177 var memberNames = propertyNamesInGlobal.filter(function(propertyKey) { | 152 var memberNames = propertyNamesInGlobal.filter(function(propertyKey) { |
178 return !jsBuiltins.has(propertyKey) && !isWebIDLConstructor(propertyKey); | 153 return !jsBuiltins.has(propertyKey) && !isWebIDLConstructor(propertyKey); |
179 }); | 154 }); |
180 memberNames.forEach(function(propertyKey) { | 155 memberNames.forEach(function(propertyKey) { |
181 collectPropertyInfo(globalObject, propertyKey, propertyStrings); | 156 collectPropertyInfo(globalObject, propertyKey, propertyStrings); |
182 }); | 157 }); |
183 propertyStrings.sort().forEach(debug); | 158 propertyStrings.sort().forEach(outputFunc); |
184 | 159 |
185 if (isWorker()) | 160 } |
186 finishJSTest(); | |
187 | |
188 })(this); // Run all the code in a local scope. | |
OLD | NEW |