AutoJSAPI jsapi; JSContext* cx = jsapi.cx(); JS::RootedObject myObject(cx, JS_NewPlainObject(cx));
AutoJSAPI jsapi; JSContext* cx = jsapi.cx(); JS::RootedValue result(cx); JS_EvaluateScript(cx, JS::HandleStringLiteral("var a = 5; a + 10;"), JS::NullPtr(), JS::NullPtr(), 1, &result); if(result.isNumber()) { double num = result.toNumber(); // num should be 15 }In this example, we first create a new context using AutoJSAPI. We then use the JS_EvaluateScript function to evaluate a JavaScript expression, in this case "var a = 5; a + 10;", which should evaluate to 15. We store the result in a RootedValue variable and check if it is a number before doing further computation. It should be noted that AutoJSAPI is a part of the SpiderMonkey library, which is included in the Mozilla Firefox browser. Therefore, to use AutoJSAPI in your C++ application, you will need to link against the SpiderMonkey library.