]> git.kaiwu.me - njs.git/commit
Fixed module importing using require().
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 15 Aug 2019 16:22:01 +0000 (19:22 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 15 Aug 2019 16:22:01 +0000 (19:22 +0300)
commit92b8a81bd32d229d047b8ed03ad6a93bfc3f4a50
treef809f69333b1a019c416c12b492e156369e8fcec
parent2f2bf4fb99b3fb5e9ce9b731d11c7cb464545982
Fixed module importing using require().

Previously, require() did not make a mutable copy of imported module.
As a result, cloned VMs could change a shared module object making
module.object->hash inconsistent.

Before 04d7a5d93ae6, the problem manifested itself only in "PROP GET"
operations, for example, using "require('fs').renameSync", because
njs_value_property() makes a mutable copy of shared methods in
module.object->hash.

After 04d7a5d93ae6, "METHOD CALL" operations, such as
"require('fs').renameSync()", now have the same problem as in "PROP
GET".

Importing modules using "import" statement is not affected, because
for it "OBJECT COPY" instruction is generated, which makes a mutable
copy of imported module object.

The fix is to make a mutable copy of a shared module in require().

This closes #206 issue on Github.
src/njs_module.c
src/test/njs_unit_test.c