/* Example of calling JavaScript (V8 engine) from ECL code via embedded C++ * * This example evalues a JS expression within an ECL transform * */ #option('linkOptions', '-lv8') // Embedded C++ that makes a evaluates the script passed to it string jseval(varstring script, varstring a, varstring b) := BEGINC++ // This section of the code should probably move to a plugin, or somesuch /* Include the JSAPI header file to get access to SpiderMonkey. */ #include "v8.h" #body using namespace v8; // extern void user1(size32_t & __lenResult,char * & __result, const char * script, const char *a, const char *b) { { Isolate* isolate = Isolate::New(); { v8::Isolate::Scope iscope(isolate); // Create a stack-allocated handle scope. HandleScope handle_scope; Persistent context = Context::New(); Context::Scope context_scope(context); // Bind the parameters into the context context->Global()->Set(String::New("a"), String::New(a)); context->Global()->Set(String::New("b"), String::New(b)); // Create a string containing the JavaScript source code. Handle source = String::New(script); // Compile the source code. Handle