-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improve-require-file-name'
Fix fileName for functions defined by modules loaded using require(). Although the fileName for the (Duktape internal) module function was set to the resolved module ID, any functions defined in the module woult not be affected by this and fileName would default to "duk_bi_global.c" which is highly misleading. See GH-58.
- Loading branch information
Showing
4 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters