2019-03-11 03:26:37 -07:00
|
|
|
// Test interaction with global object and global lexical scope.
|
|
|
|
|
2020-07-15 17:48:35 -07:00
|
|
|
function evalModuleAndCheck(source, expected) {
|
2019-03-11 03:26:37 -07:00
|
|
|
let m = parseModule(source);
|
|
|
|
m.declarationInstantiation();
|
2020-07-15 17:48:35 -07:00
|
|
|
m.evaluation();
|
|
|
|
assertEq(getModuleEnvironmentValue(m, "r"), expected);
|
2019-03-11 03:26:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var x = 1;
|
2020-07-15 17:48:35 -07:00
|
|
|
evalModuleAndCheck("export let r = x; x = 2;", 1);
|
2019-03-11 03:26:37 -07:00
|
|
|
assertEq(x, 2);
|
|
|
|
|
|
|
|
let y = 3;
|
2020-07-15 17:48:35 -07:00
|
|
|
evalModuleAndCheck("export let r = y; y = 4;", 3);
|
2019-03-11 03:26:37 -07:00
|
|
|
assertEq(y, 4);
|
|
|
|
|
|
|
|
if (helperThreadCount() == 0)
|
|
|
|
quit();
|
|
|
|
|
2020-07-15 17:48:35 -07:00
|
|
|
function offThreadEvalModuleAndCheck(source, expected) {
|
2019-03-11 03:26:37 -07:00
|
|
|
offThreadCompileModule(source);
|
|
|
|
let m = finishOffThreadModule();
|
|
|
|
print("compiled");
|
|
|
|
m.declarationInstantiation();
|
2020-07-15 17:48:35 -07:00
|
|
|
m.evaluation();
|
|
|
|
assertEq(getModuleEnvironmentValue(m, "r"), expected);
|
2019-03-11 03:26:37 -07:00
|
|
|
}
|
|
|
|
|
2020-07-15 17:48:35 -07:00
|
|
|
offThreadEvalModuleAndCheck("export let r = x; x = 5;", 2);
|
2019-03-11 03:26:37 -07:00
|
|
|
assertEq(x, 5);
|
|
|
|
|
2020-07-15 17:48:35 -07:00
|
|
|
offThreadEvalModuleAndCheck("export let r = y; y = 6;", 4);
|
2019-03-11 03:26:37 -07:00
|
|
|
assertEq(y, 6);
|