From d1cb6ac0fc8c374d076757630d4df51e8e13864e Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sun, 15 Apr 2018 00:10:27 +0300 Subject: [PATCH] Add testcases for on-demand .prototype --- ...st-dev-ondemand-constructor-prototype-1.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/ecmascript/test-dev-ondemand-constructor-prototype-1.js diff --git a/tests/ecmascript/test-dev-ondemand-constructor-prototype-1.js b/tests/ecmascript/test-dev-ondemand-constructor-prototype-1.js new file mode 100644 index 0000000000..ddf7a85328 --- /dev/null +++ b/tests/ecmascript/test-dev-ondemand-constructor-prototype-1.js @@ -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');