Index: third_party/WebKit/LayoutTests/http/tests/worklet/webexposed/resources/global-interface-listing-worklet.js |
diff --git a/third_party/WebKit/LayoutTests/http/tests/worklet/webexposed/resources/global-interface-listing-worklet.js b/third_party/WebKit/LayoutTests/http/tests/worklet/webexposed/resources/global-interface-listing-worklet.js |
index 0f2ae2ba50a576ce660ab200ba2e0355d8b36370..b602b57bd17b2f2251c81f4c8962dc08a92ca43b 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/worklet/webexposed/resources/global-interface-listing-worklet.js |
+++ b/third_party/WebKit/LayoutTests/http/tests/worklet/webexposed/resources/global-interface-listing-worklet.js |
@@ -1,7 +1,16 @@ |
/* Adopted from LayoutTests/webexposed/resources/global-interface-listing.js */ |
// Run all the code in a local scope. |
-(function(global_object) { |
+(function() { |
+ |
+// Generally, Worklet should not have a reference to the global object. |
+// https://drafts.css-houdini.org/worklets/#code-idempotency |
+if (this) { |
+ console.error('"this" should not refer to the global object'); |
+ return; |
+} |
+// Instead, retrieve the global object in a tricky way. |
+var global_object = Function('return this')(); |
var globals = []; |
@@ -66,7 +75,7 @@ var js_builtins = new Set([ |
function is_web_idl_constructor(property_name) { |
if (js_builtins.has(property_name)) |
return false; |
- var descriptor = Object.getOwnPropertyDescriptor(this, property_name); |
+ var descriptor = Object.getOwnPropertyDescriptor(global_object, property_name); |
if (descriptor.value === undefined || |
descriptor.value.prototype === undefined) { |
return false; |
@@ -97,13 +106,13 @@ function collect_property_info(object, property_name, output) { |
var interface_names = Object.getOwnPropertyNames(global_object).filter(is_web_idl_constructor); |
interface_names.sort(); |
interface_names.forEach(function(interface_name) { |
- var inherits_from = this[interface_name].__proto__.name; |
+ var inherits_from = global_object[interface_name].__proto__.name; |
if (inherits_from) |
globals.push('interface ' + interface_name + ' : ' + inherits_from); |
else |
globals.push('interface ' + interface_name); |
// List static properties then prototype properties. |
- [this[interface_name], this[interface_name].prototype].forEach(function(object) { |
+ [global_object[interface_name], global_object[interface_name].prototype].forEach(function(object) { |
if ('prototype' in object) { |
// Skip properties that aren't static (e.g. consts), or are inherited. |
var proto_properties = new Set(Object.keys(object.prototype).concat( |
@@ -138,4 +147,4 @@ globals.forEach(function(global) { |
console.log(global); |
}); |
-})(this); // Run all the code in a local scope. |
+})(); // Run all the code in a local scope. |