-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic_test.js
More file actions
59 lines (44 loc) · 1.82 KB
/
Copy pathbasic_test.js
File metadata and controls
59 lines (44 loc) · 1.82 KB
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
basic_demonstration = true;
function concat(...args) { return args.join(''); }
// use var makes it visible after script exit, let/const will not be
try {
print(`script called with magic: ${magic}\n`);
var panic = true;
var s1 = new sentinel();
var s2 = s1;
s1.foo('foo called from s1');
s2.foo('foo called from s2');
// direct access to public property works
print(`calling s1.bar(): [${s1.value_}]\n`);
// demonstrates property can be reassigned
s1.value_ = `panic is currently: ${panic}`
// demonstrates s1 is s2 (not a copy) and accessor on C++ side see property value change
print(`calling s2.bar(): [${s2.bar()}]\n`);
var parent = new sentinel();
parent.foo('parent');
print(`parent is instance ${parent.instance_}\n`);
try {
parent.instance_ = 5;
print(`[illegal] parent.instance_ = 5 succeeded!\n`);
} catch (e) {
print(`[illegal] parent.instance_ = 5 had exception ${e}\n`);
}
var child1 = parent.create_child();
child1.foo('child1');
var const_child = parent.get_child_const();
print(`[legal] const_child.bar(): ${const_child.bar()}\n`);
try {
var const_child_child = const_child.create_child();
print(`[illegal] const_child.create_child() succeeded!\n`);
} catch (e) {
print(`[illegal] const_child.create_child() had exception: ${e}\n`);
}
// this is the same as the result from create_child, but on the C++ side it's different,
// demonstrating that C++ functions returning pointers or references both work from JS
var child2 = parent.get_child();
child2.foo('child2');
print(`parent has value [${parent.value_}], child1 [${child1.value_}], child2 [${child2.value_}] \n`);
`hello world, add('21', 2) = ${add('21', 2)}`;
} catch (e) {
`Execution failed: ${e}`;
}