forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimary-tests.js
90 lines (87 loc) · 1.97 KB
/
primary-tests.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
global.globalObject1 = {
prop_1: {
nested_prop: 1,
},
prop_2: 2,
prop_3: true,
prop_4: [3, 4, "str_elm_1", null, undefined, 5],
prop_5: {
func1: function () {
return;
},
func2: function () {
return 1;
},
func3: function (n) {
return n * 2;
},
func4: function (a, b, c) {
return a + b + c;
},
func5: function (x) {
return "Hello, " + x;
},
func6: function (c, a, b) {
if (c) {
return a;
} else {
return b;
}
},
},
prop_6: {
call_host_1: () => {
return global.globalObject1.prop_6.host_func_1();
},
},
prop_7: 3.14,
prop_8: [0, , 2, 3, , , 6],
prop_9: {
func1: function () {
throw new Error();
},
func2: function () {
throw "String Error";
},
func3: function () {
throw 3.0
},
},
eval_closure: function (fn) {
return fn(arguments[1])
},
observable_obj: {
set_called: false,
target: new Proxy({
nested: {}
}, {
set(target, key, value) {
global.globalObject1.observable_obj.set_called = true;
target[key] = value;
return true;
}
})
},
};
global.Animal = function (name, age, isCat) {
if (age < 0) {
throw new Error("Invalid age " + age);
}
this.name = name;
this.age = age;
this.bark = () => {
return isCat ? "nyan" : "wan";
};
this.isCat = isCat;
this.getIsCat = function () {
return this.isCat;
};
this.setName = function (name) {
this.name = name;
}
};
const { startWasiTask } = require("../lib");
startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
console.log(err);
process.exit(1);
});