[Wasm] Fix parsing D8 CLI arguments in kotlin.test

`@JsFun("code")` is now executed inside a JS function which brings its
`arguments` into the scope shadowing D8's CLI `arguments`.
 Accessing arguments through `globalThis` fixes the problem.

Merge-request: KT-MR-8630
Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
This commit is contained in:
Svyatoslav Kuzmich
2023-02-02 16:37:32 +00:00
committed by Space Team
parent bc612fa1c6
commit 81072ac9b4
3 changed files with 14 additions and 2 deletions
@@ -9,7 +9,8 @@ import kotlin.test.FrameworkAdapter
import kotlin.math.abs
import kotlin.js.*
@JsFun("() => (typeof arguments !== 'undefined' && typeof arguments.join !== 'undefined') ? arguments.join(' ') : '' ")
// Using 'globalThis.arguments' because 'arguments' can refer to current JS function arguments
@JsFun("() => globalThis.arguments?.join?.(' ') ?? ''")
private external fun d8Arguments(): String
@JsFun("() => (typeof process != 'undefined' && typeof process.argv != 'undefined') ? process.argv.slice(2).join(' ') : ''")
private external fun nodeArguments(): String