From 19491efee8521ad3c029302d1764b0081a377a7e Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 29 Oct 2014 15:23:22 +0200 Subject: [PATCH 1/4] Testcase for GH-58 --- .../test-commonjs-require-filename.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ecmascript-testcases/test-commonjs-require-filename.js diff --git a/ecmascript-testcases/test-commonjs-require-filename.js b/ecmascript-testcases/test-commonjs-require-filename.js new file mode 100644 index 0000000000..d682065bac --- /dev/null +++ b/ecmascript-testcases/test-commonjs-require-filename.js @@ -0,0 +1,50 @@ +/* + * Filename for functions inside a module loaded using require() + * + * In Duktape 1.0.0 this would always be "duk_bi_global.c" which is confusing. + * For Duktape 1.1.0 this was fixed to be the fully resolved module ID. + * See GH-58 for discussion. + */ + +/*--- +{ + "custom": true +} +---*/ + +/*=== +moduleFunc name: +moduleFunc fileName: foo +testFunc name: testFunc +testFunc fileName: foo +===*/ + +function modSearch() { + return "function testFunc() { print('testFunc name:', Duktape.act(-2).function.name);\n" + + " print('testFunc fileName:', Duktape.act(-2).function.fileName); }\n" + + "\n" + + "exports.testFunc = testFunc;\n" + + "print('moduleFunc name:', Duktape.act(-2).function.name);\n" + + "print('moduleFunc fileName:', Duktape.act(-2).function.fileName);\n"; +} + +function test() { + /* For the module function itself (which is a Duktape internal artifact) + * the fileName is already forced to be module ID. This was OK in + * Duktape 1.0.0. + */ + + Duktape.modSearch = modSearch; + var mod = require('foo'); + + /* However, functions defined within the module don't have a proper + * fileName in Duktape 1.0.0. + */ + mod.testFunc(); +} + +try { + test(); +} catch (e) { + print(e.stack || e); +} From 8aad9fb49e47ebbbf633e2ebb6d19aed71ca8a00 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 29 Oct 2014 15:26:42 +0200 Subject: [PATCH 2/4] Testcase knownissue: depends on timezone --- ecmascript-testcases/test-bug-date-timeval-edges.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ecmascript-testcases/test-bug-date-timeval-edges.js b/ecmascript-testcases/test-bug-date-timeval-edges.js index 1739154983..b1b35628e7 100644 --- a/ecmascript-testcases/test-bug-date-timeval-edges.js +++ b/ecmascript-testcases/test-bug-date-timeval-edges.js @@ -10,6 +10,12 @@ * to either side of 01 January, 1970 UTC. */ +/*--- +{ + "knownissue": "test case depends on current timezone offset" +} +---*/ + /*=== test1 8639999996399999 From 08c6e0573c33782dd1efc73f0d47849b065a373c Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 29 Oct 2014 15:27:36 +0200 Subject: [PATCH 3/4] Fix fileName for functions defined within a module See GH-58. --- src/duk_bi_global.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/duk_bi_global.c b/src/duk_bi_global.c index 715921e205..5cf52275e4 100644 --- a/src/duk_bi_global.c +++ b/src/duk_bi_global.c @@ -1073,17 +1073,15 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_require(duk_context *ctx) { return 1; } - /* Finish the wrapped module source. */ + /* Finish the wrapped module source. Force resolved module ID as the + * fileName so it gets set for functions defined within a module. This + * also ensures loggers created within the module get the module ID as + * their default logger name. + */ duk_push_string(ctx, "})"); duk_concat(ctx, 3); - duk_eval(ctx); - - /* Force 'fileName' property of the module function so that if the - * module creates a logger, the logger name defaults to the module - * name. - */ - duk_dup(ctx, 3); - duk_put_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME); + duk_dup(ctx, 3); /* resolved module ID for fileName */ + duk_eval_raw(ctx, NULL, 0, DUK_COMPILE_EVAL); /* XXX: The module wrapper function is currently anonymous and is shown * in stack traces. It would be nice to force it to match the module From 3a63e10e02e90a24a479e72fbe1946e4f284afce Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 29 Oct 2014 15:31:39 +0200 Subject: [PATCH 4/4] Release note: fileName for loaded modules --- RELEASES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASES.rst b/RELEASES.rst index b0c18882d2..173a58fd33 100644 --- a/RELEASES.rst +++ b/RELEASES.rst @@ -615,6 +615,10 @@ Planned * Fix compile error for DUK_OPT_NO_PC2LINE +* Fix fileName for functions defined in a module loaded using require(), + previously fileName would always be duk_bi_global.c which is misleading + (see GH-58) + 1.2.0 (2015-XX-XX) ------------------