diff --git a/src/node.js b/src/node.js index 7301d9d114ed98..a4d86da6a93a69 100644 --- a/src/node.js +++ b/src/node.js @@ -877,6 +877,7 @@ this.id = id; this.exports = {}; this.loaded = false; + this.loading = true; } NativeModule._source = process.binding('natives'); @@ -888,7 +889,7 @@ } var cached = NativeModule.getCached(id); - if (cached) { + if (cached && (cached.loaded || cached.loading)) { return cached.exports; } @@ -952,13 +953,18 @@ var source = NativeModule.getSource(this.id); source = NativeModule.wrap(source); - var fn = runInThisContext(source, { - filename: this.filename, - lineOffset: 0 - }); - fn(this.exports, NativeModule.require, this, this.filename); + this.loading = true; + try { + var fn = runInThisContext(source, { + filename: this.filename, + lineOffset: 0 + }); + fn(this.exports, NativeModule.require, this, this.filename); - this.loaded = true; + this.loaded = true; + } finally { + this.loading = false; + } }; NativeModule.prototype.cache = function() { diff --git a/test/message/console_low_stack_space.js b/test/message/console_low_stack_space.js new file mode 100644 index 00000000000000..1685a35a1f9304 --- /dev/null +++ b/test/message/console_low_stack_space.js @@ -0,0 +1,22 @@ +'use strict'; +// copy console accessor because requiring ../common touches it +const consoleDescriptor = Object.getOwnPropertyDescriptor(global, 'console'); +delete global.console; +global.console = {}; + +require('../common'); + +function a() { + try { + return a(); + } catch (e) { + const console = consoleDescriptor.get(); + if (console.log) { + console.log('Hello, World!'); + } else { + throw e; + } + } +} + +a(); diff --git a/test/message/console_low_stack_space.out b/test/message/console_low_stack_space.out new file mode 100644 index 00000000000000..8ab686eafeb1f4 --- /dev/null +++ b/test/message/console_low_stack_space.out @@ -0,0 +1 @@ +Hello, World!