From d5f1a647e101227fd915fd43d113375dbbd5f8bd Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 11 Mar 2017 01:28:13 +0200 Subject: [PATCH 1/2] Allow modules with // on last unterminated line --- extras/module-duktape/Makefile | 1 + extras/module-duktape/duk_module_duktape.c | 2 +- extras/module-node/Makefile | 1 + extras/module-node/duk_module_node.c | 2 +- extras/module-node/test.c | 2 ++ 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extras/module-duktape/Makefile b/extras/module-duktape/Makefile index 5d9518bd..300acc45 100644 --- a/extras/module-duktape/Makefile +++ b/extras/module-duktape/Makefile @@ -11,3 +11,4 @@ test: ./test 'assert(typeof Duktape.modSearch === "undefined");' ./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 123;" }; assert(require("dummy").foo === 123);' ./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 234;" }; delete Duktape; assert(typeof Duktape === "undefined"); assert(require("dummy").foo === 234);' + ./test 'Duktape.modSearch = function myModSearch(id) { return "exports.foo = 234; // comment" }; delete Duktape; assert(typeof Duktape === "undefined"); assert(require("dummy").foo === 234);' diff --git a/extras/module-duktape/duk_module_duktape.c b/extras/module-duktape/duk_module_duktape.c index b1546843..5b789e85 100644 --- a/extras/module-duktape/duk_module_duktape.c +++ b/extras/module-duktape/duk_module_duktape.c @@ -346,7 +346,7 @@ static duk_ret_t duk__require(duk_context *ctx) { * (Note capitalization: .filename matches Node.js while .fileName is * used elsewhere in Duktape.) */ - duk_push_string(ctx, "})"); + duk_push_string(ctx, "\n})"); /* Newline allows module last line to contain a // comment. */ duk_concat(ctx, 3); if (!duk_get_prop_string(ctx, DUK__IDX_MODULE, "filename")) { /* module.filename for .fileName, default to resolved ID if diff --git a/extras/module-node/Makefile b/extras/module-node/Makefile index 6fb6bcd1..b381ceff 100644 --- a/extras/module-node/Makefile +++ b/extras/module-node/Makefile @@ -15,3 +15,4 @@ test: ./test 'var ape = require("ape"); assert(ape.module.loaded === true && ape.wasLoaded === false, "module.loaded");' ./test 'var ape = require("ape"); assert(ape.__filename === "ape.js", "__filename");' ./test 'var badger = require("badger"); assert(badger.foo === 123 && badger.bar === 234, "exports.foo assignment");' + ./test 'var comment = require("comment"); assert(comment.foo === 123 && comment.bar === 234, "last line with // comment");' diff --git a/extras/module-node/duk_module_node.c b/extras/module-node/duk_module_node.c index 2704dd44..6e74ba7f 100644 --- a/extras/module-node/duk_module_node.c +++ b/extras/module-node/duk_module_node.c @@ -218,7 +218,7 @@ static duk_int_t duk__eval_module_source(duk_context *ctx) { */ duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname){"); duk_dup(ctx, -2); /* source */ - duk_push_string(ctx, "})"); + duk_push_string(ctx, "\n})"); /* Newline allows module last line to contain a // comment. */ duk_concat(ctx, 3); /* [ ... module source func_src ] */ diff --git a/extras/module-node/test.c b/extras/module-node/test.c index 8daa57de..fe878a5a 100644 --- a/extras/module-node/test.c +++ b/extras/module-node/test.c @@ -36,6 +36,8 @@ static duk_ret_t cb_load_module(duk_context *ctx) { duk_push_string(ctx, "module.exports = { module: module, __filename: __filename, wasLoaded: module.loaded };"); } else if (strcmp(module_id, "badger.js") == 0) { duk_push_string(ctx, "exports.foo = 123; exports.bar = 234;"); + } else if (strcmp(module_id, "comment.js") == 0) { + duk_push_string(ctx, "exports.foo = 123; exports.bar = 234; // comment"); } else { duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot find module: %s", module_id); } From 6e44372c2663f9f801773ed2906c93bbf544ce33 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Sat, 11 Mar 2017 01:30:04 +0200 Subject: [PATCH 2/2] Releases: modules with trailing // comment --- RELEASES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.rst b/RELEASES.rst index 51633d79..cea29edb 100644 --- a/RELEASES.rst +++ b/RELEASES.rst @@ -2522,6 +2522,9 @@ Planned * Fix duk_error_raw() compile warning with -Wmissing-prototypes (GH-1390) +* Fix module-duktape and module-node handling of a module source which has + a // comment on the last line without a trailing newline (GH-1394, GH-1395) + * Avoid log2(), log10(), cbrt(), and trunc() on Android (GH-1325, GH-1341) * Portability improvements for Solaris, HPUX, and AIX (GH-1356)