| 133 | } |
| 134 | |
| 135 | bool eval(const std::string& code) override { |
| 136 | bool success = true; |
| 137 | try { |
| 138 | initGlobals(); |
| 139 | if (duk_peval_string(m_handle, code.c_str()) != 0) { |
| 140 | printLastResult(); |
| 141 | std::cout << "Error: [" << duk_safe_to_string(m_handle, -1) << "]" << std::endl; |
| 142 | success = false; |
| 143 | } |
| 144 | |
| 145 | if (m_printLastResult && |
| 146 | !duk_is_null_or_undefined(m_handle, -1)) { |
| 147 | m_delegate->onConsolePrint(duk_safe_to_string(m_handle, -1)); |
| 148 | } |
| 149 | |
| 150 | duk_pop(m_handle); |
| 151 | } catch (const std::exception& ex) { |
| 152 | std::string err = "Error: "; |
| 153 | err += ex.what(); |
| 154 | m_delegate->onConsolePrint(err.c_str()); |
| 155 | success = false; |
| 156 | std::cout << "Error: [" << err << "]" << std::endl; |
| 157 | } |
| 158 | execAfterEval(success); |
| 159 | return success; |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | static Engine::Regular<DukEngine> registration("duk", {"js"}); |
nothing calls this directly
no test coverage detected