From d6c9d31cb5a343f8280035b1d3770e6d7c917201 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Sep 2009 16:02:29 +0200 Subject: [PATCH] cpplint.py node.cc and node.h --- src/node.cc | 209 +++++++++++++++++++++------------------------------- src/node.h | 45 ++++++----- 2 files changed, 110 insertions(+), 144 deletions(-) diff --git a/src/node.cc b/src/node.cc index d26b6a1be9..9158e8314c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1,16 +1,5 @@ -#include "node.h" - -#include "events.h" -#include "dns.h" -#include "net.h" -#include "file.h" -#include "http.h" -#include "timer.h" -#include "child_process.h" -#include "constants.h" -#include "node_stdio.h" - -#include "natives.h" +// Copyright 2009 Ryan Dahl +#include #include #include @@ -21,20 +10,25 @@ #include #include /* dlopen(), dlsym() */ -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include using namespace v8; -using namespace node; extern char **environ; -Local -node::Encode (const void *buf, size_t len, enum encoding encoding) -{ +namespace node { + +Local Encode(const void *buf, size_t len, enum encoding encoding) { HandleScope scope; if (!len) return scope.Close(Null()); @@ -47,16 +41,17 @@ node::Encode (const void *buf, size_t len, enum encoding encoding) array->Set(Integer::New(i), Integer::New(val)); } return scope.Close(array); - } + } if (encoding == RAWS) { const unsigned char *cbuf = static_cast(buf); - uint16_t twobytebuf[len]; + uint16_t * twobytebuf = new uint16_t[len]; for (size_t i = 0; i < len; i++) { - // XXX is the following line platform independent? + // XXX is the following line platform independent? twobytebuf[i] = cbuf[i]; } Local chunk = String::New(twobytebuf, len); + delete twobytebuf; return scope.Close(chunk); } @@ -65,10 +60,8 @@ node::Encode (const void *buf, size_t len, enum encoding encoding) return scope.Close(chunk); } -// Returns -1 if the handle was not valid for decoding -ssize_t -node::DecodeBytes (v8::Handle val, enum encoding encoding) -{ +// Returns -1 if the handle was not valid for decoding +ssize_t DecodeBytes(v8::Handle val, enum encoding encoding) { HandleScope scope; if (val->IsArray()) { @@ -79,21 +72,21 @@ node::DecodeBytes (v8::Handle val, enum encoding encoding) if (!val->IsString()) return -1; - Handle string = Handle::Cast(val); + Handle str = Handle::Cast(val); - if (encoding == UTF8) return string->Utf8Length(); + if (encoding == UTF8) return str->Utf8Length(); - return string->Length(); + return str->Length(); } #ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) +# define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif // Returns number of bytes written. -ssize_t -node::DecodeWrite (char *buf, size_t buflen, v8::Handle val, enum encoding encoding) -{ +ssize_t DecodeWrite(char *buf, size_t buflen, + v8::Handle val, + enum encoding encoding) { size_t i; HandleScope scope; @@ -115,23 +108,23 @@ node::DecodeWrite (char *buf, size_t buflen, v8::Handle val, enum enc } assert(val->IsString()); - Handle string = Handle::Cast(val); + Handle str = Handle::Cast(val); if (encoding == UTF8) { - string->WriteUtf8(buf, buflen); + str->WriteUtf8(buf, buflen); return buflen; } if (encoding == ASCII) { - string->WriteAscii(buf, 0, buflen); + str->WriteAscii(buf, 0, buflen); return buflen; } // THIS IS AWFUL!!! FIXME - uint16_t twobytebuf[buflen]; + uint16_t * twobytebuf = new uint16_t[buflen]; - string->Write(twobytebuf, 0, buflen); + str->Write(twobytebuf, 0, buflen); for (size_t i = 0; i < buflen; i++) { unsigned char *b = reinterpret_cast(&twobytebuf[i]); @@ -139,26 +132,24 @@ node::DecodeWrite (char *buf, size_t buflen, v8::Handle val, enum enc buf[i] = b[0]; } + delete twobytebuf; + return buflen; } -// Extracts a C string from a V8 Utf8Value. -const char* -ToCString(const v8::String::Utf8Value& value) -{ - return *value ? *value : ""; +// Extracts a C str from a V8 Utf8Value. +const char* ToCString(const v8::String::Utf8Value& value) { + return *value ? *value : ""; } -static void -ReportException (TryCatch &try_catch) -{ - Handle message = try_catch.Message(); +static void ReportException(TryCatch *try_catch) { + Handle message = try_catch->Message(); if (message.IsEmpty()) { fprintf(stderr, "Error: (no message)\n"); fflush(stderr); return; } - Handle error = try_catch.Exception(); + Handle error = try_catch->Exception(); Handle stack; if (error->IsObject()) { Handle obj = Handle::Cast(error); @@ -198,32 +189,28 @@ ReportException (TryCatch &try_catch) fflush(stderr); } -// Executes a string within the current v8 context. -Handle -ExecuteString(v8::Handle source, - v8::Handle filename) -{ +// Executes a str within the current v8 context. +Handle ExecuteString(v8::Handle source, + v8::Handle filename) { HandleScope scope; TryCatch try_catch; Handle