| 76 | } |
| 77 | |
| 78 | void Plugin::Start() |
| 79 | { |
| 80 | if (!_hasLoaded) |
| 81 | { |
| 82 | throw std::runtime_error("Plugin has not been loaded."); |
| 83 | } |
| 84 | |
| 85 | const JSValue mainFunc = _metadata.Main.callback; |
| 86 | if (!JS_IsFunction(_context, mainFunc)) |
| 87 | { |
| 88 | throw std::runtime_error("No main function specified."); |
| 89 | } |
| 90 | |
| 91 | _hasStarted = true; |
| 92 | |
| 93 | const JSValue res = JS_Call(_context, mainFunc, JS_UNDEFINED, 0, nullptr); |
| 94 | if (JS_IsException(res)) |
| 95 | { |
| 96 | JSValue exceptionVal = JS_GetException(_context); |
| 97 | std::string details = Stringify(_context, exceptionVal); |
| 98 | JS_FreeValue(_context, exceptionVal); |
| 99 | JS_FreeValue(_context, res); |
| 100 | throw std::runtime_error("[" + _metadata.Name + "]\n" + details); |
| 101 | } |
| 102 | JS_FreeValue(_context, res); |
| 103 | } |
| 104 | |
| 105 | void Plugin::StopBegin() |
| 106 | { |
no outgoing calls
no test coverage detected