MCPcopy Create free account
hub / github.com/Tracktion/choc / run

Method run

choc/javascript/choc_javascript_V8.h:164–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162 }
163
164 void run (const std::string& code, Context::ReadModuleContentFn* resolveModule, Context::CompletionHandler handleResult) override
165 {
166 v8::Isolate::Scope isolateScope (isolate);
167 v8::HandleScope handleScope (isolate);
168 auto localContext = context.Get (isolate);
169 v8::Context::Scope contextScope (localContext);
170 v8::TryCatch tryCatch (isolate);
171
172 auto handleError = [&]
173 {
174 currentModuleResolver = nullptr;
175 auto exception = getExceptionMessage (tryCatch, localContext);
176
177 if (exception.empty())
178 exception = "Unknown error";
179
180 if (handleResult)
181 handleResult (exception, {});
182 };
183
184 auto source = stringToV8 (code);
185 v8::MaybeLocal<v8::Value> result;
186
187 if (resolveModule != nullptr)
188 {
189 currentModuleResolver = resolveModule;
190
191 auto mod = loadModule (localContext, source);
192
193 if (mod.IsEmpty())
194 return handleError();
195
196 result = mod.ToLocalChecked()->Evaluate (localContext);
197 }
198 else
199 {
200 auto script = v8::Script::Compile (localContext, source);
201
202 if (script.IsEmpty())
203 return handleError();
204
205 result = script.ToLocalChecked()->Run (localContext);
206 }
207
208 if (result.IsEmpty())
209 return handleError();
210
211 if (handleResult)
212 handleResult ({}, v8ToChoc (localContext, result.ToLocalChecked()));
213 }
214
215 void pushObjectOrArray (const choc::value::ValueView& v) override
216 {

Callers

nothing calls this directly

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected