Skip to content

Commit

Permalink
Fix fileName for functions defined within a module
Browse files Browse the repository at this point in the history
See GH-58.
  • Loading branch information
svaarala committed Oct 29, 2014
1 parent 8aad9fb commit 08c6e05
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/duk_bi_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08c6e05

Please sign in to comment.