-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
50 lines (37 loc) · 1.36 KB
/
test.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
var addon = require('bindings')('arctic');
addon.configure_module_path(__dirname);
// test
setInterval(function () { }, 0);
(async () => {
try {
var agent = addon.create_host_agent(1, []);
var object = {};
object.foo = "bar";
object.func = function (value) {
console.log("func has been called.(" + value + ")");
}
agent.export("instance", object);
var res = agent.start();
if (res != 0) {
return;
}
var localInstance = await agent.find(1, "instance");
console.log("localInstance.foo = " + await localInstance.getProperty("foo"));
await localInstance.setProperty("aaa", 123321);
console.log("localInstance.aaa = ", await localInstance.getProperty("aaa"));
localInstance.invoke("func", "fake parameters");
var one = function () {
console.log("one event has been fired.");
}
var two = function () {
console.log("two event has been fired.");
}
localInstance.addEventListener("one", one);
localInstance.addEventListener("two", two);
localInstance.removeEventListener("one", one);
localInstance.fireEvent("one");
localInstance.fireEvent("two");
} catch (e) {
console.log(e);
}
})();