Skip to content

Commit d1cb6ac

Browse files
committed
Add testcases for on-demand .prototype
1 parent 68b873b commit d1cb6ac

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*---
2+
{
3+
"custom": true
4+
}
5+
---*/
6+
7+
function FX() {
8+
print('finalize X');
9+
}
10+
function FY() {
11+
print('finalize Y');
12+
}
13+
14+
print('- prototype in func');
15+
var f = function () {};
16+
print('prototype' in f);
17+
Duktape.gc(); Duktape.gc();
18+
19+
print('- own property names');
20+
var f = function () {};
21+
print(Object.getOwnPropertyNames(f).join(','));
22+
f.prototype.foo = 'bar';
23+
print(Object.getOwnPropertyNames(f).join(','));
24+
Duktape.gc(); Duktape.gc();
25+
26+
print('- refcount finalization, anonymous function');
27+
var X = function () {};
28+
Duktape.fin(X, FX);
29+
print('setting X to null');
30+
X = null;
31+
print('X set to null');
32+
Duktape.gc(); Duktape.gc();
33+
34+
print('- refcount finalization, named function');
35+
var X = function foo() {};
36+
Duktape.fin(X, FX);
37+
print('setting X to null');
38+
X = null;
39+
print('X set to null');
40+
Duktape.gc(); Duktape.gc();
41+
42+
print('- refcount finalization, anonymous inner function, reference not kept');
43+
var X = function () {
44+
var Y = function () {};
45+
Duktape.fin(Y, FY);
46+
Y = null;
47+
};
48+
Duktape.fin(X, FX);
49+
print('call X');
50+
X();
51+
print('setting X to null');
52+
X = null;
53+
print('X set to null');
54+
Duktape.gc(); Duktape.gc();
55+
56+
print('- refcount finalization, anonymous inner function, reference kept');
57+
var X = function () {
58+
var Y = function () {};
59+
Duktape.fin(Y, FY);
60+
// At this point the anonymous inner function points to the outer scope,
61+
// which holds a reference back to the function via 'Y', so cannot
62+
// collect via refcounting.
63+
};
64+
Duktape.fin(X, FX);
65+
print('call X');
66+
X();
67+
print('setting X to null');
68+
X = null;
69+
print('X set to null');
70+
Duktape.gc(); Duktape.gc();
71+
72+
print('done');

0 commit comments

Comments
 (0)