| 205 | } |
| 206 | |
| 207 | jsi::Value V8Runtime::ExecuteScript( |
| 208 | v8::Isolate *isolate, |
| 209 | const v8::Local<v8::String> &script, |
| 210 | const std::string &sourceURL) { |
| 211 | v8::HandleScope scopedHandle(isolate); |
| 212 | v8::TryCatch tryCatch(isolate); |
| 213 | |
| 214 | v8::MaybeLocal<v8::String> sourceURLValue = v8::String::NewFromUtf8( |
| 215 | isolate, |
| 216 | sourceURL.c_str(), |
| 217 | v8::NewStringType::kNormal, |
| 218 | static_cast<int>(sourceURL.length())); |
| 219 | v8::ScriptOrigin origin(isolate, sourceURLValue.ToLocalChecked()); |
| 220 | |
| 221 | v8::Local<v8::Context> context(isolate->GetCurrentContext()); |
| 222 | |
| 223 | auto codecache = LoadCodeCacheIfNeeded(sourceURL); |
| 224 | v8::ScriptCompiler::CachedData *cachedData = codecache.release(); |
| 225 | |
| 226 | std::unique_ptr<v8::ScriptCompiler::Source> source = |
| 227 | UseFakeSourceIfNeeded(origin, cachedData); |
| 228 | if (!source) { |
| 229 | source = std::make_unique<v8::ScriptCompiler::Source>( |
| 230 | script, origin, cachedData); |
| 231 | } |
| 232 | |
| 233 | v8::Local<v8::Script> compiledScript; |
| 234 | if (!v8::ScriptCompiler::Compile( |
| 235 | context, |
| 236 | source.release(), |
| 237 | cachedData ? v8::ScriptCompiler::kConsumeCodeCache |
| 238 | : v8::ScriptCompiler::kNoCompileOptions) |
| 239 | .ToLocal(&compiledScript)) { |
| 240 | ReportException(isolate, &tryCatch); |
| 241 | return {}; |
| 242 | } |
| 243 | |
| 244 | if (cachedData && cachedData->rejected) { |
| 245 | LOG(INFO) << "[rnv8] cache miss: " << sourceURL; |
| 246 | } |
| 247 | SaveCodeCacheIfNeeded(compiledScript, sourceURL, cachedData); |
| 248 | |
| 249 | v8::Local<v8::Value> result; |
| 250 | if (!compiledScript->Run(context).ToLocal(&result)) { |
| 251 | assert(tryCatch.HasCaught()); |
| 252 | ReportException(isolate, &tryCatch); |
| 253 | return {}; |
| 254 | } |
| 255 | |
| 256 | return JSIV8ValueConverter::ToJSIValue(isolate, result); |
| 257 | } |
| 258 | |
| 259 | void V8Runtime::ReportException(v8::Isolate *isolate, v8::TryCatch *tryCatch) |
| 260 | const { |
nothing calls this directly
no outgoing calls
no test coverage detected