"block-scoping/let" kata is broken, due to using var which creates a global variable #2

Closed
opened 2023-10-05 14:53:17 +00:00 by wolframkriesing · 2 comments

The following kata does not work currently: https://jskatas.org/katas/es6/language/block-scoping/let/

Why?
Currently the test is executed in the global space, simply said, just using new Function(sourceCode)(). This resulted in the following when running this test:

if (true) {
  var letX = true;
}
assert.throws(() => letX, ReferenceError);

The code var letX = true; defines the variable letX in the global space, this results in the assertion NOT to fail.

The following kata does not work currently: https://jskatas.org/katas/es6/language/block-scoping/let/ Why? Currently the test is executed in the global space, simply said, just using `new Function(sourceCode)()`. This resulted in the following when running this test: ```js if (true) { var letX = true; } assert.throws(() => letX, ReferenceError); ``` The code `var letX = true;` defines the variable `letX` in the global space, this results in the assertion NOT to fail.
wolframkriesing added the
bug
label 2023-10-05 14:54:41 +00:00
wolframkriesing changed title from The `let` kata does not work anymore, due to using `var` which creates a global variable to "block-scoping/let" kata is broken, due to using `var` which creates a global variable 2023-10-05 14:56:06 +00:00

Possible solutions:

  • execute the test in a web worker
    • will prevent access to document
    • every test run can use a separate web worker, that separates the contexts and the memory footprint should be ok
  • execute the test in an iframe
    • document could be passed in as parameter, I think
    • when reusing the iframe variables would stay defined
Possible solutions: - execute the test in a web worker - will prevent access to `document` - every test run can use a separate web worker, that separates the contexts and the memory footprint should be ok - execute the test in an iframe - `document` could be passed in as parameter, I think - when reusing the iframe variables would stay defined

fixed in 20feffbd3d

fixed in https://codeberg.org/wolframkriesing/jskatas-org/commit/20feffbd3d954b429cae71871e05c433237aa746
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: wolframkriesing/jskatas-org#2
There is no content yet.