#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" #include #include #include #include /* PATH_MAX */ #include #include #include #include /* dlopen(), dlsym() */ #include #include #include #include using namespace v8; using namespace node; // Extracts a C string 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(); if (message.IsEmpty()) { fprintf(stderr, "Error: (no message)\n"); return; } Handle error = try_catch.Exception(); Handle stack; if (error->IsObject()) { Handle obj = Handle::Cast(error); Handle raw_stack = obj->Get(String::New("stack")); if (raw_stack->IsString()) stack = Handle::Cast(raw_stack); } if (stack.IsEmpty()) { String::Utf8Value exception(error); // Print (filename):(line number): (message). String::Utf8Value filename(message->GetScriptResourceName()); const char* filename_string = ToCString(filename); int linenum = message->GetLineNumber(); fprintf(stderr, "%s:%i: %s\n", filename_string, linenum, *exception); // Print line of source code. String::Utf8Value sourceline(message->GetSourceLine()); const char* sourceline_string = ToCString(sourceline); fprintf(stderr, "%s\n", sourceline_string); // Print wavy underline (GetUnderline is deprecated). int start = message->GetStartColumn(); for (int i = 0; i < start; i++) { fprintf(stderr, " "); } int end = message->GetEndColumn(); for (int i = start; i < end; i++) { fprintf(stderr, "^"); } fprintf(stderr, "\n"); message->PrintCurrentStackTrace(stderr); } else { String::Utf8Value trace(stack); fprintf(stderr, "%s\n", *trace); } } // Executes a string within the current v8 context. Handle ExecuteString(v8::Handle source, v8::Handle filename) { HandleScope scope; TryCatch try_catch; Handle