如何使用JavaScript V8的拦截器?请向我提供有关它的示例代码. [英] How to use interceptor of JavaScript V8?Pls provide me a sample code about it.Thanks!

查看:80
本文介绍了如何使用JavaScript V8的拦截器?请向我提供有关它的示例代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript V8的拦截器?
请为我提供一个有关c ++的示例代码.

How to use interceptor of JavaScript V8?
Pls provide me a sample code about it with c++.
Thanks!

推荐答案

#include< v8.h>谢谢!
使用命名空间v8;
int main(int argc,char * argv []){
//创建一个堆栈分配的句柄作用域.
HandleScope handle_scope;
//创建一个新的上下文.
处理< context> context = Context :: New();
//输入创建的上下文进行编译,然后
//运行hello world脚本.
Context :: Scope context_scope(context);
//创建一个包含JavaScript源代码的字符串.
处理< string>源= String :: New(" Hello"+``,World!''");
//编译源代码.
处理脚本= Script :: Compile(source);
//运行脚本以获取结果.
处理< value>结果=脚本-& gt; Run();
//将结果转换为ASCII字符串并打印.
字符串:: AsciiValue ascii(result);
printf(%s \ n",* ascii);
返回0;
}
我认为这段代码可以帮助您</value>
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Create a new context.
Handle<context> context = Context::New();
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<string> source = String::New("''Hello'' + '', World!''");
// Compile the source code.
Handle script = Script::Compile(source);
// Run the script to get the result.
Handle<value> result = script-&gt;Run();
// Convert the result to an ASCII string and print it.
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}
i think this code help you</value>


这篇关于如何使用JavaScript V8的拦截器?请向我提供有关它的示例代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆