Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5782ec2

Browse filesBrowse files
addaleaxMyles Borins
authored andcommitted
module: don't cache uninitialized builtins
Don't cache the exported values of fully uninitialized builtins. This works by adding an additional `loading` flag that is only active during initial loading of an internal module and checking that either the module is fully loaded or is in that state before using its cached value. This has the effect that builtins modules which could not be loaded (e.g. because compilation failed due to missing stack space) can be loaded at a later point. Fixes: #6899 Ref: #6899 PR-URL: #6907 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent b9dfdfe commit 5782ec2
Copy full SHA for 5782ec2

File tree

Expand file treeCollapse file tree

3 files changed

+36
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+36
-7
lines changed
Open diff view settings
Collapse file

‎src/node.js‎

Copy file name to clipboardExpand all lines: src/node.js
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@
877877
this.id = id;
878878
this.exports = {};
879879
this.loaded = false;
880+
this.loading = true;
880881
}
881882

882883
NativeModule._source = process.binding('natives');
@@ -888,7 +889,7 @@
888889
}
889890

890891
var cached = NativeModule.getCached(id);
891-
if (cached) {
892+
if (cached && (cached.loaded || cached.loading)) {
892893
return cached.exports;
893894
}
894895

@@ -952,13 +953,18 @@
952953
var source = NativeModule.getSource(this.id);
953954
source = NativeModule.wrap(source);
954955

955-
var fn = runInThisContext(source, {
956-
filename: this.filename,
957-
lineOffset: 0
958-
});
959-
fn(this.exports, NativeModule.require, this, this.filename);
956+
this.loading = true;
957+
try {
958+
var fn = runInThisContext(source, {
959+
filename: this.filename,
960+
lineOffset: 0
961+
});
962+
fn(this.exports, NativeModule.require, this, this.filename);
960963

961-
this.loaded = true;
964+
this.loaded = true;
965+
} finally {
966+
this.loading = false;
967+
}
962968
};
963969

964970
NativeModule.prototype.cache = function() {
Collapse file
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
// copy console accessor because requiring ../common touches it
3+
const consoleDescriptor = Object.getOwnPropertyDescriptor(global, 'console');
4+
delete global.console;
5+
global.console = {};
6+
7+
require('../common');
8+
9+
function a() {
10+
try {
11+
return a();
12+
} catch (e) {
13+
const console = consoleDescriptor.get();
14+
if (console.log) {
15+
console.log('Hello, World!');
16+
} else {
17+
throw e;
18+
}
19+
}
20+
}
21+
22+
a();
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World!

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.