Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: third_party/WebKit/LayoutTests/webexposed/resources/global-interface-listing.js

Issue 1788503005: [LayoutTests] add Symbols to webexposed global-interface-listing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Run all the code in a local scope. 1 // Run all the code in a local scope.
2 (function(globalObject) { 2 (function(globalObject) {
3 3
4 // Save the list of property names of the global object before loading other scr ipts. 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); 5 var propertyNamesInGlobal = globalObject.propertyNamesInGlobal || Object.getOwnP ropertyNames(globalObject);
6 6
7 if (self.importScripts) { 7 if (self.importScripts) {
8 importScripts('../../resources/js-test.js'); 8 importScripts('../../resources/js-test.js');
9 9
10 if (!self.postMessage) { 10 if (!self.postMessage) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 function isWebIDLConstructor(propertyName) { 91 function isWebIDLConstructor(propertyName) {
92 if (jsBuiltins.has(propertyName)) 92 if (jsBuiltins.has(propertyName))
93 return false; 93 return false;
94 var descriptor = Object.getOwnPropertyDescriptor(this, propertyName); 94 var descriptor = Object.getOwnPropertyDescriptor(this, propertyName);
95 if (descriptor.value == undefined || descriptor.value.prototype == undefined ) 95 if (descriptor.value == undefined || descriptor.value.prototype == undefined )
96 return false; 96 return false;
97 return descriptor.writable && !descriptor.enumerable && descriptor.configura ble; 97 return descriptor.writable && !descriptor.enumerable && descriptor.configura ble;
98 } 98 }
99 99
100 var wellKnownSymbols = new Map([
101 [Symbol.hasInstance, "@@hasInstance"],
102 [Symbol.isConcatSpreadable, "@@isConcatSpreadable"],
103 [Symbol.iterator, "@@iterator"],
104 [Symbol.match, "@@match"],
105 [Symbol.replace, "@@replace"],
106 [Symbol.search, "@@search"],
107 [Symbol.species, "@@species"],
108 [Symbol.split, "@@split"],
109 [Symbol.toPrimitive, "@@toPrimitive"],
110 [Symbol.toStringTag, "@@toStringTag"],
111 [Symbol.unscopables, "@@unscopables"]
112 ]);
113
100 function collectPropertyInfo(object, propertyName, output) { 114 function collectPropertyInfo(object, propertyName, output) {
jsbell 2016/03/11 20:23:46 Can we s/propertyName/propertyKey/ while we're her
caitp (gmail) 2016/03/11 20:29:01 Acknowledged.
101 var keywords = ('prototype' in object) ? 'static ' : ''; 115 var propertyString = wellKnownSymbols.get(propertyName) || propertyName.toSt ring();
jsbell 2016/03/11 20:23:46 Is this map necessary? Seems annoying to maintain.
caitp (gmail) 2016/03/11 20:29:01 hmm, it doesn't seem that hard --- I just wanted t
116 var keywords = Object.prototype.hasOwnProperty.call(object, 'prototype') ? ' static ' : '';
102 var descriptor = Object.getOwnPropertyDescriptor(object, propertyName); 117 var descriptor = Object.getOwnPropertyDescriptor(object, propertyName);
103 if ('value' in descriptor) { 118 if ('value' in descriptor) {
104 var type = typeof descriptor.value === 'function' ? 'method' : 'attribut e'; 119 var type = typeof descriptor.value === 'function' ? 'method' : 'attribut e';
105 output.push(' ' + keywords + type + ' ' + propertyName); 120 output.push(' ' + keywords + type + ' ' + propertyString);
106 } else { 121 } else {
107 if (descriptor.get) 122 if (descriptor.get)
108 output.push(' ' + keywords + 'getter ' + propertyName); 123 output.push(' ' + keywords + 'getter ' + propertyString);
109 if (descriptor.set) 124 if (descriptor.set)
110 output.push(' ' + keywords + 'setter ' + propertyName); 125 output.push(' ' + keywords + 'setter ' + propertyString);
111 } 126 }
112 } 127 }
113 128
129 function ownEnumerableSymbols(object) {
130 return Object.getOwnPropertySymbols(object).
131 filter(function(name) {
132 return Object.getOwnPropertyDescriptor(name).enumerable;
133 });
134 }
135
136 function collectPropertyNames(object) {
137 if (Object.prototype.hasOwnProperty.call(object, 'prototype')) {
138 // Skip properties that aren't static (e.g. consts), or are inherited.
139 var protoProperties = new Set(Object.keys(object.prototype).concat(
caitp (gmail) 2016/03/11 20:10:49 I'm not sure if it's intentional to use Object.key
jsbell 2016/03/11 20:23:46 I'm okay with leaving this as-is for now, maybe wi
140 Object.keys(object.__proto__),
141 ownEnumerableSymbols(object.prototype),
142 ownEnumerableSymbols(object.__proto__)));
143 return propertyNames = Object.keys(object).
144 concat(ownEnumerableSymbols(object)).
145 filter(function(name) {
146 // TODO(johnme): Stop filtering out 'toString' once
147 // https://crbug.com/547773 is fixed.
148 return !protoProperties.has(name) && name !== 'toString';
149 });
150 }
151 return Object.getOwnPropertyNames(object).concat(Object.getOwnPropertySymbols (object));
152 }
153
114 // FIXME: List interfaces with NoInterfaceObject specified in their IDL file. 154 // FIXME: List interfaces with NoInterfaceObject specified in their IDL file.
115 debug('[INTERFACES]'); 155 debug('[INTERFACES]');
116 var interfaceNames = Object.getOwnPropertyNames(this).filter(isWebIDLConstructor ); 156 var interfaceNames = Object.getOwnPropertyNames(this).filter(isWebIDLConstructor );
117 interfaceNames.sort(); 157 interfaceNames.sort();
118 interfaceNames.forEach(function(interfaceName) { 158 interfaceNames.forEach(function(interfaceName) {
119 var inheritsFrom = this[interfaceName].__proto__.name; 159 var inheritsFrom = this[interfaceName].__proto__.name;
120 if (inheritsFrom) 160 if (inheritsFrom)
121 debug('interface ' + interfaceName + ' : ' + inheritsFrom); 161 debug('interface ' + interfaceName + ' : ' + inheritsFrom);
122 else 162 else
123 debug('interface ' + interfaceName); 163 debug('interface ' + interfaceName);
124 // List static properties then prototype properties. 164 // List static properties then prototype properties.
125 [this[interfaceName], this[interfaceName].prototype].forEach(function(object ) { 165 [this[interfaceName], this[interfaceName].prototype].forEach(function(object ) {
126 if ('prototype' in object) { 166 var propertyNames = collectPropertyNames(object);
127 // Skip properties that aren't static (e.g. consts), or are inherite d.
128 var protoProperties = new Set(Object.keys(object.prototype).concat(
129 Object.keys(object.__proto__)));
130 var propertyNames = Object.keys(object).filter(function(name) {
131 // TODO(johnme): Stop filtering out 'toString' once
132 // https://crbug.com/547773 is fixed.
133 return !protoProperties.has(name) && name !== 'toString';
134 });
135 } else {
136 var propertyNames = Object.getOwnPropertyNames(object);
137 }
138 var propertyStrings = []; 167 var propertyStrings = [];
139 propertyNames.forEach(function(propertyName) { 168 propertyNames.forEach(function(propertyName) {
140 collectPropertyInfo(object, propertyName, propertyStrings); 169 collectPropertyInfo(object, propertyName, propertyStrings);
141 }); 170 });
142 propertyStrings.sort().forEach(debug); 171 propertyStrings.sort().forEach(debug);
143 }); 172 });
144 }); 173 });
145 174
146 debug('[GLOBAL OBJECT]'); 175 debug('[GLOBAL OBJECT]');
147 var propertyStrings = []; 176 var propertyStrings = [];
148 var memberNames = propertyNamesInGlobal.filter(function(propertyName) { 177 var memberNames = propertyNamesInGlobal.filter(function(propertyName) {
149 return !jsBuiltins.has(propertyName) && !isWebIDLConstructor(propertyName); 178 return !jsBuiltins.has(propertyName) && !isWebIDLConstructor(propertyName);
150 }); 179 });
151 memberNames.forEach(function(propertyName) { 180 memberNames.forEach(function(propertyName) {
152 collectPropertyInfo(globalObject, propertyName, propertyStrings); 181 collectPropertyInfo(globalObject, propertyName, propertyStrings);
153 }); 182 });
154 propertyStrings.sort().forEach(debug); 183 propertyStrings.sort().forEach(debug);
155 184
156 if (isWorker()) 185 if (isWorker())
157 finishJSTest(); 186 finishJSTest();
158 187
159 })(this); // Run all the code in a local scope. 188 })(this); // Run all the code in a local scope.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698