Browse Source

Fix utf8 scripts, add test. Thanks Urban.

v0.7.4-release
Ryan 16 years ago
parent
commit
b1588e78d9
  1. 12
      src/file.cc
  2. 4
      src/file.js
  3. 10
      test/mjsunit/test-utf8-scripts.js
  4. 2
      website/api.txt

12
src/file.cc

@ -248,17 +248,19 @@ AfterUtf8Read (eio_req *req)
HandleScope scope;
Local<Value> argv[1];
Local<Value> argv[2];
if (req->result == 0) {
// eof
argv[0] = Local<Value>::New(Null());
argv[1] = Integer::New(0);
} else {
char *buf = reinterpret_cast<char*>(req->ptr2);
argv[0] = String::New(buf, req->result);
argv[1] = Integer::New(req->result);
}
promise->EmitSuccess(1, argv);
promise->EmitSuccess(2, argv);
return 0;
}
@ -273,10 +275,11 @@ AfterRawRead(eio_req *req)
}
HandleScope scope;
Local<Value> argv[1];
Local<Value> argv[2];
if (req->result == 0) {
argv[0] = Local<Value>::New(Null());
argv[1] = Integer::New(0);
} else {
char *buf = reinterpret_cast<char*>(req->ptr2);
size_t len = req->result;
@ -285,9 +288,10 @@ AfterRawRead(eio_req *req)
array->Set(Integer::New(i), Integer::New(buf[i]));
}
argv[0] = array;
argv[1] = Integer::New(req->result);
}
promise->EmitSuccess(1, argv);
promise->EmitSuccess(2, argv);
return 0;
}

4
src/file.js

@ -20,14 +20,14 @@ node.fs.cat = function (path, encoding) {
read_promise.addErrback(function () { cat_promise.emitError(); });
read_promise.addCallback(function (chunk) {
read_promise.addCallback(function (chunk, bytes_read) {
if (chunk) {
if (chunk.constructor == String)
content += chunk;
else
content = content.concat(chunk);
pos += chunk.length;
pos += bytes_read;
readChunk();
} else {
cat_promise.emitSuccess([content]);

10
test/mjsunit/test-utf8-scripts.js

@ -0,0 +1,10 @@
include("mjsunit.js");
// üäö
puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
function onLoad () {
  assertTrue( /Hellö Wörld/.test("Hellö Wörld") );
}

2
website/api.txt

@ -479,7 +479,7 @@ reading from in the file.
+encoding+ is either +node.UTF8+
or +node.RAW+.
+
- on success: returns +data+, what was read from the file.
- on success: returns +data, bytes_read+, what was read from the file.
- on error: no parameters.

Loading…
Cancel
Save