Search code examples
javascriptc++v8

how to send string data into a javascript?


I am using v8 and i faced next problem - i have an application which running a javascript file ( i simply read it into a string and than execute with

Local<String> source = String::New(javascript); //javascript is string with js file
Local<Script> script = Script::Compile(source);
Local<Value> result = script->Run(); 

how can I send a string variable into this file?


Solution

  • Put a placeholder in the script source, like STRING_HERE. Then, before creating the source object, find that placeholder in the string and replace it with the string value you want.