OLD | NEW |
| (Empty) |
1 // Run all the code in a local scope. | |
2 (function(globalObject) { | |
3 | |
4 // Save the list of property names of the global object before loading other scr
ipts. | |
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 | |
33 // 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. | |
35 // | |
36 // 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 | |
38 var jsBuiltins = new Set([ | |
39 'Array', | |
40 'ArrayBuffer', | |
41 'Boolean', | |
42 'Date', | |
43 'Error', | |
44 'EvalError', | |
45 'Float32Array', | |
46 'Float64Array', | |
47 'Function', | |
48 'Infinity', | |
49 'Int16Array', | |
50 'Int32Array', | |
51 'Int8Array', | |
52 'Intl', | |
53 'JSON', | |
54 'Map', | |
55 'Math', | |
56 'NaN', | |
57 'Number', | |
58 'Object', | |
59 'Promise', | |
60 'Proxy', | |
61 'RangeError', | |
62 'ReferenceError', | |
63 'Reflect', | |
64 'RegExp', | |
65 'Set', | |
66 'String', | |
67 'Symbol', | |
68 'SyntaxError', | |
69 'TypeError', | |
70 'URIError', | |
71 'Uint16Array', | |
72 'Uint32Array', | |
73 'Uint8Array', | |
74 'Uint8ClampedArray', | |
75 'WeakMap', | |
76 'WeakSet', | |
77 'WebAssembly', | |
78 'decodeURI', | |
79 'decodeURIComponent', | |
80 'encodeURI', | |
81 'encodeURIComponent', | |
82 'escape', | |
83 'eval', | |
84 'isFinite', | |
85 'isNaN', | |
86 'parseFloat', | |
87 'parseInt', | |
88 'undefined', | |
89 'unescape', | |
90 ]); | |
91 | |
92 function isWebIDLConstructor(propertyKey) { | |
93 if (jsBuiltins.has(propertyKey)) | |
94 return false; | |
95 var descriptor = Object.getOwnPropertyDescriptor(this, propertyKey); | |
96 if (descriptor.value == undefined || descriptor.value.prototype == undefined
) | |
97 return false; | |
98 return descriptor.writable && !descriptor.enumerable && descriptor.configura
ble; | |
99 } | |
100 | |
101 var wellKnownSymbols = new Map([ | |
102 [Symbol.hasInstance, "@@hasInstance"], | |
103 [Symbol.isConcatSpreadable, "@@isConcatSpreadable"], | |
104 [Symbol.iterator, "@@iterator"], | |
105 [Symbol.match, "@@match"], | |
106 [Symbol.replace, "@@replace"], | |
107 [Symbol.search, "@@search"], | |
108 [Symbol.species, "@@species"], | |
109 [Symbol.split, "@@split"], | |
110 [Symbol.toPrimitive, "@@toPrimitive"], | |
111 [Symbol.toStringTag, "@@toStringTag"], | |
112 [Symbol.unscopables, "@@unscopables"] | |
113 ]); | |
114 | |
115 function collectPropertyInfo(object, propertyKey, output) { | |
116 var propertyString = wellKnownSymbols.get(propertyKey) || propertyKey.toStri
ng(); | |
117 var keywords = Object.prototype.hasOwnProperty.call(object, 'prototype') ? '
static ' : ''; | |
118 var descriptor = Object.getOwnPropertyDescriptor(object, propertyKey); | |
119 if ('value' in descriptor) { | |
120 var type = typeof descriptor.value === 'function' ? 'method' : 'attribut
e'; | |
121 output.push(' ' + keywords + type + ' ' + propertyString); | |
122 } else { | |
123 if (descriptor.get) | |
124 output.push(' ' + keywords + 'getter ' + propertyString); | |
125 if (descriptor.set) | |
126 output.push(' ' + keywords + 'setter ' + propertyString); | |
127 } | |
128 } | |
129 | |
130 function ownEnumerableSymbols(object) { | |
131 return Object.getOwnPropertySymbols(object). | |
132 filter(function(name) { | |
133 return Object.getOwnPropertyDescriptor(object, name).enumerable; | |
134 }); | |
135 } | |
136 | |
137 function collectPropertyKeys(object) { | |
138 if (Object.prototype.hasOwnProperty.call(object, 'prototype')) { | |
139 // Skip properties that aren't static (e.g. consts), or are inherited. | |
140 // TODO(caitp): Don't exclude non-enumerable properties | |
141 var protoProperties = new Set(Object.keys(object.prototype).concat( | |
142 Object.keys(object.__proto__), | |
143 ownEnumerableSymbols(object.prototype), | |
144 ownEnumerableSymbols(object.__proto__))); | |
145 return propertyKeys = Object.keys(object). | |
146 concat(ownEnumerableSymbols(object)). | |
147 filter(function(name) { | |
148 return !protoProperties.has(name); | |
149 }); | |
150 } | |
151 return Object.getOwnPropertyNames(object).concat(Object.getOwnPropertySymbols
(object)); | |
152 } | |
153 | |
154 // FIXME: List interfaces with NoInterfaceObject specified in their IDL file. | |
155 debug('[INTERFACES]'); | |
156 var interfaceNames = Object.getOwnPropertyNames(this).filter(isWebIDLConstructor
); | |
157 interfaceNames.sort(); | |
158 interfaceNames.forEach(function(interfaceName) { | |
159 var inheritsFrom = this[interfaceName].__proto__.name; | |
160 if (inheritsFrom) | |
161 debug('interface ' + interfaceName + ' : ' + inheritsFrom); | |
162 else | |
163 debug('interface ' + interfaceName); | |
164 // List static properties then prototype properties. | |
165 [this[interfaceName], this[interfaceName].prototype].forEach(function(object
) { | |
166 var propertyKeys = collectPropertyKeys(object); | |
167 var propertyStrings = []; | |
168 propertyKeys.forEach(function(propertyKey) { | |
169 collectPropertyInfo(object, propertyKey, propertyStrings); | |
170 }); | |
171 propertyStrings.sort().forEach(debug); | |
172 }); | |
173 }); | |
174 | |
175 debug('[GLOBAL OBJECT]'); | |
176 var propertyStrings = []; | |
177 var memberNames = propertyNamesInGlobal.filter(function(propertyKey) { | |
178 return !jsBuiltins.has(propertyKey) && !isWebIDLConstructor(propertyKey); | |
179 }); | |
180 memberNames.forEach(function(propertyKey) { | |
181 collectPropertyInfo(globalObject, propertyKey, propertyStrings); | |
182 }); | |
183 propertyStrings.sort().forEach(debug); | |
184 | |
185 if (isWorker()) | |
186 finishJSTest(); | |
187 | |
188 })(this); // Run all the code in a local scope. | |
OLD | NEW |