Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace v8;
- int
- main (int argc, char *argv[])
- {
- //handle scope created
- HandleScope handle_scope;
- //creating context
- Persistent < Context > context = Context::New ();
- Context::Scope context_scope (context);
- // need source scrip and result
- Handle < String > source;
- Handle < Script > script;
- Handle < Value > result;
- // Create a string containing the JavaScript source code.
- source = String:: New(" var obj={name:8}; obj.abc=function(){return 9;}; function xyz() { var match = 0;if(arguments[0] == arguments[1]) { match = 1; } return match; } ");
- // Compile the source code.
- script = Script::Compile (source);
- // Run the script to get the result.
- result = script->Run ();
- // Dispose the persistent context.
- context.Dispose ();
- // create the global object
- Handle < v8::Object > global = context->Global ();
- Handle < v8::Value > value = global->Get (String::New ("xyz"));
- Handle < v8::Function > func = v8::Handle < v8::Function >::Cast (value);
- Handle < Value > js_result;
- Handle < Value > ret = func->Call (global, 0, 0);
- if (ret.IsEmpty ())
- {
- if(ret->IsNumber())
- {
- std::cout<<" \nis Number\n";
- }
- else
- {
- std::cout<<" \nNot a Number\n";
- }
- }
- else
- std::cout<< " is null\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement