njs: setImmediate() is broken inside module
$ cat bug.js
export default { bug: true };
setImmediate(function() {
console.log('immediate');
});
$ build/njs
interactive njs 0.3.0
v.<Tab> -> the properties and prototype methods of v.
type console.help() for more information
>> import bug from 'bug.js'
ReferenceError: "setImmediate" is not defined in bug.js:0
>> bug
ReferenceError: "bug" is not defined in shell:1
>> setImmediate
Segmentation fault
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 28 (28 by maintainers)
Commits related to this issue
- Resetting loaded modules in accumulative mode. This closes #113 issue on Github. — committed to nginx/njs by xeioex 5 years ago
@drsm
Fixed modules reset in accumulative mode.
Thanks again.
@drsm I need more work, the patch is still not ideal.
@hongzhidao with the patch above:
deleted.
@xeioex @hongzhidao
and
@xeioex
I think we can commit it first, then I’ll recommit the patch of
arrow function. This ticket can be kept.In next week.
arrow function.template literal.@hongzhidao
Agree. So, let’s wait for @drsm response, otherwise I plan to commit https://gist.github.com/xeioex/83f8a91447f075e29d220e9bc54647b8
@xeioex
Yes. It does in chrome.
I think I misunderstand the usage of variable accessing in modules. See this. It seems global variables are allowed to access in modules. http://exploringjs.com/es6/ch_modules.html#_benefit-variable-checking
It only says that the top level scope of variables in modules is a local scope. If yes, your patch is right enough.
@drsm suggestions are welcome.
@xeioex
cat test.html (note that add type with ‘module’ value)
cat file2.js
cat file1.js
@xeioex
Tried in chrome.
And normal global variables are not allowed to access in modules.
@hongzhidao, BTW it does not fail without the patch (will do), otherwise looks good.
@drsm thanks.
Try the patch please.