-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathmodule-bugfixes.js
199 lines (183 loc) · 7.26 KB
/
module-bugfixes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// ES6 Module tests for bugfixes
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
function testModuleScript(source, message, shouldFail = false) {
let testfunc = () => testRunner.LoadModule(source, 'samethread', shouldFail);
if (shouldFail) {
let caught = false;
// We can't use assert.throws here because the SyntaxError used to construct the thrown error
// is from a different context so it won't be strictly equal to our SyntaxError.
try {
testfunc();
} catch(e) {
caught = true;
// Compare toString output of SyntaxError and other context SyntaxError constructor.
assert.areEqual(e.constructor.toString(), SyntaxError.toString(), message);
}
assert.isTrue(caught, `Expected error not thrown: ${message}`);
} else {
assert.doesNotThrow(testfunc, message);
}
}
var tests = [
{
name: "OS12113549: Assertion on module export in ProcessCapturedSym",
body: function() {
let functionBody =
`
import { module1_exportbinding_0 as module2_localbinding_0 } from 'bug_OS12113549_module1.js';
assert.areEqual({"BugID": "OS12113549"}, module2_localbinding_0);
`
testRunner.LoadModule(functionBody, 'samethread');
}
},
{
name: "Memory leak test on syntax error",
body: function() {
try {
WScript.LoadModule('');
WScript.LoadModule('1');
WScript.LoadModule('const a = () -> {};');
} catch(e) {
// no-op
}
}
},
{
name: "Issue 4482: Indirect circular module dependencies",
body: function() {
let functionBody = "import 'module_4482_dep1.js';"
testRunner.LoadModule(functionBody);
}
},
{
name: "Issue 4570: Module that appears multiple times in dependency tree",
body: function() {
let functionBody = "import 'module_4570_dep1.js';"
testRunner.LoadModule(functionBody);
}
},
{
name: "Issue 5171: Incorrect module load order",
body: function() {
WScript.RegisterModuleSource("obj.js", `export const obj = {a:false, b: false, c: false};`);
WScript.RegisterModuleSource("a.js",`
import {obj} from "obj.js";
assert.isTrue(obj.b);
assert.isFalse(obj.c);
assert.isFalse(obj.a);
obj.a = true;`);
WScript.RegisterModuleSource("b.js",`
import {obj} from "obj.js";
assert.isFalse(obj.b);
assert.isFalse(obj.c);
assert.isFalse(obj.a);
obj.b = true;`);
WScript.RegisterModuleSource("c.js",`
import {obj} from "obj.js";
assert.isTrue(obj.b);
assert.isFalse(obj.c);
assert.isTrue(obj.a);
obj.c = true;`);
const start = 'import "b.js"; import "a.js"; import "c.js";';
testRunner.LoadModule(start);
}
},
{
name: "Issue 6261: Specifier dependent module load order",
body: function() {
WScript.RegisterModuleSource("dep", `export const obj = {a:false, b: false, c: false};`);
WScript.RegisterModuleSource("one",`
import {obj} from "dep";
assert.isFalse(obj.b);
assert.isFalse(obj.c);
assert.isFalse(obj.a);
obj.a = true;`);
WScript.RegisterModuleSource("two",`
import {obj} from "dep";
assert.isFalse(obj.b);
assert.isFalse(obj.c);
assert.isTrue(obj.a);
obj.b = true;`);
WScript.RegisterModuleSource("three",`
import {obj} from "dep";
assert.isTrue(obj.b);
assert.isFalse(obj.c);
assert.isTrue(obj.a);
obj.c = true;`);
const start = 'import "one"; import "two"; import "three";';
testRunner.LoadModule(start);
}
},
{
// https://github.com/Microsoft/ChakraCore/issues/5501
name : "Issue 5501: Indirect exports excluded from namespace object - POC 1",
body()
{
WScript.RegisterModuleSource("test5501Part1", `
export {bar as foo} from "test5501Part1";
export const bar = 5;
import * as stuff from "test5501Part1";
assert.areEqual(stuff.bar, stuff.foo);
`);
testRunner.LoadModule("import 'test5501Part1'");
}
},
{
name : "Issue 5501: Indirect exports excluded from namespace object - POC 2",
body()
{
WScript.RegisterModuleSource("test5501Part2a", "export default function () { return true; }");
WScript.RegisterModuleSource("test5501Part2b", "export {default as aliasName} from 'test5501Part2a'");
testRunner.LoadModule(`
import {aliasName} from 'test5501Part2b';
assert.isTrue(aliasName());
`);
}
},
{
name : "Issue 6133: Child module imports non-existant export from another module",
body()
{
WScript.RegisterModuleSource("test6133a", 'import Default from "test6133b";');
WScript.RegisterModuleSource("test6133b", 'export function notDefault () {}');
testRunner.LoadModule('import "test6133a";', undefined, true);
}
},
{
name : "Issue 5236: Module function exports not hoisted test",
body()
{
WScript.RegisterModuleSource("test5236a", `
import {default as Default, bar, foo} from "test5236b";
export default function () {}
export function one() {}
export var two = function () {}
bar();
assert.isNotUndefined(Default);
foo();
`);
WScript.RegisterModuleSource("test5236b", `
import Default from "test5236c";
export function bar() {}
export default class {}
export var foo = function () {}
Default();
`);
WScript.RegisterModuleSource("test5236c", `
import {default as Default, one, two} from "test5236a";
import otherDefault from "test5236b";
export default function bar() {}
Default();
one();
assert.isUndefined(two);
assert.isUndefined(otherDefault);
`);
testRunner.LoadModule('import "test5236a";', undefined, false);
}
}
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });