#include <v8.h>
using namespace v8;
int main()
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Handle<String> string = String::New("function People() { this.name = 'lixinqi'; } People.prototype.getName = function () { return this.name; }; var p = new People();");
Handle<Script> script = Script::Compile(string);
script->Run();
Handle<Value> data_p = context->Global()->Get(String::New("p"));
Handle<Object> p = Handle<Object>::Cast(data_p);
Handle<Function> getName = Handle<Function>::Cast(p->Get(String::New("getName")));
Handle<Value> value = getName->Call(p, 0, NULL);
String::AsciiValue ascii(value);
printf("%s\n", *ascii);
return 0;
}
注意其中的
Handle<Function> getName = Handle<Function>::Cast(p->Get(String::New("getName")));
Handle<Value> value = getName->Call(p, 0, Null);