-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcases for on-demand .prototype
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
tests/ecmascript/test-dev-ondemand-constructor-prototype-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*--- | ||
{ | ||
"custom": true | ||
} | ||
---*/ | ||
|
||
function FX() { | ||
print('finalize X'); | ||
} | ||
function FY() { | ||
print('finalize Y'); | ||
} | ||
|
||
print('- prototype in func'); | ||
var f = function () {}; | ||
print('prototype' in f); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('- own property names'); | ||
var f = function () {}; | ||
print(Object.getOwnPropertyNames(f).join(',')); | ||
f.prototype.foo = 'bar'; | ||
print(Object.getOwnPropertyNames(f).join(',')); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('- refcount finalization, anonymous function'); | ||
var X = function () {}; | ||
Duktape.fin(X, FX); | ||
print('setting X to null'); | ||
X = null; | ||
print('X set to null'); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('- refcount finalization, named function'); | ||
var X = function foo() {}; | ||
Duktape.fin(X, FX); | ||
print('setting X to null'); | ||
X = null; | ||
print('X set to null'); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('- refcount finalization, anonymous inner function, reference not kept'); | ||
var X = function () { | ||
var Y = function () {}; | ||
Duktape.fin(Y, FY); | ||
Y = null; | ||
}; | ||
Duktape.fin(X, FX); | ||
print('call X'); | ||
X(); | ||
print('setting X to null'); | ||
X = null; | ||
print('X set to null'); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('- refcount finalization, anonymous inner function, reference kept'); | ||
var X = function () { | ||
var Y = function () {}; | ||
Duktape.fin(Y, FY); | ||
// At this point the anonymous inner function points to the outer scope, | ||
// which holds a reference back to the function via 'Y', so cannot | ||
// collect via refcounting. | ||
}; | ||
Duktape.fin(X, FX); | ||
print('call X'); | ||
X(); | ||
print('setting X to null'); | ||
X = null; | ||
print('X set to null'); | ||
Duktape.gc(); Duktape.gc(); | ||
|
||
print('done'); |