Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: experimental/SkV8Example/SkV8Example.cpp

Issue 100583005: Add a print function in the global JS scope for debugging. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 4 spaces Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <v8.h> 9 #include <v8.h>
10 10
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) { 285 void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
286 RECT winRect; 286 RECT winRect;
287 winRect.top = rect.top(); 287 winRect.top = rect.top();
288 winRect.bottom = rect.bottom(); 288 winRect.bottom = rect.bottom();
289 winRect.right = rect.right(); 289 winRect.right = rect.right();
290 winRect.left = rect.left(); 290 winRect.left = rect.left();
291 InvalidateRect((HWND)this->getHWND(), &winRect, false); 291 InvalidateRect((HWND)this->getHWND(), &winRect, false);
292 } 292 }
293 #endif 293 #endif
294 294
295
296 // The callback that is invoked by v8 whenever the JavaScript 'print'
297 // function is called. Prints its arguments on stdout separated by
298 // spaces and ending with a newline.
299 void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
300 bool first = true;
301 HandleScope handle_scope(args.GetIsolate());
302 for (int i = 0; i < args.Length(); i++) {
303 if (first) {
304 first = false;
305 } else {
306 printf(" ");
307 }
308 v8::String::Utf8Value str(args[i]);
309 printf("%s", ToCString(str));
310 }
311 printf("\n");
312 fflush(stdout);
313 }
314
315
295 // Creates a new execution environment containing the built-in 316 // Creates a new execution environment containing the built-in
296 // function draw(). 317 // function draw().
297 Handle<Context> createRootContext(Isolate* isolate) { 318 Handle<Context> createRootContext(Isolate* isolate) {
298 // Create a template for the global object. 319 // Create a template for the global object.
299 Handle<ObjectTemplate> global = ObjectTemplate::New(); 320 Handle<ObjectTemplate> global = ObjectTemplate::New();
300 321
301 // This is where we would inject any globals into the root Context 322 // This is where we would inject any globals into the root Context
302 // using global->Set(...) 323 // using global->Set(...)
303 324
325 global->Set(v8::String::NewFromUtf8(isolate, "print"),
326 v8::FunctionTemplate::New(Print));
327
304 return Context::New(isolate, NULL, global); 328 return Context::New(isolate, NULL, global);
305 } 329 }
306 330
307 331
308 // Parse and run script. Then fetch out the onDraw function from the global 332 // Parse and run script. Then fetch out the onDraw function from the global
309 // object. 333 // object.
310 bool JsCanvas::initialize(const char script[]) { 334 bool JsCanvas::initialize(const char script[]) {
311 335
312 // Create a stack-allocated handle scope. 336 // Create a stack-allocated handle scope.
313 HandleScope handleScope(fIsolate); 337 HandleScope handleScope(fIsolate);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (NULL == script) { 425 if (NULL == script) {
402 printf("Could not load file: %s.\n", FLAGS_infile[0]); 426 printf("Could not load file: %s.\n", FLAGS_infile[0]);
403 exit(1); 427 exit(1);
404 } 428 }
405 if (!jsCanvas->initialize(script)) { 429 if (!jsCanvas->initialize(script)) {
406 printf("Failed to initialize.\n"); 430 printf("Failed to initialize.\n");
407 exit(1); 431 exit(1);
408 } 432 }
409 return new SkV8ExampleWindow(hwnd, jsCanvas); 433 return new SkV8ExampleWindow(hwnd, jsCanvas);
410 } 434 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698