summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/parser/compile-script.js
blob: 293d25632e60787ef81cda92a3b340946301fe6d (plain)
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
// |jit-test| skip-if: !('oomTest' in this)

load(libdir + "asserts.js");

let stencil = compileToStencil('314;');
assertEq(evalStencil(stencil), 314);

stencil = compileToStencil('let o = { a: 42, b: 2718 }["b"]; o', { prepareForInstantiate: true });
assertEq(evalStencil(stencil), 2718);

assertThrowsInstanceOf(() => compileToStencil('let fail ='), SyntaxError);
assertThrowsInstanceOf(() => compileToStencil('42;', 42), Error);

oomTest(function() {
    compileToStencil('"hello stencil!";', { prepareForInstantiate: false });
});

oomTest(function() {
    compileToStencil('"hello stencil!";', { prepareForInstantiate: true });
});

// Modules
function compileAndEvaluateModule(script, options) {
    if (!options) {
        options = {};
    }
    options.module = true;
    let stencil = compileToStencil(script, options);
    let m = instantiateModuleStencil(stencil);
    moduleLink(m);
    moduleEvaluate(m);
    return m;
}

var m = compileAndEvaluateModule('export let r = 314;');
assertEq(getModuleEnvironmentValue(m, "r"), 314);

m = compileAndEvaluateModule('export let r = { a: 42, b: 2718 }["b"];', { prepareForInstantiate: true });
assertEq(getModuleEnvironmentValue(m, "r"), 2718);

assertThrowsInstanceOf(() => compileAndEvaluateModule('let fail ='), SyntaxError);
assertThrowsInstanceOf(() => compileToStencil('42;', 42), Error);

oomTest(function() {
    compileAndEvaluateModule('export let r = "hello stencil!";', { prepareForInstantiate: false });
});

oomTest(function() {
    compileAndEvaluateModule('export let r = "hello stencil!";', { prepareForInstantiate: true });
});