Skip to content

Commit b52b419

Browse files
isaacsry
authored andcommitted
Fix problem with requireNative not exporting 'module' object
Broke require('constants'). Add unrelated test which breaks it.
1 parent 1255438 commit b52b419

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ function requireNative (id) {
8080
if (!natives[id]) throw new Error('No such native module ' + id);
8181

8282
var fn = evals.Script.runInThisContext(
83-
"(function (exports, require) {" + natives[id] + "\n})",
83+
"(function (module, exports, require) {" + natives[id] + "\n})",
8484
id + '.js');
8585
var m = {id: id, exports: {}};
86-
fn(m.exports, requireNative);
86+
fn(m, m.exports, requireNative);
8787
m.loaded = true;
8888
internalModuleCache[id] = m;
8989
return m.exports;

test/simple/test-fs-write.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
common = require("../common");
2-
assert = common.assert
1+
var common = require("../common");
2+
var assert = common.assert
33
var path = require('path');
44
var Buffer = require('buffer').Buffer;
55
var fs = require('fs');
66
var fn = path.join(common.tmpDir, "write.txt");
7+
var fn2 = path.join(common.tmpDir, "write2.txt");
78
var expected = "ümlaut.";
8-
var found;
9+
var constants = require('constants');
10+
var found, found2;
911

1012
fs.open(fn, 'w', 0644, function (err, fd) {
1113
if (err) throw err;
@@ -25,7 +27,29 @@ fs.open(fn, 'w', 0644, function (err, fd) {
2527
});
2628
});
2729

30+
31+
fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC,
32+
0644, function (err, fd) {
33+
if (err) throw err;
34+
console.log('open done');
35+
fs.write(fd, '', 0, 'utf8', function(err, written) {
36+
assert.equal(0, written);
37+
});
38+
fs.write(fd, expected, 0, "utf8", function (err, written) {
39+
console.log('write done');
40+
if (err) throw err;
41+
assert.equal(Buffer.byteLength(expected), written);
42+
fs.closeSync(fd);
43+
found2 = fs.readFileSync(fn2, 'utf8');
44+
console.log('expected: ' + expected.toJSON());
45+
console.log('found: ' + found2.toJSON());
46+
fs.unlinkSync(fn2);
47+
});
48+
});
49+
50+
2851
process.addListener("exit", function () {
2952
assert.equal(expected, found);
53+
assert.equal(expected, found2);
3054
});
3155

0 commit comments

Comments
 (0)