WebKit之V8编写简单demon

来源:互联网 发布:淘宝中的延长收货 编辑:程序博客网 时间:2024/04/19 12:33

## 测试  testv8.cxx

[cpp] view plain copy
  1. // testv8.cpp : Defines the entry point for the console application.  
  2. //  
  3. #include <v8.h>  
  4.   
  5. using namespace v8;  
  6.   
  7. int main(int argc, char* argv[]) {  
  8.   
  9.     // Create a stack-allocated handle scope.  
  10.     HandleScope handle_scope;  
  11.   
  12.     // Create a new context.  
  13.     Persistent<Context> context = Context::New();  
  14.   
  15.     // Enter the created context for compiling and  
  16.     // running the hello world script.   
  17.     Context::Scope context_scope(context);  
  18.   
  19.     // Create a string containing the JavaScript source code.  
  20.     Handle<String> source = String::New("var x='xyziamheres2///sdfsdf123'; x.match(/\\d{3,3}/);");  
  21.   
  22.     // Compile the source code.  
  23.     Handle<Script> script = Script::Compile(source);  
  24.   
  25.     // Run the script to get the result.  
  26.     Handle<Value> result = script->Run();  
  27.   
  28.     // Dispose the persistent context.  
  29.     context.Dispose();  
  30.   
  31.     // Convert the result to an ASCII string and print it.  
  32.     String::AsciiValue ascii(result);  
  33.     printf("%s\n", *ascii);  
  34.     return 0;  
  35. }  
0 0
原创粉丝点击