0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00

Change encoding setter/getter to setEncoding function.

This commit is contained in:
Ryan 2009-05-20 10:02:02 +02:00
parent 5e37dfca02
commit 1b54e3d87d
4 changed files with 32 additions and 48 deletions

View File

@ -66,11 +66,7 @@ Connection::Initialize (v8::Handle<v8::Object> target)
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fullClose", FullClose);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", ForceClose);
constructor_template->PrototypeTemplate()->SetAccessor(
ENCODING_SYMBOL,
EncodingGetter,
EncodingSetter);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setEncoding", SetEncoding);
constructor_template->PrototypeTemplate()->SetAccessor(
READY_STATE_SYMBOL,
@ -98,41 +94,6 @@ Connection::ReadyStateGetter (Local<String> _, const AccessorInfo& info)
return ThrowException(String::New("This shouldn't happen."));
}
Handle<Value>
Connection::EncodingGetter (Local<String> _, const AccessorInfo& info)
{
Connection *connection = NODE_UNWRAP(Connection, info.This());
if (!connection) return Handle<Value>();
HandleScope scope;
if (connection->encoding_ == UTF8)
return scope.Close(UTF8_SYMBOL);
else
return scope.Close(RAW_SYMBOL);
}
void
Connection::EncodingSetter (Local<String> _, Local<Value> value, const AccessorInfo& info)
{
Connection *connection = NODE_UNWRAP(Connection, info.This());
if (!connection) return;
if (!value->IsString()) {
connection->encoding_ = RAW;
return;
}
HandleScope scope;
Local<String> encoding = value->ToString();
char buf[5]; // need enough room for "utf8" or "raw"
encoding->WriteAscii(buf, 0, 4);
buf[4] = '\0';
if(strcasecmp(buf, "utf8") == 0)
connection->encoding_ = UTF8;
else
connection->encoding_ = RAW;
}
Connection::Connection (Handle<Object> handle)
: ObjectWrap(handle)
{
@ -234,6 +195,33 @@ Connection::Connect (const Arguments& args)
return Undefined();
}
Handle<Value>
Connection::SetEncoding (const Arguments& args)
{
HandleScope scope;
Connection *connection = NODE_UNWRAP(Connection, args.This());
if (!connection) return Handle<Value>();
if (!args[0]->IsString()) {
connection->encoding_ = RAW;
return scope.Close(RAW_SYMBOL);
}
Local<String> encoding = args[0]->ToString();
char buf[5]; // need enough room for "utf8" or "raw"
encoding->WriteAscii(buf, 0, 4);
buf[4] = '\0';
if(strcasecmp(buf, "utf8") == 0) {
connection->encoding_ = UTF8;
return scope.Close(UTF8_SYMBOL);
} else {
connection->encoding_ = RAW;
return scope.Close(RAW_SYMBOL);
}
}
int
Connection::Resolve (eio_req *req)
{

View File

@ -25,11 +25,7 @@ protected:
static v8::Handle<v8::Value> Close (const v8::Arguments& args);
static v8::Handle<v8::Value> FullClose (const v8::Arguments& args);
static v8::Handle<v8::Value> ForceClose (const v8::Arguments& args);
static v8::Handle<v8::Value> EncodingGetter (v8::Local<v8::String> _,
const v8::AccessorInfo& info);
static void EncodingSetter (v8::Local<v8::String> _,
v8::Local<v8::Value> value, const v8::AccessorInfo& info);
static v8::Handle<v8::Value> SetEncoding (const v8::Arguments& args);
static v8::Handle<v8::Value> ReadyStateGetter (v8::Local<v8::String> _,
const v8::AccessorInfo& info);

View File

@ -5,7 +5,7 @@ var N = 1000;
var count = 0;
function Ponger (socket) {
socket.encoding = "UTF8";
socket.setEncoding("utf8");
socket.timeout = 0;
puts("got socket.");
@ -40,7 +40,7 @@ function onLoad() {
var client = new node.tcp.Connection();
assertEquals("closed", client.readyState);
client.encoding = "UTF8";
client.setEncoding("utf8");
client.onConnect = function () {
assertEquals("open", client.readyState);

View File

@ -21,7 +21,7 @@ function onLoad () {
var count = 0;
var client = new node.tcp.Connection();
client.encoding = "UTF8";
client.setEncoding("UTF8");
client.onConnect = function () {
puts("client connected");
};