Temporary function to determine str byte length

Will need a better place later on
This commit is contained in:
Felix Geisendörfer 2009-11-11 18:10:58 +01:00 committed by Ryan Dahl
parent 1026ffea40
commit 7371fcb312
2 changed files with 24 additions and 0 deletions

View File

@ -231,6 +231,18 @@ Handle<Value> ExecuteString(v8::Handle<v8::String> source,
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) {
HandleScope scope;
@ -624,6 +636,7 @@ static Local<Object> Load(int argc, char *argv[]) {
// define various internal methods
NODE_SET_METHOD(process, "compile", Compile);
NODE_SET_METHOD(process, "_byteLength", ByteLength);
NODE_SET_METHOD(process, "reallyExit", Exit);
NODE_SET_METHOD(process, "chdir", Chdir);
NODE_SET_METHOD(process, "cwd", Cwd);

View File

@ -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)');