| 128 | } |
| 129 | |
| 130 | choc::value::Value evaluateExpression (const std::string& code) override |
| 131 | { |
| 132 | v8::Isolate::Scope isolateScope (isolate); |
| 133 | v8::HandleScope handleScope (isolate); |
| 134 | auto localContext = context.Get (isolate); |
| 135 | v8::Context::Scope contextScope (localContext); |
| 136 | v8::TryCatch tryCatch (isolate); |
| 137 | |
| 138 | auto handleError = [&] |
| 139 | { |
| 140 | auto exception = getExceptionMessage (tryCatch, localContext); |
| 141 | |
| 142 | if (exception.empty()) |
| 143 | exception = "Unknown error"; |
| 144 | |
| 145 | throw choc::javascript::Error (exception); |
| 146 | }; |
| 147 | |
| 148 | auto source = stringToV8 (code); |
| 149 | v8::MaybeLocal<v8::Value> result; |
| 150 | |
| 151 | auto script = v8::Script::Compile (localContext, source); |
| 152 | |
| 153 | if (script.IsEmpty()) |
| 154 | handleError(); |
| 155 | |
| 156 | result = script.ToLocalChecked()->Run (localContext); |
| 157 | |
| 158 | if (result.IsEmpty()) |
| 159 | handleError(); |
| 160 | |
| 161 | return v8ToChoc (localContext, result.ToLocalChecked()); |
| 162 | } |
| 163 | |
| 164 | void run (const std::string& code, Context::ReadModuleContentFn* resolveModule, Context::CompletionHandler handleResult) override |
| 165 | { |