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

Unified Diff: samples/shell.cc

Issue 5274002: Version 2.5.8... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 1 month 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 | « include/v8-profiler.h ('k') | src/SConscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/shell.cc
===================================================================
--- samples/shell.cc (revision 5873)
+++ samples/shell.cc (working copy)
@@ -37,6 +37,7 @@
v8::Handle<v8::Value> name,
bool print_result,
bool report_exceptions);
+v8::Handle<v8::Value> PrintToInteger(const v8::Arguments& args);
v8::Handle<v8::Value> Print(const v8::Arguments& args);
v8::Handle<v8::Value> Read(const v8::Arguments& args);
v8::Handle<v8::Value> Load(const v8::Arguments& args);
@@ -53,7 +54,8 @@
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
// Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
- // Bind the global 'read' function to the C++ Read callback.
+global->Set(v8::String::New("print2int"), v8::FunctionTemplate::New(PrintToInteger));
+// Bind the global 'read' function to the C++ Read callback.
global->Set(v8::String::New("read"), v8::FunctionTemplate::New(Read));
// Bind the global 'load' function to the C++ Load callback.
global->Set(v8::String::New("load"), v8::FunctionTemplate::New(Load));
@@ -138,6 +140,16 @@
}
+v8::Handle<v8::Value> PrintToInteger(const v8::Arguments& args) {
+ v8::HandleScope handle_scope;
+ v8::String::Utf8Value str(args[0]);
+ const char* cstr = ToCString(str);
+ printf("%s -> %d\n", cstr, args[0]->ToInt32()->Value());
+ fflush(stdout);
+ return v8::Undefined();
+}
+
+
// The callback that is invoked by v8 whenever the JavaScript 'read'
// function is called. This function loads the content of the file named in
// the argument into a JavaScript string.
« no previous file with comments | « include/v8-profiler.h ('k') | src/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698