From 7a37618141b2f0cb4dfa2f1c92267d3c60fd712d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 28 Jun 2016 03:02:07 +0200 Subject: [PATCH] Use an anonymous function in Node module loader extra --- extras/module-node/duk_module_node.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extras/module-node/duk_module_node.c b/extras/module-node/duk_module_node.c index 55a151e0..541f3405 100644 --- a/extras/module-node/duk_module_node.c +++ b/extras/module-node/duk_module_node.c @@ -202,7 +202,7 @@ static duk_int_t duk__eval_module_source(duk_context *ctx) { * way to implement CommonJS closure semantics and matches the behavior of * e.g. Node.js. */ - duk_push_string(ctx, "(function main(exports,require,module,__filename,__dirname){"); + duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname){"); duk_dup(ctx, -2); /* source */ duk_push_string(ctx, "})"); duk_concat(ctx, 3); @@ -215,6 +215,11 @@ static duk_int_t duk__eval_module_source(duk_context *ctx) { /* [ ... module source func ] */ + /* Set name for the wrapper function. */ + duk_push_string(ctx, "name"); + duk_push_string(ctx, "main"); + duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE); + /* call the function wrapper */ (void) duk_get_prop_string(ctx, -3, "exports"); /* exports */ (void) duk_get_prop_string(ctx, -4, "require"); /* require */