| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 * | 7 * |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #ifndef SkV8Example_Global_DEFINED | 10 #ifndef SkV8Example_Global_DEFINED |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Provides the global isolate and context for our V8 instance. | 26 // Provides the global isolate and context for our V8 instance. |
| 27 // Also implements all the global level functions. | 27 // Also implements all the global level functions. |
| 28 class Global : SkNoncopyable { | 28 class Global : SkNoncopyable { |
| 29 public: | 29 public: |
| 30 Global(Isolate* isolate) | 30 Global(Isolate* isolate) |
| 31 : fIsolate(isolate) | 31 : fIsolate(isolate) |
| 32 , fWindow(NULL) | 32 , fWindow(NULL) |
| 33 , fLastTimerID(0) | 33 , fLastTimerID(0) |
| 34 { | 34 { |
| 35 gGlobal = this; | 35 gGlobal = this; |
| 36 this->initialize(); |
| 36 } | 37 } |
| 37 virtual ~Global() {} | 38 virtual ~Global() {} |
| 38 | 39 |
| 39 // The script will be parsed into the context this Global contains. | 40 // The script will be parsed into the context this Global contains. |
| 40 bool parseScript(const char script[]); | 41 bool parseScript(const char script[]); |
| 41 | 42 |
| 42 Local<Context> getContext() { | 43 Local<Context> getContext() { |
| 43 return Local<Context>::New(fIsolate, fContext); | 44 return Local<Context>::New(fIsolate, fContext); |
| 44 } | 45 } |
| 45 | 46 |
| 46 Isolate* getIsolate() { | 47 Isolate* getIsolate() { |
| 47 return fIsolate; | 48 return fIsolate; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void setWindow(SkOSWindow* win) { | 51 void setWindow(SkOSWindow* win) { |
| 51 fWindow = win; | 52 fWindow = win; |
| 52 } | 53 } |
| 53 SkOSWindow* getWindow() { | 54 SkOSWindow* getWindow() { |
| 54 return fWindow; | 55 return fWindow; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void reportException(TryCatch* tryCatch); | 58 void reportException(TryCatch* tryCatch); |
| 58 | 59 |
| 59 private: | 60 private: |
| 61 void initialize(); |
| 60 Handle<Context> createRootContext(); | 62 Handle<Context> createRootContext(); |
| 61 int32_t getNextTimerID(); | 63 int32_t getNextTimerID(); |
| 62 | 64 |
| 63 static bool TimeOutProc(const SkEvent& evt); | 65 static bool TimeOutProc(const SkEvent& evt); |
| 64 | 66 |
| 65 // Static functions that implement the global JS functions we add to | 67 // Static functions that implement the global JS functions we add to |
| 66 // the context. | 68 // the context. |
| 67 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args); | 69 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 68 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); | 70 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 69 static void Inval(const v8::FunctionCallbackInfo<Value>& args); | 71 static void Inval(const v8::FunctionCallbackInfo<Value>& args); |
| 70 | 72 |
| 71 Persistent<Context> fContext; | 73 Persistent<Context> fContext; |
| 72 Isolate* fIsolate; | 74 Isolate* fIsolate; |
| 73 SkOSWindow* fWindow; | 75 SkOSWindow* fWindow; |
| 74 static Global* gGlobal; | 76 static Global* gGlobal; |
| 75 | 77 |
| 76 // Handle to the functions to call when a timeout triggers as indexed by id. | 78 // Handle to the functions to call when a timeout triggers as indexed by id. |
| 77 std::map<int32_t, CopyablePersistentFn > fTimeouts; | 79 std::map<int32_t, CopyablePersistentFn > fTimeouts; |
| 78 | 80 |
| 79 // Last timer ID generated. | 81 // Last timer ID generated. |
| 80 int32_t fLastTimerID; | 82 int32_t fLastTimerID; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 #endif | 85 #endif |
| OLD | NEW |