From b02460fa633390e8224aa16c8bb52f582df90b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 21 Jan 2024 18:50:54 +0100 Subject: [PATCH] tests: Fix check for global scope pollution Since commit c570011 dropped the `with` statement, this bit of the test has only checked for writes to a specific variable in the file. There is no direct replacement for `with` here, the best we can do (I think) is comparing property names on the global objects before and after the `eval()` call. Part-of: --- tests/unit/jsParse.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/unit/jsParse.js b/tests/unit/jsParse.js index 9dac85c19..37e2e0cb9 100644 --- a/tests/unit/jsParse.js +++ b/tests/unit/jsParse.js @@ -210,8 +210,8 @@ for (let i = 0; i < testsIsUnsafeExpression.length; i++) { for (let i = 0; i < testsModifyScope.length; i++) { let text = testsModifyScope[i]; - // We need to use var here for the with statement - var obj = {}; + + const globalPropsPre = Object.getOwnPropertyNames(globalThis).sort(); // Just as in JsParse.getCompletions, we will find the offset // of the expression, test whether it is unsafe, and then eval it. @@ -232,6 +232,8 @@ for (let i = 0; i < testsModifyScope.length; i++) { } } } - let propertyNames = Object.getOwnPropertyNames(obj); - JsUnit.assertEquals(`The context '${JSON.stringify(obj)}' was not modified`, propertyNames.length, 0); + + const globalPropsPost = Object.getOwnPropertyNames(globalThis).sort(); + Assertions.assertArrayEquals('The global object was not modified', + globalPropsPre, globalPropsPost); }