| OLD | NEW |
| 1 /* Adopted from LayoutTests/webexposed/resources/global-interface-listing.js */ | 1 // Avoid polluting the global scope. |
| 2 | |
| 3 // Run all the code in a local scope. | |
| 4 (function(global_object) { | 2 (function(global_object) { |
| 5 | 3 |
| 6 var globals = []; | 4 // Save the list of property names of the global object before loading other s
cripts. |
| 5 var global_property_names = Object.getOwnPropertyNames(global_object); |
| 7 | 6 |
| 8 // List of builtin JS constructors; Blink is not controlling what properties the
se | 7 importScripts('/js-test-resources/global-interface-listing.js'); |
| 9 // objects have, so exercising them in a Blink test doesn't make sense. | |
| 10 // | |
| 11 // This list should be kept in sync with the one at LayoutTests/webexposed/resou
rces/global-interface-listing.js | |
| 12 var js_builtins = new Set([ | |
| 13 'Array', | |
| 14 'ArrayBuffer', | |
| 15 'Boolean', | |
| 16 'Date', | |
| 17 'Error', | |
| 18 'EvalError', | |
| 19 'Float32Array', | |
| 20 'Float64Array', | |
| 21 'Function', | |
| 22 'Infinity', | |
| 23 'Int16Array', | |
| 24 'Int32Array', | |
| 25 'Int8Array', | |
| 26 'Intl', | |
| 27 'JSON', | |
| 28 'Map', | |
| 29 'Math', | |
| 30 'NaN', | |
| 31 'Number', | |
| 32 'Object', | |
| 33 'Promise', | |
| 34 'Proxy', | |
| 35 'RangeError', | |
| 36 'ReferenceError', | |
| 37 'Reflect', | |
| 38 'RegExp', | |
| 39 'Set', | |
| 40 'String', | |
| 41 'Symbol', | |
| 42 'SyntaxError', | |
| 43 'TypeError', | |
| 44 'URIError', | |
| 45 'Uint16Array', | |
| 46 'Uint32Array', | |
| 47 'Uint8Array', | |
| 48 'Uint8ClampedArray', | |
| 49 'WeakMap', | |
| 50 'WeakSet', | |
| 51 'WebAssembly', | |
| 52 'decodeURI', | |
| 53 'decodeURIComponent', | |
| 54 'encodeURI', | |
| 55 'encodeURIComponent', | |
| 56 'escape', | |
| 57 'eval', | |
| 58 'isFinite', | |
| 59 'isNaN', | |
| 60 'parseFloat', | |
| 61 'parseInt', | |
| 62 'undefined', | |
| 63 'unescape', | |
| 64 ]); | |
| 65 | 8 |
| 66 function is_web_idl_constructor(property_name) { | 9 var globals = []; |
| 67 if (js_builtins.has(property_name)) | |
| 68 return false; | |
| 69 var descriptor = Object.getOwnPropertyDescriptor(this, property_name); | |
| 70 if (descriptor.value === undefined || | |
| 71 descriptor.value.prototype === undefined) { | |
| 72 return false; | |
| 73 } | |
| 74 return descriptor.writable && !descriptor.enumerable && | |
| 75 descriptor.configurable; | |
| 76 } | |
| 77 | 10 |
| 78 function collect_property_info(object, property_name, output) { | 11 globalInterfaceListing(global_object, |
| 79 var keywords = ('prototype' in object) ? 'static ' : ''; | 12 global_property_names, |
| 80 var descriptor = Object.getOwnPropertyDescriptor(object, property_name); | 13 string => globals.push(string)); |
| 81 if ('value' in descriptor) { | |
| 82 var type; | |
| 83 if (typeof descriptor.value === 'function') { | |
| 84 type = 'method'; | |
| 85 } else { | |
| 86 type = 'attribute'; | |
| 87 } | |
| 88 output.push(' ' + keywords + type + ' ' + property_name); | |
| 89 } else { | |
| 90 if (descriptor.get) | |
| 91 output.push(' ' + keywords + 'getter ' + property_name); | |
| 92 if (descriptor.set) | |
| 93 output.push(' ' + keywords + 'setter ' + property_name); | |
| 94 } | |
| 95 } | |
| 96 | 14 |
| 97 var interface_names = Object.getOwnPropertyNames(global_object).filter(is_web_id
l_constructor); | 15 self.addEventListener('message', function(event) { |
| 98 interface_names.sort(); | 16 event.ports[0].postMessage({ result: globals }); |
| 99 interface_names.forEach(function(interface_name) { | |
| 100 var inherits_from = this[interface_name].__proto__.name; | |
| 101 if (inherits_from) | |
| 102 globals.push('interface ' + interface_name + ' : ' + inherits_from); | |
| 103 else | |
| 104 globals.push('interface ' + interface_name); | |
| 105 // List static properties then prototype properties. | |
| 106 [this[interface_name], this[interface_name].prototype].forEach(function(object
) { | |
| 107 if ('prototype' in object) { | |
| 108 // Skip properties that aren't static (e.g. consts), or are inherited. | |
| 109 var proto_properties = new Set(Object.keys(object.prototype).concat( | |
| 110 Object.keys(object.__proto__))); | |
| 111 var property_names = Object.keys(object).filter(function(name) { | |
| 112 return !proto_properties.has(name); | |
| 113 }); | |
| 114 } else { | |
| 115 var property_names = Object.getOwnPropertyNames(object); | |
| 116 } | |
| 117 var property_strings = []; | |
| 118 property_names.forEach(function(property_name) { | |
| 119 collect_property_info(object, property_name, property_strings); | |
| 120 }); | |
| 121 globals.push.apply(globals, property_strings.sort()); | |
| 122 }); | 17 }); |
| 123 }); | |
| 124 | 18 |
| 125 globals.push('global object'); | 19 })(this); |
| 126 var property_strings = []; | |
| 127 var member_names = Object.getOwnPropertyNames(global_object).filter(function(pro
perty_name) { | |
| 128 return !js_builtins.has(property_name) && !is_web_idl_constructor(property_nam
e); | |
| 129 }); | |
| 130 member_names.forEach(function(property_name) { | |
| 131 collect_property_info(global_object, property_name, property_strings); | |
| 132 }); | |
| 133 globals.push.apply(globals, property_strings.sort()); | |
| 134 | |
| 135 self.addEventListener('message', function(event) { | |
| 136 event.ports[0].postMessage({ result: globals }); | |
| 137 }); | |
| 138 | |
| 139 })(this); // Run all the code in a local scope. | |
| OLD | NEW |