/* * Copyright 2013 Google Inc. * * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * */ #include using namespace v8; #include "SkV8Example.h" #include "gl/GrGLUtil.h" #include "gl/GrGLDefines.h" #include "gl/GrGLInterface.h" #include "SkApplication.h" #include "SkDraw.h" #include "SkGpuDevice.h" #include "SkGraphics.h" void application_init() { SkGraphics::Init(); SkEvent::Init(); } void application_term() { SkEvent::Term(); SkGraphics::Term(); } // Extracts a C string from a V8 Utf8Value. const char* ToCString(const v8::String::Utf8Value& value) { return *value ? *value : ""; } // Slight modification to an original function found in the V8 sample shell.cc. void reportException(Isolate* isolate, TryCatch* try_catch) { HandleScope handle_scope(isolate); String::Utf8Value exception(try_catch->Exception()); const char* exception_string = ToCString(exception); Handle message = try_catch->Message(); if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. fprintf(stderr, "%s\n", exception_string); } else { // 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_string); // 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. 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"); String::Utf8Value stack_trace(try_catch->StackTrace()); if (stack_trace.length() > 0) { const char* stack_trace_string = ToCString(stack_trace); fprintf(stderr, "%s\n", stack_trace_string); } } } SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, Isolate* isolate, Handle context, Handle