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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/SkV8Example.cpp
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index 106bef99de2a88e27d24bab722cabebb4d978c2d..a62b9191c6db17e8a95e4f6f2413acd6b53f0043 100644
--- a/experimental/SkV8Example/SkV8Example.cpp
+++ b/experimental/SkV8Example/SkV8Example.cpp
@@ -292,6 +292,27 @@ void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
}
#endif
+
+// The callback that is invoked by v8 whenever the JavaScript 'print'
+// function is called. Prints its arguments on stdout separated by
+// spaces and ending with a newline.
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ bool first = true;
+ HandleScope handle_scope(args.GetIsolate());
+ for (int i = 0; i < args.Length(); i++) {
+ if (first) {
+ first = false;
+ } else {
+ printf(" ");
+ }
+ v8::String::Utf8Value str(args[i]);
+ printf("%s", ToCString(str));
+ }
+ printf("\n");
+ fflush(stdout);
+}
+
+
// Creates a new execution environment containing the built-in
// function draw().
Handle<Context> createRootContext(Isolate* isolate) {
@@ -301,6 +322,9 @@ Handle<Context> createRootContext(Isolate* isolate) {
// This is where we would inject any globals into the root Context
// using global->Set(...)
+ global->Set(v8::String::NewFromUtf8(isolate, "print"),
+ v8::FunctionTemplate::New(Print));
+
return Context::New(isolate, NULL, global);
}
« 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