Search code examples
v8

Conversion of std::string to v8::string


How can I convert std::string to v8::string,when I am trying to pass an std::string to a script in the following way

script1 = Script::Compile(param1);

I am getting conversion error.


Solution

  • To convert a std::string to a v8::Local<v8::String>, you don't need to compile and run a script. Just do this:

    std::string sText = "whatever";
    v8::Local<v8::String> hTextJS = v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sText.c_str());