Browse Source

Temporary function to determine str byte length

Will need a better place later on
v0.7.4-release
Felix Geisendörfer 15 years ago
committed by Ryan Dahl
parent
commit
7371fcb312
  1. 13
      src/node.cc
  2. 11
      test/mjsunit/test-byte-length.js

13
src/node.cc

@ -231,6 +231,18 @@ Handle<Value> ExecuteString(v8::Handle<v8::String> source,
return scope.Close(result); return scope.Close(result);
} }
static Handle<Value> ByteLength(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("Bad argument.")));
}
Local<Integer> length = Integer::New(DecodeBytes(args[0], ParseEncoding(args[1], UTF8)));
return scope.Close(length);
}
static Handle<Value> Chdir(const Arguments& args) { static Handle<Value> Chdir(const Arguments& args) {
HandleScope scope; HandleScope scope;
@ -624,6 +636,7 @@ static Local<Object> Load(int argc, char *argv[]) {
// define various internal methods // define various internal methods
NODE_SET_METHOD(process, "compile", Compile); NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(process, "_byteLength", ByteLength);
NODE_SET_METHOD(process, "reallyExit", Exit); NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "chdir", Chdir); NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd); NODE_SET_METHOD(process, "cwd", Cwd);

11
test/mjsunit/test-byte-length.js

@ -0,0 +1,11 @@
process.mixin(require("./common"));
assertEquals(14, process._byteLength("Il était tué"));
assertEquals(14, process._byteLength("Il était tué", "utf8"));
assertEquals(12, process._byteLength("Il était tué", "ascii"));
assertEquals(12, process._byteLength("Il était tué", "binary"));
assertThrows('process._byteLength()');
assertThrows('process._byteLength(5)');
Loading…
Cancel
Save