[SERVER-73514] Use globalThis for global variable access in test runner standard libraries Created: 01/Feb/23  Updated: 29/Oct/23  Resolved: 03/Feb/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.3.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Matt Broadstone Assignee: Matt Broadstone
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Server Serverless 2023-02-06
Participants:

 Description   

The core set of libraries included in the test runner (nee "shell") are injected in all new javascript scopes before any test code is run. These libraries define a number of global variables (such as rs, sh, etc) which may be overwritten accidentally by jstests which unintentionally shadow those variables. This has traditionally been avoided by aggressive use of IIFEs in jstests, but part of the process of converting the test corpus to es modules includes unwrapping those IIFE-guarded tests. A solution to this problem is to have the standard libraries always prefix their access of these global variables with globalThis, so that we are guaranteed access of the global variable rather than any lexically scoped, shadowed variant within jstest code.



 Comments   
Comment by Githook User [ 03/Feb/23 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@mongodb.com', 'username': 'mbroadst'}

Message: SERVER-73514 Use globalThis for globals in javascript std libraries
Branch: master
https://github.com/mongodb/mongo/commit/6a23eb81710c4d111f81c0b88fa9a877f8c187ea

Generated at Thu Feb 08 06:24:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.