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

Method evaluateExpression

choc/javascript/choc_javascript_V8.h:130–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 2

ErrorClass · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected