This gave me a good head start. However, my program crashes at 
function->Call statement. 

Can you please tell me what values function_value, function_name and 
function are supposed to take.I have also populated argv with random values 
since I am not using them in my function. If that could also be a reason 
for the crash, please let me know.

This is my JS code :

Local<String> source =
*String::NewFromUtf8(isolate, "'function test_function() {var match = 0; 
return match+10;}'",*
* NewStringType::kNormal).ToLocalChecked();*

*Thanks,*
*Kavin*

On Friday, August 4, 2017 at 3:29:23 PM UTC-7, Jeremy Bettis wrote:
>
> What I do to call a function is to use 
>
> v8::Local<v8::Value> function_value;
> context->Global()->Get(context, function_name).ToLocal(&function_value);
> v8::Local<v8::Function> function = 
> v8::Local<v8::Function>::Cast(function_value);
> const int argc = arguments.size();
> std::vector<v8::Local<v8::Value>> argv(argc);
> // populate the argv somehow
> function->Call(context, context->Global(), argc, argv.data());
>
> On Fri, Aug 4, 2017 at 4:17 PM, Kavin Mani <kavin...@gmail.com 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I am new to V8 engine and starting to experiment things. I am wondering 
>> if it is possible to execute different functions from a Javascript file at 
>> different times.
>>
>> Consider the following scenario:
>>
>> I have a Javascript file with a global variable *foo *and two functions 
>> *func1() *and *func2().* Something like this:
>>
>> *Test.js:*
>>
>> var foo = 0;
>>
>> function func1() {
>>       foo = 100;
>> }
>>
>> function func2() {
>>       return foo + 10;
>> }
>>
>> In my *cpp* file, I want to first execute *func1() *from Test.js*, *print 
>> some random statements (need not be related to using *foo*) and then 
>> call *func2()*. Finally, I want to print the value of *foo *in my C++ 
>> program. Here is what I want to do - 
>>
>> *Test.cpp*
>>
>> Print some statements...
>>
>> Call func1()
>>
>> Print some more statements...
>>
>> Call func2()
>>
>> Print the value of foo
>>
>>
>> Almost all of the examples that I could find takes the Javascript program 
>> as a string and executes it completely. However, I want to execute them in 
>> parts at different times. Can someone please help me to find a way to do 
>> this?
>>
>> Thanks,
>> Kavin
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com <javascript:>
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-users+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Jeremy Bettis | Staff Software Engineer | jbe...@google.com <javascript:>
>  | 303-257-2486
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to