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 #include "Global.h" | 9 #include "Global.h" |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 int32_t id = gGlobal->getNextTimerID(); | 120 int32_t id = gGlobal->getNextTimerID(); |
121 | 121 |
122 gGlobal->fTimeouts[id].Reset(gGlobal->fIsolate, timeoutFn); | 122 gGlobal->fTimeouts[id].Reset(gGlobal->fIsolate, timeoutFn); |
123 | 123 |
124 // Create an SkEvent and add it with the right delay. | 124 // Create an SkEvent and add it with the right delay. |
125 SkEvent* evt = new SkEvent(); | 125 SkEvent* evt = new SkEvent(); |
126 evt->setTargetProc(Global::TimeOutProc); | 126 evt->setTargetProc(Global::TimeOutProc); |
127 evt->setFast32(id); | 127 evt->setFast32(id); |
128 evt->postDelay(delay); | 128 evt->postDelay(delay); |
129 | 129 |
130 args.GetReturnValue().Set(Integer::New(id)); | 130 args.GetReturnValue().Set(Integer::New(gGlobal->fIsolate, id)); |
131 } | 131 } |
132 | 132 |
133 // Callback function for SkEvents used to implement timeouts. | 133 // Callback function for SkEvents used to implement timeouts. |
134 bool Global::TimeOutProc(const SkEvent& evt) { | 134 bool Global::TimeOutProc(const SkEvent& evt) { |
135 // Create a handle scope to keep the temporary object references. | 135 // Create a handle scope to keep the temporary object references. |
136 HandleScope handleScope(gGlobal->getIsolate()); | 136 HandleScope handleScope(gGlobal->getIsolate()); |
137 | 137 |
138 // Create a local context from our global context. | 138 // Create a local context from our global context. |
139 Local<Context> context = gGlobal->getContext(); | 139 Local<Context> context = gGlobal->getContext(); |
140 | 140 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 return true; | 174 return true; |
175 } | 175 } |
176 | 176 |
177 // Creates a new execution environment containing the built-in functions. | 177 // Creates a new execution environment containing the built-in functions. |
178 Handle<Context> Global::createRootContext() { | 178 Handle<Context> Global::createRootContext() { |
179 // Create a template for the global object. | 179 // Create a template for the global object. |
180 Handle<ObjectTemplate> global = ObjectTemplate::New(); | 180 Handle<ObjectTemplate> global = ObjectTemplate::New(); |
181 | 181 |
182 global->Set(v8::String::NewFromUtf8(fIsolate, "print"), | 182 global->Set(v8::String::NewFromUtf8(fIsolate, "print"), |
183 v8::FunctionTemplate::New(Global::Print)); | 183 v8::FunctionTemplate::New(fIsolate, Global::Print)); |
184 global->Set(v8::String::NewFromUtf8(fIsolate, "setTimeout"), | 184 global->Set(v8::String::NewFromUtf8(fIsolate, "setTimeout"), |
185 v8::FunctionTemplate::New(Global::SetTimeout)); | 185 v8::FunctionTemplate::New(fIsolate, Global::SetTimeout)); |
186 global->Set(v8::String::NewFromUtf8(fIsolate, "inval"), | 186 global->Set(v8::String::NewFromUtf8(fIsolate, "inval"), |
187 v8::FunctionTemplate::New(Global::Inval)); | 187 v8::FunctionTemplate::New(fIsolate, Global::Inval)); |
188 | 188 |
189 | 189 |
190 return Context::New(fIsolate, NULL, global); | 190 return Context::New(fIsolate, NULL, global); |
191 } | 191 } |
192 | 192 |
193 void Global::initialize() { | 193 void Global::initialize() { |
194 // Create a stack-allocated handle scope. | 194 // Create a stack-allocated handle scope. |
195 HandleScope handleScope(fIsolate); | 195 HandleScope handleScope(fIsolate); |
196 | 196 |
197 // Create a new context. | 197 // Create a new context. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // Handle any exceptions or output. | 236 // Handle any exceptions or output. |
237 if (result.IsEmpty()) { | 237 if (result.IsEmpty()) { |
238 SkASSERT(tryCatch.HasCaught()); | 238 SkASSERT(tryCatch.HasCaught()); |
239 // Print errors that happened during execution. | 239 // Print errors that happened during execution. |
240 this->reportException(&tryCatch); | 240 this->reportException(&tryCatch); |
241 return false; | 241 return false; |
242 } | 242 } |
243 | 243 |
244 return true; | 244 return true; |
245 } | 245 } |
OLD | NEW |