javascriptc++v8embedded-v8

Can I get the source text of JavaScript functions in C++ callback function using google v8?


I am embeding google v8 into my C++ program. I want to get the source code of Javascript functions passed as arguments into my C++ function. For example:

function ComputePixel(nir, red, blue) {
    return (nir-red)/(blue-red)
}
var layer = L8.function(ComputePixel, {
    ‘nir': L8.select('B5'),
    ‘red': L8.select('B4'),
    ‘blue': L8.select('B2’) })

Here "L8.function" is my C++ callback function. Is there any way I get can the complete source of ComputePixel in my C++ function?


Solution

  • You should be able to call ToString on it:

    v8::String::Utf8Value str(args[0]->ToString());