#include "node.h" #include "events.h" #include "net.h" #include "file.h" #include "http.h" #include "timer.h" #include "process.h" #include "constants.h" #include "natives.h" #include #include #include #include #include #include #include using namespace v8; using namespace node; using namespace std; static void buf_free (evnet_buf *b) { V8::AdjustAmountOfExternalAllocatedMemory(-b->len); free(b); } evnet_buf * node::buf_new (size_t size) { size_t total = sizeof(evnet_buf) + size; void *p = malloc(total); if (p == NULL) return NULL; evnet_buf *b = static_cast(p); b->base = static_cast(p) + sizeof(evnet_buf); b->len = size; b->release = buf_free; V8::AdjustAmountOfExternalAllocatedMemory(total); return b; } // Extracts a C string from a V8 Utf8Value. const char* ToCString(const v8::String::Utf8Value& value) { return *value ? *value : ""; } void ReportException(v8::TryCatch* try_catch) { v8::HandleScope handle_scope; v8::String::Utf8Value exception(try_catch->Exception()); const char* exception_string = ToCString(exception); v8::Handle message = try_catch->Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. printf("%s\n", exception_string); } else { message->PrintCurrentStackTrace(stdout); // Print (filename):(line number): (message). v8::String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); printf("%s:%i: %s\n", filename_string, linenum, exception_string); // Print line of source code. v8::String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); printf("%s\n", sourceline_string); // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { printf(" "); } int end = message->GetEndColumn(); for (int i = start; i < end; i++) { printf("^"); } printf("\n"); } } // Executes a string within the current v8 context. Handle ExecuteString(v8::Handle source, v8::Handle filename) { HandleScope scope; TryCatch try_catch; Handle