Browse Source

Use an anonymous function in Node module loader extra

pull/843/head
Saúl Ibarra Corretgé 8 years ago
parent
commit
7a37618141
  1. 7
      extras/module-node/duk_module_node.c

7
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 * way to implement CommonJS closure semantics and matches the behavior of
* e.g. Node.js. * 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_dup(ctx, -2); /* source */
duk_push_string(ctx, "})"); duk_push_string(ctx, "})");
duk_concat(ctx, 3); duk_concat(ctx, 3);
@ -215,6 +215,11 @@ static duk_int_t duk__eval_module_source(duk_context *ctx) {
/* [ ... module source func ] */ /* [ ... 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 */ /* call the function wrapper */
(void) duk_get_prop_string(ctx, -3, "exports"); /* exports */ (void) duk_get_prop_string(ctx, -3, "exports"); /* exports */
(void) duk_get_prop_string(ctx, -4, "require"); /* require */ (void) duk_get_prop_string(ctx, -4, "require"); /* require */

Loading…
Cancel
Save