void RunIt(v8::Isolate *isolate, const char *script_text)
v8::HandleScope handle_scope(isolate);
std::cout << "/" << script_text << "/ <==" << std::endl;
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate,script_text);
v8::Local<v8::Script> script = v8::Script::Compile(source);
v8::Local<v8::Value> result = script->Run();
std::cout << "/" << script_text << "/ ==> " << *v8::String::Utf8Value(result) << std::endl;
void CallParenthesis(const v8::FunctionCallbackInfo<v8::Value>& args)
v8::EscapableHandleScope handle_scope(args.GetIsolate());
std::cout << "CALL PARENTHESIS runs (for " << *v8::String::Utf8Value(args.This()) << ")" << std::endl;
v8::Local<v8::Value> retval = v8::String::NewFromUtf8(args.GetIsolate(), "hello");
args.GetReturnValue().Set(handle_scope.Escape(retval));
int main(int argc, char* argv[])
v8::Isolate* isolate = v8::Isolate::New();
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
globalTemplate->SetCallAsFunctionHandler(CallParenthesis);
v8::Handle<v8::Context> context = v8::Context::New(isolate,NULL,globalTemplate);
v8::Context::Scope context_scope(context);
v8::Local<v8::ObjectTemplate> specificTemplate = v8::ObjectTemplate::New();
specificTemplate->SetCallAsFunctionHandler(CallParenthesis);
v8::Handle<v8::Object> specificObj = specificTemplate->NewInstance();
context->Global()->Set(v8::String::NewFromUtf8(isolate,"obj"), specificObj);
RunIt(isolate,"a = obj();");
RunIt(isolate,"window = this; b = window();");