-
Notifications
You must be signed in to change notification settings - Fork 269
Description
On the Chrome implementation side, we’re looking at other options for reusing the JavaScript context for running worklets. One option we are pursuing and would like some feedback on is freezing the global object (equivalent to calling Object.Freeze recursively on globalThis and its properties) before running any scripts. This, combined with some other changes to script local storage would prevent worklet functions from persisting information between runs, so we can reuse the context for any interest groups that use the same bidding script.
If we freeze the global context, some JavaScript changes will be necessary:
- Global variable definitions through
var
and function definitionsfunction generateBid(...) {..}
will not be allowed. Instead use script-level definitions throughlet
orconst
, defining worklet functions like:const generateBid = function(...) {...};
.
Instead of these:
-
var x = …
-
function generateBid(...) {...}
-
globalThis.generateBid = function(...) {...}
Use these:
-
let x = …
orconst x = …
-
const generateBid = function(...) {...};
- "Overwriting" a property on an object whose prototype is frozen may not work as expected.
Instead of this:
let e = Error(“foo”);
e.name = “bar”; // this line will throw a TypeError
Use this:
let e = Error(“foo”);
Object.defineProperty(e, “name”, {value: “foo”});