Skip to content

Commit

Permalink
Fix problem with requireNative not exporting 'module' object
Browse files Browse the repository at this point in the history
Broke require('constants'). Add unrelated test which breaks it.
  • Loading branch information
isaacs authored and ry committed Nov 22, 2010
1 parent 1255438 commit b52b419
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ function requireNative (id) {
if (!natives[id]) throw new Error('No such native module ' + id);

var fn = evals.Script.runInThisContext(
"(function (exports, require) {" + natives[id] + "\n})",
"(function (module, exports, require) {" + natives[id] + "\n})",
id + '.js');
var m = {id: id, exports: {}};
fn(m.exports, requireNative);
fn(m, m.exports, requireNative);
m.loaded = true;
internalModuleCache[id] = m;
return m.exports;
Expand Down
30 changes: 27 additions & 3 deletions test/simple/test-fs-write.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
common = require("../common");
assert = common.assert
var common = require("../common");
var assert = common.assert
var path = require('path');
var Buffer = require('buffer').Buffer;
var fs = require('fs');
var fn = path.join(common.tmpDir, "write.txt");
var fn2 = path.join(common.tmpDir, "write2.txt");
var expected = "ümlaut.";
var found;
var constants = require('constants');
var found, found2;

fs.open(fn, 'w', 0644, function (err, fd) {
if (err) throw err;
Expand All @@ -25,7 +27,29 @@ fs.open(fn, 'w', 0644, function (err, fd) {
});
});


fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC,
0644, function (err, fd) {
if (err) throw err;
console.log('open done');
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.equal(0, written);
});
fs.write(fd, expected, 0, "utf8", function (err, written) {
console.log('write done');
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.closeSync(fd);
found2 = fs.readFileSync(fn2, 'utf8');
console.log('expected: ' + expected.toJSON());
console.log('found: ' + found2.toJSON());
fs.unlinkSync(fn2);
});
});


process.addListener("exit", function () {
assert.equal(expected, found);
assert.equal(expected, found2);
});

0 comments on commit b52b419

Please sign in to comment.