Lines Matching defs:isolate

344 static MaybeLocal<Value> TryGetValue(v8::Isolate* isolate,
348 MaybeLocal<String> v8_str = String::NewFromUtf8(isolate, property);
353 static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context,
355 return TryGetValue(isolate, context, object, property).ToLocalChecked();
358 std::shared_ptr<Worker> GetWorkerFromInternalField(Isolate* isolate,
361 isolate->ThrowError("this is not a Worker");
367 isolate->ThrowError("Worker is defunct because main thread is terminating");
392 static void FillTraceConfig(v8::Isolate* isolate,
395 HandleScope outer_scope(isolate);
396 Local<Context> context = Context::New(isolate);
398 HandleScope inner_scope(isolate);
401 String::NewFromUtf8(isolate, json_str).ToLocalChecked();
405 UpdateIncludedCategoriesList(isolate, context, trace_config_object,
411 v8::Isolate* isolate, Local<Context> context, Local<v8::Object> object,
414 GetValue(isolate, context, object, kIncludedCategoriesParam);
422 String::Utf8Value str(isolate, v->ToString(context).ToLocalChecked());
434 v8::Isolate* isolate, const char* json_str) {
437 TraceConfigParser::FillTraceConfig(isolate, trace_config, json_str);
488 ScriptCompiler::CachedData* Shell::LookupCodeCache(Isolate* isolate,
492 v8::String::Utf8Value key(isolate, source);
506 void Shell::StoreInCodeCache(Isolate* isolate, Local<Value> source,
511 v8::String::Utf8Value key(isolate, source);
548 StreamingCompileTask(Isolate* isolate,
551 : isolate_(isolate),
553 isolate, streamed_source, type)) {
567 explicit FinishTask(Isolate* isolate) : isolate_(isolate) {}
622 MaybeLocal<T> Shell::CompileString(Isolate* isolate, Local<Context> context,
630 isolate, &streamed_source,
634 Shell::CompleteMessageLoop(isolate);
640 cached_code = LookupCodeCache(isolate, source);
656 ScriptOrigin CreateScriptOrigin(Isolate* isolate, Local<String> resource_name,
659 PrimitiveArray::New(isolate, kHostDefinedOptionsLength);
660 options->Set(isolate, 0,
661 v8::Uint32::New(isolate, kHostDefinedOptionsMagicConstant));
662 options->Set(isolate, 1, resource_name);
663 return ScriptOrigin(isolate, resource_name, 0, 0, false, -1, Local<Value>(),
682 bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
686 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
720 HandleScope handle_scope(isolate);
721 TryCatch try_catch(isolate);
736 PerIsolateData* data = PerIsolateData::Get(isolate);
738 Local<Context>::New(isolate, data->realms_[data->realm_current_]);
740 Local<Context> context(isolate->GetCurrentContext());
742 CreateScriptOrigin(isolate, name, ScriptType::kClassic);
745 HandleScope handle_scope_for_compiling(isolate);
746 if (CompileString<Script>(isolate, context, source, origin).IsEmpty()) {
751 if (!CompileString<Script>(isolate, context, source, origin)
761 StoreInCodeCache(isolate, source, cached_data);
779 StoreInCodeCache(isolate, source, cached_data);
783 if (!EmptyMessageQueues(isolate)) success = false;
784 if (!HandleUnhandledPromiseRejections(isolate)) success = false;
795 ReadLines(isolate, options.web_snapshot_config);
798 isolate->ThrowError("Web snapshots: unable to read config");
800 ReportException(isolate, &try_catch);
804 i::WebSnapshotSerializer serializer(isolate);
815 isolate->ThrowError(
832 v8::String::Utf8Value str(isolate, result);
837 v8::String::Utf8Value str(isolate, Stringify(isolate, result));
847 std::string ToSTLString(Isolate* isolate, Local<String> v8_str) {
848 String::Utf8Value utf8(isolate, v8_str);
928 explicit ModuleGlobalHash(Isolate* isolate) : isolate_(isolate) {}
938 explicit ModuleEmbedderData(Isolate* isolate)
939 : module_to_specifier_map(10, ModuleGlobalHash(isolate)),
940 json_module_to_parsed_json_map(10, ModuleGlobalHash(isolate)) {}
945 Isolate* isolate = context->GetIsolate();
951 std::string assertion_key = ToSTLString(isolate, v8_assertion_key);
956 std::string assertion_value = ToSTLString(isolate, v8_assertion_value);
1002 Isolate* isolate = context->GetIsolate();
1005 d->module_to_specifier_map.find(Global<Module>(isolate, referrer));
1007 std::string absolute_path = NormalizePath(ToSTLString(isolate, specifier),
1014 return module_it->second.Get(isolate);
1024 Isolate* isolate = context->GetIsolate();
1025 MaybeLocal<String> source_text = ReadFile(isolate, file_name.c_str(), false);
1028 source_text = ReadFile(isolate, fallback_file_name.c_str(), false);
1031 source_text = ReadFile(isolate, fallback_file_name.c_str());
1040 d->module_to_specifier_map.find(Global<Module>(isolate, referrer));
1044 isolate->ThrowError(
1045 v8::String::NewFromUtf8(isolate, msg.c_str()).ToLocalChecked());
1050 String::NewFromUtf8(isolate, file_name.c_str()).ToLocalChecked();
1052 CreateScriptOrigin(isolate, resource_name, ScriptType::kModule);
1057 if (!CompileString<Module>(isolate, context, source_text.ToLocalChecked(),
1070 String::NewFromUtf8(isolate, "default").ToLocalChecked()};
1073 isolate,
1074 String::NewFromUtf8(isolate, file_name.c_str()).ToLocalChecked(),
1078 .insert(std::make_pair(Global<Module>(isolate, module),
1079 Global<Value>(isolate, parsed_json)))
1087 Global<Module>(isolate, module)))
1090 .insert(std::make_pair(Global<Module>(isolate, module), file_name))
1101 NormalizePath(ToSTLString(isolate, name), dir_name);
1108 isolate->ThrowError("Invalid module type was asserted");
1128 Isolate* isolate = context->GetIsolate();
1132 d->json_module_to_parsed_json_map.find(Global<Module>(isolate, module));
1134 Local<Value> json_value = json_value_it->second.Get(isolate);
1136 TryCatch try_catch(isolate);
1138 isolate,
1139 String::NewFromUtf8Literal(isolate, "default",
1149 resolver->Resolve(context, Undefined(isolate)).ToChecked();
1158 : isolate(isolate_) {
1159 referrer.Reset(isolate, referrer_);
1160 specifier.Reset(isolate, specifier_);
1161 import_assertions.Reset(isolate, import_assertions_);
1162 resolver.Reset(isolate, resolver_);
1165 Isolate* isolate;
1176 : isolate(isolate_) {
1177 module_namespace.Reset(isolate, module_namespace_);
1178 resolver.Reset(isolate, resolver_);
1181 Isolate* isolate;
1193 Isolate* isolate(module_resolution_data->isolate);
1194 HandleScope handle_scope(isolate);
1197 module_resolution_data->resolver.Get(isolate));
1199 module_resolution_data->module_namespace.Get(isolate));
1201 PerIsolateData* data = PerIsolateData::Get(isolate);
1202 Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
1213 Isolate* isolate(module_resolution_data->isolate);
1214 HandleScope handle_scope(isolate);
1217 module_resolution_data->resolver.Get(isolate));
1219 PerIsolateData* data = PerIsolateData::Get(isolate);
1220 Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
1231 Isolate* isolate = context->GetIsolate();
1242 isolate, "Invalid host defined options")))
1246 new DynamicImportData(isolate, resource_name.As<String>(), specifier,
1248 PerIsolateData::Get(isolate)->AddDynamicImportData(data);
1249 isolate->EnqueueMicrotask(Shell::DoHostImportModuleDynamically, data);
1257 Isolate* isolate = context->GetIsolate();
1258 HandleScope handle_scope(isolate);
1262 d->module_to_specifier_map.find(Global<Module>(isolate, module));
1266 String::NewFromUtf8Literal(isolate, "url", NewStringType::kInternalized);
1267 Local<String> url = String::NewFromUtf8(isolate, specifier_it->second.c_str())
1281 Isolate* isolate(import_data_->isolate);
1282 HandleScope handle_scope(isolate);
1284 Local<String> referrer(import_data_->referrer.Get(isolate));
1285 Local<String> specifier(import_data_->specifier.Get(isolate));
1287 import_data_->import_assertions.Get(isolate));
1288 Local<Promise::Resolver> resolver(import_data_->resolver.Get(isolate));
1290 PerIsolateData* data = PerIsolateData::Get(isolate);
1291 PerIsolateData::Get(isolate)->DeleteDynamicImportData(import_data_);
1293 Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
1299 TryCatch try_catch(isolate);
1303 isolate->ThrowError("Invalid module type was asserted");
1309 std::string source_url = ToSTLString(isolate, referrer);
1312 std::string file_name = ToSTLString(isolate, specifier);
1320 root_module = module_it->second.Get(isolate);
1334 EmptyMessageQueues(isolate);
1350 new ModuleResolutionData(isolate, module_namespace, resolver);
1351 Local<v8::External> edata = External::New(isolate, module_resolution_data);
1362 bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
1363 HandleScope handle_scope(isolate);
1365 PerIsolateData* data = PerIsolateData::Get(isolate);
1366 Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
1374 // isolate->ReportPendingMessages().
1375 TryCatch try_catch(isolate);
1382 root_module = module_it->second.Get(isolate);
1387 ReportException(isolate, &try_catch);
1396 EmptyMessageQueues(isolate);
1401 ReportException(isolate, &try_catch);
1408 Shell::CompleteMessageLoop(isolate);
1417 isolate->ThrowException(result_promise->Result());
1421 ReportException(isolate, &try_catch);
1429 bool Shell::ExecuteWebSnapshot(Isolate* isolate, const char* file_name) {
1430 HandleScope handle_scope(isolate);
1432 PerIsolateData* data = PerIsolateData::Get(isolate);
1433 Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
1435 TryCatch try_catch(isolate);
1444 isolate->ThrowError("Could not read the web snapshot file");
1448 i::WebSnapshotDeserializer deserializer(isolate, snapshot_data.get(),
1455 ReportException(isolate, &try_catch);
1461 bool Shell::LoadJSON(Isolate* isolate, const char* file_name) {
1462 HandleScope handle_scope(isolate);
1463 PerIsolateData* isolate_data = PerIsolateData::Get(isolate);
1465 isolate_data->realms_[isolate_data->realm_current_].Get(isolate);
1467 TryCatch try_catch(isolate);
1481 String::NewFromUtf8(isolate, line.c_str()).ToLocalChecked();
1487 ReportException(isolate, &try_catch);
1495 PerIsolateData::PerIsolateData(Isolate* isolate)
1496 : isolate_(isolate), realms_(nullptr) {
1497 isolate->SetData(0, this);
1499 async_hooks_wrapper_ = new AsyncHooks(isolate);
1504 HandleScope scope(isolate);
1505 Shell::CreateSnapshotTemplate(isolate);
1511 delete async_hooks_wrapper_; // This uses the isolate
1689 v8::Isolate* isolate = args.GetIsolate();
1690 Local<Context> context = isolate->GetCurrentContext();
1693 Local<Value> value = TryGetValue(isolate, context, object, "detailed")
1699 if (value->IsBoolean() && value->BooleanValue(isolate)) {
1706 v8::MeasureMemoryDelegate::Default(isolate, context, promise_resolver,
1714 Isolate* isolate = args.GetIsolate();
1715 PerIsolateData* data = PerIsolateData::Get(isolate);
1716 int index = data->RealmFind(isolate->GetEnteredOrMicrotaskContext());
1723 Isolate* isolate = args.GetIsolate();
1724 PerIsolateData* data = PerIsolateData::Get(isolate);
1730 args[0]->ToObject(isolate->GetCurrentContext()).ToLocalChecked();
1774 Isolate* isolate = args.GetIsolate();
1775 TryCatch try_catch(isolate);
1776 PerIsolateData* data = PerIsolateData::Get(isolate);
1783 realm.Reset(isolate, old_realms[i]);
1791 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
1793 Context::New(isolate, nullptr, global_template, global_object);
1797 data->realms_[index].Reset(isolate, context);
1805 Isolate* isolate = args.GetIsolate();
1806 PerIsolateData* data = PerIsolateData::Get(isolate);
1807 Local<Context> context = data->realms_[index].Get(isolate);
1812 isolate->ContextDisposedNotification();
1813 isolate->IdleNotificationDeadline(g_platform->MonotonicallyIncreasingTime());
1836 Isolate* isolate = args.GetIsolate();
1837 PerIsolateData* data = PerIsolateData::Get(isolate);
1846 Local<Context> context = Local<Context>::New(isolate, data->realms_[index]);
1852 HandleScope scope(isolate);
1865 Isolate* isolate = args.GetIsolate();
1866 PerIsolateData* data = PerIsolateData::Get(isolate);
1875 HandleScope scope(isolate);
1876 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
1882 Isolate* isolate = args.GetIsolate();
1883 PerIsolateData* data = PerIsolateData::Get(isolate);
1896 Isolate* isolate = args.GetIsolate();
1897 PerIsolateData* data = PerIsolateData::Get(isolate);
1905 Isolate* isolate = args.GetIsolate();
1906 PerIsolateData* data = PerIsolateData::Get(isolate);
1910 isolate->ThrowError("Invalid argument");
1916 isolate->ThrowError("Invalid argument");
1920 CreateScriptOrigin(isolate, String::NewFromUtf8Literal(isolate, "(d8)"),
1925 if (!ScriptCompiler::CompileUnboundScript(isolate, &script_source)
1944 Isolate* isolate = info.GetIsolate();
1945 PerIsolateData* data = PerIsolateData::Get(isolate);
1952 Isolate* isolate = info.GetIsolate();
1953 PerIsolateData* data = PerIsolateData::Get(isolate);
1954 data->realm_shared_.Reset(isolate, value);
1961 Isolate* isolate = args.GetIsolate();
1963 isolate->ThrowError("Invalid argument");
1966 PerIsolateData* data = PerIsolateData::Get(isolate);
1970 Local<Context> current_context = isolate->GetCurrentContext();
1973 Local<PrimitiveArray> exports = PrimitiveArray::New(isolate, length);
1979 isolate->ThrowError("Invalid argument");
1982 exports->Set(isolate, i, str);
1987 TryCatch try_catch(isolate);
1990 i::WebSnapshotSerializer serializer(isolate);
1994 args.GetReturnValue().Set(Undefined(isolate));
2001 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2009 snapshot_template->NewInstance(isolate->GetCurrentContext())
2019 Isolate* isolate = args.GetIsolate();
2021 isolate->ThrowError("Invalid argument");
2024 PerIsolateData* data = PerIsolateData::Get(isolate);
2031 isolate->ThrowError("Invalid argument");
2043 i::WebSnapshotDeserializer deserializer(isolate,
2052 Isolate* isolate = args.GetIsolate();
2053 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2054 HandleScope handle_scope(isolate);
2058 isolate->ThrowError("Only capturing from temporary files is supported.");
2062 isolate->ThrowError("Logging not enabled.");
2069 isolate->ThrowError("Log file does not exist.");
2078 isolate->ThrowError("Unable to read log file.");
2082 String::NewFromUtf8(isolate, raw_log.c_str(), NewStringType::kNormal,
2091 Isolate* isolate = args.GetIsolate();
2094 isolate->ThrowError("Expected function as single argument.");
2101 isolate->ThrowError("Expected function as single argument.");
2105 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2106 HandleScope handle_scope(isolate);
2117 isolate->ThrowError("Expected function as bound target.");
2127 isolate->ThrowError("Function has no BytecodeArray attached.");
2153 isolate->ThrowError("Baseline bytecode offset mismatch.");
2165 isolate->ThrowError(
2174 isolate->ThrowError("Missing bytecode(s) in baseline offset mapping.");
2181 isolate->ThrowError("Excess offsets in baseline offset mapping.");
2188 Isolate* isolate = args.GetIsolate();
2189 isolate->InstallConditionalFeatures(isolate->GetCurrentContext());
2205 Isolate* isolate = args.GetIsolate();
2206 HandleScope handle_scope(isolate);
2208 isolate,
2209 PerIsolateData::Get(isolate)->GetAsyncHooks()->GetExecutionAsyncId()));
2214 Isolate* isolate = args.GetIsolate();
2215 HandleScope handle_scope(isolate);
2217 isolate,
2218 PerIsolateData::Get(isolate)->GetAsyncHooks()->GetTriggerAsyncId()));
2232 Isolate* isolate = args.GetIsolate();
2238 isolate->ThrowError(
2244 Local<Context> context = isolate->GetCurrentContext();
2245 HandleScope handle_scope(isolate);
2253 args.GetReturnValue().Set(v8::Undefined(isolate));
2255 isolate->ThrowError(
2328 Local<String> Shell::ReadFromStdin(Isolate* isolate) {
2331 Local<String> accumulator = String::NewFromUtf8Literal(isolate, "");
2345 isolate, accumulator,
2346 String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
2351 String::Concat(isolate, accumulator,
2352 String::NewFromUtf8(isolate, buffer,
2357 isolate, accumulator,
2358 String::NewFromUtf8(isolate, buffer, NewStringType::kNormal,
2366 Isolate* isolate = args.GetIsolate();
2368 HandleScope handle_scope(isolate);
2369 String::Utf8Value file_name(isolate, args[i]);
2373 isolate->ThrowError(
2374 String::NewFromUtf8(isolate, oss.str().c_str()).ToLocalChecked());
2378 if (!ReadFile(isolate, *file_name).ToLocal(&source)) return;
2381 String::NewFromUtf8(isolate, *file_name).ToLocalChecked(),
2387 isolate->ThrowError(
2388 String::NewFromUtf8(isolate, oss.str().c_str()).ToLocalChecked());
2395 Isolate* isolate = args.GetIsolate();
2396 args.GetReturnValue().Set(v8::Number::New(isolate, 0));
2399 Local<Context> context = isolate->GetCurrentContext();
2400 PerIsolateData::Get(isolate)->SetTimeout(callback, context);
2406 Isolate* isolate = args.GetIsolate();
2409 Local<Context> context = isolate->GetCurrentContext();
2411 if (!TryGetValue(isolate, context, object, "type").ToLocal(&value)) {
2421 String::Utf8Value str(isolate, worker_type_string);
2433 TryGetValue(isolate, context, object, "arguments").ToLocal(arguments);
2444 Isolate* isolate) {
2445 Local<Context> context = isolate->GetCurrentContext();
2450 isolate->ThrowError("Failed to convert function to string");
2453 *source = String::NewFromUtf8Literal(isolate, "(");
2454 *source = String::Concat(isolate, *source, function_string);
2455 Local<String> middle = String::NewFromUtf8Literal(isolate, ")(");
2456 *source = String::Concat(isolate, *source, middle);
2459 isolate->ThrowError("'arguments' must be an array");
2462 Local<String> comma = String::NewFromUtf8Literal(isolate, ",");
2466 *source = String::Concat(isolate, *source, comma);
2471 isolate->ThrowError("Failed to get argument");
2476 isolate->ThrowError("Failed to convert argument to string");
2479 *source = String::Concat(isolate, *source, argument_string);
2482 Local<String> suffix = String::NewFromUtf8Literal(isolate, ")");
2483 *source = String::Concat(isolate, *source, suffix);
2497 Isolate* isolate = args.GetIsolate();
2509 &source, isolate)) {
2517 String::Utf8Value filename(isolate, args[index]);
2518 if (!Shell::ReadFile(isolate, *filename).ToLocal(&source)) {
2537 Isolate* isolate = args.GetIsolate();
2538 HandleScope handle_scope(isolate);
2540 isolate->ThrowError("1st argument must be a string or a function");
2546 isolate->ThrowError("Invalid argument");
2551 isolate->ThrowError("Worker must be constructed with new");
2558 args.Holder()->SetInternalField(0, v8::Integer::New(isolate, 0));
2566 String::Utf8Value script(isolate, source);
2568 isolate->ThrowError("Can't get worker script");
2576 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2582 isolate->ThrowError("Can't start thread");
2589 Isolate* isolate = args.GetIsolate();
2590 HandleScope handle_scope(isolate);
2593 isolate->ThrowError("Invalid argument");
2598 GetWorkerFromInternalField(isolate, args.Holder());
2605 args.Length() >= 2 ? args[1] : Undefined(isolate).As<Value>();
2607 Shell::SerializeValue(isolate, message, transfer);
2614 Isolate* isolate = args.GetIsolate();
2615 HandleScope handle_scope(isolate);
2617 GetWorkerFromInternalField(isolate, args.Holder());
2625 if (Shell::DeserializeValue(isolate, std::move(data)).ToLocal(&value)) {
2632 Isolate* isolate = args.GetIsolate();
2633 HandleScope handle_scope(isolate);
2635 GetWorkerFromInternalField(isolate, args.Holder());
2642 Isolate* isolate = args.GetIsolate();
2643 HandleScope handle_scope(isolate);
2645 GetWorkerFromInternalField(isolate, args.Holder());
2657 Isolate* isolate = args->GetIsolate();
2658 isolate->Exit();
2663 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2668 OnExit(isolate, false);
2742 void Shell::ReportException(Isolate* isolate, Local<v8::Message> message,
2746 CHECK(!reinterpret_cast<i::Isolate*>(isolate)->has_pending_exception());
2747 HandleScope handle_scope(isolate);
2748 Local<Context> context = isolate->GetCurrentContext();
2751 context = Local<Context>::New(isolate, evaluation_context_);
2759 v8::String::Utf8Value exception(isolate, exception_obj);
2773 v8::String::Utf8Value filename(isolate,
2781 v8::String::Utf8Value sourcelinevalue(isolate, sourceline);
2800 v8::String::Utf8Value stack_trace(isolate, stack_trace_string.As<String>());
2807 void Shell::ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
2808 ReportException(isolate, try_catch->Message(), try_catch->Exception());
2835 void Shell::MapCounters(v8::Isolate* isolate, const char* name) {
2845 isolate->SetCounterFunction(LookupCounter);
2846 isolate->SetCreateHistogramFunction(CreateHistogram);
2847 isolate->SetAddHistogramSampleFunction(AddHistogramSample);
2896 Local<String> Shell::Stringify(Isolate* isolate, Local<Value> value) {
2898 v8::Local<v8::Context>::New(isolate, evaluation_context_);
2901 String::NewFromUtf8(isolate, stringify_source_).ToLocalChecked();
2902 Local<String> name = String::NewFromUtf8Literal(isolate, "d8-stringify");
2903 ScriptOrigin origin(isolate, name);
2907 isolate, script->Run(context).ToLocalChecked().As<Function>());
2909 Local<Function> fun = Local<Function>::New(isolate, stringify_function_);
2911 v8::TryCatch try_catch(isolate);
2912 MaybeLocal<Value> result = fun->Call(context, Undefined(isolate), 1, argv);
2913 if (result.IsEmpty()) return String::Empty(isolate);
2918 v8::Isolate* isolate = args.GetIsolate();
2919 args.GetReturnValue().Set(v8::Number::New(isolate, 1));
2922 Local<FunctionTemplate> Shell::CreateNodeTemplates(Isolate* isolate) {
2923 Local<FunctionTemplate> node = FunctionTemplate::New(isolate);
2925 Local<Signature> signature = v8::Signature::New(isolate, node);
2927 isolate, NodeTypeCallback, Local<Value>(), signature);
2930 String::NewFromUtf8Literal(isolate, "nodeType"), nodeType);
2932 Local<FunctionTemplate> element = FunctionTemplate::New(isolate);
2935 Local<FunctionTemplate> html_element = FunctionTemplate::New(isolate);
2938 Local<FunctionTemplate> div_element = FunctionTemplate::New(isolate);
2944 Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
2945 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
2946 global_template->Set(Symbol::GetToStringTag(isolate),
2947 String::NewFromUtf8Literal(isolate, "global"));
2948 global_template->Set(isolate, "version",
2949 FunctionTemplate::New(isolate, Version));
2951 global_template->Set(isolate, "print", FunctionTemplate::New(isolate, Print));
2952 global_template->Set(isolate, "printErr",
2953 FunctionTemplate::New(isolate, PrintErr));
2954 global_template->Set(isolate, "write",
2955 FunctionTemplate::New(isolate, WriteStdout));
2956 global_template->Set(isolate, "read",
2957 FunctionTemplate::New(isolate, ReadFile));
2958 global_template->Set(isolate, "readbuffer",
2959 FunctionTemplate::New(isolate, ReadBuffer));
2960 global_template->Set(isolate, "readline",
2961 FunctionTemplate::New(isolate, ReadLine));
2962 global_template->Set(isolate, "load",
2963 FunctionTemplate::New(isolate, ExecuteFile));
2964 global_template->Set(isolate, "setTimeout",
2965 FunctionTemplate::New(isolate, SetTimeout));
2970 global_template->Set(isolate, "quit", FunctionTemplate::New(isolate, Quit));
2972 global_template->Set(isolate, "testRunner",
2973 Shell::CreateTestRunnerTemplate(isolate));
2974 global_template->Set(isolate, "Realm", Shell::CreateRealmTemplate(isolate));
2975 global_template->Set(isolate, "performance",
2976 Shell::CreatePerformanceTemplate(isolate));
2977 global_template->Set(isolate, "Worker", Shell::CreateWorkerTemplate(isolate));
2981 global_template->Set(isolate, "os", Shell::CreateOSTemplate(isolate));
2983 global_template->Set(isolate, "d8", Shell::CreateD8Template(isolate));
2987 String::NewFromUtf8(isolate, "fuzzilli", NewStringType::kNormal)
2989 FunctionTemplate::New(isolate, Fuzzilli), PropertyAttribute::DontEnum);
2993 global_template->Set(isolate, "async_hooks",
2994 Shell::CreateAsyncHookTemplate(isolate));
3000 Local<ObjectTemplate> Shell::CreateOSTemplate(Isolate* isolate) {
3001 Local<ObjectTemplate> os_template = ObjectTemplate::New(isolate);
3002 AddOSMethods(isolate, os_template);
3003 os_template->Set(isolate, "name",
3004 v8::String::NewFromUtf8Literal(isolate, V8_TARGET_OS_STRING),
3007 isolate, "d8Path",
3008 v8::String::NewFromUtf8(isolate, options.d8_path).ToLocalChecked(),
3013 Local<FunctionTemplate> Shell::CreateWorkerTemplate(Isolate* isolate) {
3015 FunctionTemplate::New(isolate, WorkerNew);
3017 Signature::New(isolate, worker_fun_template);
3019 String::NewFromUtf8Literal(isolate, "Worker"));
3022 isolate, "terminate",
3023 FunctionTemplate::New(isolate, WorkerTerminate, Local<Value>(),
3026 isolate, "terminateAndWait",
3027 FunctionTemplate::New(isolate, WorkerTerminateAndWait, Local<Value>(),
3030 isolate, "postMessage",
3031 FunctionTemplate::New(isolate, WorkerPostMessage, Local<Value>(),
3034 isolate, "getMessage",
3035 FunctionTemplate::New(isolate, WorkerGetMessage, Local<Value>(),
3041 Local<ObjectTemplate> Shell::CreateAsyncHookTemplate(Isolate* isolate) {
3042 Local<ObjectTemplate> async_hooks_templ = ObjectTemplate::New(isolate);
3043 async_hooks_templ->Set(isolate, "createHook",
3044 FunctionTemplate::New(isolate, AsyncHooksCreateHook));
3046 isolate, "executionAsyncId",
3047 FunctionTemplate::New(isolate, AsyncHooksExecutionAsyncId));
3049 isolate, "triggerAsyncId",
3050 FunctionTemplate::New(isolate, AsyncHooksTriggerAsyncId));
3054 Local<ObjectTemplate> Shell::CreateTestRunnerTemplate(Isolate* isolate) {
3055 Local<ObjectTemplate> test_template = ObjectTemplate::New(isolate);
3056 test_template->Set(isolate, "notifyDone",
3057 FunctionTemplate::New(isolate, NotifyDone));
3058 test_template->Set(isolate, "waitUntilDone",
3059 FunctionTemplate::New(isolate, WaitUntilDone));
3063 test_template->Set(isolate, "quit", FunctionTemplate::New(isolate, Quit));
3068 Local<ObjectTemplate> Shell::CreatePerformanceTemplate(Isolate* isolate) {
3069 Local<ObjectTemplate> performance_template = ObjectTemplate::New(isolate);
3070 performance_template->Set(isolate, "now",
3071 FunctionTemplate::New(isolate, PerformanceNow));
3073 isolate, "measureMemory",
3074 FunctionTemplate::New(isolate, PerformanceMeasureMemory));
3078 Local<ObjectTemplate> Shell::CreateRealmTemplate(Isolate* isolate) {
3079 Local<ObjectTemplate> realm_template = ObjectTemplate::New(isolate);
3080 realm_template->Set(isolate, "current",
3081 FunctionTemplate::New(isolate, RealmCurrent));
3082 realm_template->Set(isolate, "owner",
3083 FunctionTemplate::New(isolate, RealmOwner));
3084 realm_template->Set(isolate, "global",
3085 FunctionTemplate::New(isolate, RealmGlobal));
3086 realm_template->Set(isolate, "create",
3087 FunctionTemplate::New(isolate, RealmCreate));
3089 isolate, "createAllowCrossRealmAccess",
3090 FunctionTemplate::New(isolate, RealmCreateAllowCrossRealmAccess));
3091 realm_template->Set(isolate, "navigate",
3092 FunctionTemplate::New(isolate, RealmNavigate));
3093 realm_template->Set(isolate, "detachGlobal",
3094 FunctionTemplate::New(isolate, RealmDetachGlobal));
3095 realm_template->Set(isolate, "dispose",
3096 FunctionTemplate::New(isolate, RealmDispose));
3097 realm_template->Set(isolate, "switch",
3098 FunctionTemplate::New(isolate, RealmSwitch));
3099 realm_template->Set(isolate, "eval",
3100 FunctionTemplate::New(isolate, RealmEval));
3101 realm_template->SetAccessor(String::NewFromUtf8Literal(isolate, "shared"),
3104 realm_template->Set(isolate, "takeWebSnapshot",
3105 FunctionTemplate::New(isolate, RealmTakeWebSnapshot));
3106 realm_template->Set(isolate, "useWebSnapshot",
3107 FunctionTemplate::New(isolate, RealmUseWebSnapshot));
3112 Local<FunctionTemplate> Shell::CreateSnapshotTemplate(Isolate* isolate) {
3113 Local<FunctionTemplate> snapshot_template = FunctionTemplate::New(isolate);
3115 PerIsolateData::Get(isolate)->SetSnapshotObjectCtor(snapshot_template);
3118 Local<ObjectTemplate> Shell::CreateD8Template(Isolate* isolate) {
3119 Local<ObjectTemplate> d8_template = ObjectTemplate::New(isolate);
3121 Local<ObjectTemplate> file_template = ObjectTemplate::New(isolate);
3122 file_template->Set(isolate, "read",
3123 FunctionTemplate::New(isolate, Shell::ReadFile));
3124 file_template->Set(isolate, "execute",
3125 FunctionTemplate::New(isolate, Shell::ExecuteFile));
3126 d8_template->Set(isolate, "file", file_template);
3129 Local<ObjectTemplate> log_template = ObjectTemplate::New(isolate);
3130 log_template->Set(isolate, "getAndStop",
3131 FunctionTemplate::New(isolate, LogGetAndStop));
3133 d8_template->Set(isolate, "log", log_template);
3136 Local<ObjectTemplate> dom_template = ObjectTemplate::New(isolate);
3137 dom_template->Set(isolate, "Div", Shell::CreateNodeTemplates(isolate));
3138 d8_template->Set(isolate, "dom", dom_template);
3141 Local<ObjectTemplate> test_template = ObjectTemplate::New(isolate);
3146 isolate, "verifySourcePositions",
3147 FunctionTemplate::New(isolate, TestVerifySourcePositions));
3154 test_template->Set(isolate, "FastCAPI",
3155 Shell::CreateTestFastCApiTemplate(isolate));
3156 test_template->Set(isolate, "LeafInterfaceType",
3157 Shell::CreateLeafInterfaceTypeTemplate(isolate));
3162 isolate, "installConditionalFeatures",
3163 FunctionTemplate::New(isolate, Shell::InstallConditionalFeatures));
3165 d8_template->Set(isolate, "test", test_template);
3168 Local<ObjectTemplate> promise_template = ObjectTemplate::New(isolate);
3170 isolate, "setHooks",
3171 FunctionTemplate::New(isolate, SetPromiseHooks, Local<Value>(),
3173 d8_template->Set(isolate, "promise", promise_template);
3176 Local<ObjectTemplate> debugger_template = ObjectTemplate::New(isolate);
3178 isolate, "enable",
3179 FunctionTemplate::New(isolate, EnableDebugger, Local<Value>(),
3182 isolate, "disable",
3183 FunctionTemplate::New(isolate, DisableDebugger, Local<Value>(),
3185 d8_template->Set(isolate, "debugger", debugger_template);
3212 Isolate* isolate = message->GetIsolate();
3213 v8::String::Utf8Value msg(isolate, message->Get());
3216 v8::String::Utf8Value filename(isolate,
3219 Maybe<int> maybeline = message->GetLineNumber(isolate->GetCurrentContext());
3232 v8::Isolate* isolate = promise->GetIsolate();
3233 PerIsolateData* isolate_data = PerIsolateData::Get(isolate);
3240 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
3243 isolate->SetCaptureStackTraceForUncaughtExceptions(true);
3248 message = v8::Exception::CreateMessage(isolate, exception);
3254 v8::String::NewFromUtf8Literal(isolate, "Unhandled Promise."));
3255 message = Exception::CreateMessage(isolate, exception);
3257 isolate->SetCaptureStackTraceForUncaughtExceptions(capture_exceptions);
3262 void Shell::Initialize(Isolate* isolate, D8Console* console,
3264 isolate->SetPromiseRejectCallback(PromiseRejectCallback);
3268 MapCounters(isolate, i::FLAG_map_counters);
3271 isolate->AddMessageListenerWithErrorLevel(
3278 isolate->SetHostImportModuleDynamicallyCallback(
3280 isolate->SetHostInitializeImportMetaObjectCallback(
3282 isolate->SetHostCreateShadowRealmContextCallback(
3290 ->GetCoverageBitmap(reinterpret_cast<i::Isolate*>(isolate))
3304 debug::SetConsoleDelegate(isolate, console);
3307 Local<String> Shell::WasmLoadSourceMapCallback(Isolate* isolate,
3309 return Shell::ReadFile(isolate, path, false).ToLocalChecked();
3312 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
3316 Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
3317 EscapableHandleScope handle_scope(isolate);
3318 Local<Context> context = Context::New(isolate, nullptr, global_template);
3319 DCHECK_IMPLIES(context.IsEmpty(), isolate->IsExecutionTerminating());
3322 isolate->SetWasmLoadSourceMapCallback(Shell::WasmLoadSourceMapCallback);
3329 Local<Array> array = Array::New(isolate, size);
3332 v8::String::NewFromUtf8(isolate, args[i]).ToLocalChecked();
3333 Local<Number> index = v8::Number::New(isolate, i);
3337 isolate, "arguments", NewStringType::kInternalized);
3343 isolate, "console", NewStringType::kInternalized);
3352 void Shell::WriteIgnitionDispatchCountersFile(v8::Isolate* isolate) {
3353 HandleScope handle_scope(isolate);
3354 Local<Context> context = Context::New(isolate);
3358 reinterpret_cast<i::Isolate*>(isolate)
3364 isolate, JSON::Stringify(context, Utils::ToLocal(dispatch_counters))
3397 void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
3399 HandleScope handle_scope(isolate);
3400 debug::Coverage coverage = debug::Coverage::CollectPrecise(isolate);
3408 std::string file_name = ToSTLString(isolate, name);
3431 name_stream << ToSTLString(isolate, function_name);
3458 void Shell::OnExit(v8::Isolate* isolate, bool dispose) {
3459 isolate->Dispose();
3635 MaybeLocal<PrimitiveArray> Shell::ReadLines(Isolate* isolate,
3651 Local<PrimitiveArray> exports = PrimitiveArray::New(isolate, size);
3654 isolate, lines[i].c_str(), NewStringType::kNormal,
3660 exports->Set(isolate, i, str);
3668 Isolate* isolate = args.GetIsolate();
3669 String::Utf8Value filename(isolate, args[0]);
3672 isolate->ThrowError("Error loading file");
3678 isolate->ThrowError("Error reading file");
3681 Local<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, length);
3689 MaybeLocal<String> Shell::ReadFile(Isolate* isolate, const char* name,
3698 isolate->ThrowError(
3700 isolate, oss.str().substr(0, String::kMaxLength).c_str())
3711 return String::NewExternalOneByte(isolate, resource);
3713 return String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size);
3723 void Shell::RunShell(Isolate* isolate) {
3724 HandleScope outer_scope(isolate);
3726 v8::Local<v8::Context>::New(isolate, evaluation_context_);
3728 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
3729 Local<String> name = String::NewFromUtf8Literal(isolate, "(d8)");
3732 HandleScope inner_scope(isolate);
3734 Local<String> input = Shell::ReadFromStdin(isolate);
3736 ExecuteString(isolate, input, name, kPrintResult, kReportExceptions,
3871 Isolate* isolate = args.GetIsolate();
3872 v8::HandleScope handle_scope(isolate);
3873 Local<Context> context = isolate->GetCurrentContext();
3874 args.GetReturnValue().Set(Undefined(isolate));
3880 message->Write(isolate, buffer.get(), 0, length);
3883 v8::SealHandleScope seal_handle_scope(isolate);
3886 args.GetReturnValue().Set(True(isolate));
3913 bool SourceGroup::Execute(Isolate* isolate) {
3917 HandleScope handle_scope(isolate);
3919 String::NewFromUtf8(isolate, "fuzzcode.js", NewStringType::kNormal)
3936 String::NewFromUtf8(isolate, buffer, NewStringType::kNormal)
3940 if (!Shell::ExecuteString(isolate, source, file_name, Shell::kNoPrintResult,
3951 HandleScope handle_scope(isolate);
3952 Local<String> file_name = String::NewFromUtf8Literal(isolate, "unnamed");
3954 String::NewFromUtf8(isolate, argv_[i + 1]).ToLocalChecked();
3956 if (!Shell::ExecuteString(isolate, source, file_name,
3966 if (!Shell::ExecuteModule(isolate, arg)) {
3975 if (!Shell::ExecuteModule(isolate, arg)) {
3984 if (!Shell::ExecuteWebSnapshot(isolate, arg)) {
3993 if (!Shell::LoadJSON(isolate, arg)) {
4004 HandleScope handle_scope(isolate);
4006 String::NewFromUtf8(isolate, arg).ToLocalChecked();
4008 if (!Shell::ReadFile(isolate, arg).ToLocal(&source)) {
4014 if (!Shell::ExecuteString(isolate, source, file_name, Shell::kNoPrintResult,
4031 Isolate* isolate = Isolate::New(create_params);
4032 Shell::SetWaitUntilDone(isolate, false);
4033 D8Console console(isolate);
4034 Shell::Initialize(isolate, &console, false);
4039 reinterpret_cast<i::Isolate*>(isolate)->main_thread_local_isolate());
4043 Isolate::Scope iscope(isolate);
4044 PerIsolateData data(isolate);
4046 HandleScope scope(isolate);
4047 Local<Context> context = Shell::CreateEvaluationContext(isolate);
4052 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
4053 Execute(isolate);
4054 Shell::CompleteMessageLoop(isolate);
4058 Shell::CollectGarbage(isolate);
4063 isolate->Dispose();
4220 // holding the {worker_mutex_}, it's safe to access the isolate.
4355 Isolate* isolate = args.GetIsolate();
4356 HandleScope handle_scope(isolate);
4359 isolate->ThrowError("Invalid argument");
4364 Local<Value> transfer = Undefined(isolate);
4366 Shell::SerializeValue(isolate, message, transfer);
4445 } else if (strcmp(argv[i], "--logfile-per-isolate") == 0) {
4472 // isolate-independent.
4482 } else if (strcmp(argv[i], "--isolate") == 0) {
4679 if (strcmp(str, "--isolate") == 0) {
4701 V8::SetFlagsFromString("--no-logfile-per-isolate");
4707 int Shell::RunMain(Isolate* isolate, bool last_run) {
4713 SetWaitUntilDone(isolate, false);
4715 debug::Coverage::SelectMode(isolate, debug::CoverageMode::kBlockCount);
4717 HandleScope scope(isolate);
4718 Local<Context> context = CreateEvaluationContext(isolate);
4719 CreateSnapshotTemplate(isolate);
4723 evaluation_context_.Reset(isolate, context);
4728 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
4729 if (!options.isolate_sources[0].Execute(isolate)) success = false;
4730 if (!CompleteMessageLoop(isolate)) success = false;
4735 WriteLcovData(isolate, options.lcov_file);
4738 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
4749 CollectGarbage(isolate);
4753 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
4777 void Shell::CollectGarbage(Isolate* isolate) {
4780 isolate->ContextDisposedNotification();
4781 isolate->IdleNotificationDeadline(
4788 isolate->LowMemoryNotification();
4792 void Shell::SetWaitUntilDone(Isolate* isolate, bool value) {
4794 isolate_status_[isolate] = value;
4797 void Shell::NotifyStartStreamingTask(Isolate* isolate) {
4800 ++isolate_running_streaming_tasks_[isolate];
4803 void Shell::NotifyFinishStreamingTask(Isolate* isolate) {
4806 --isolate_running_streaming_tasks_[isolate];
4807 DCHECK_GE(isolate_running_streaming_tasks_[isolate], 0);
4811 bool RunSetTimeoutCallback(Isolate* isolate, bool* did_run) {
4812 PerIsolateData* data = PerIsolateData::Get(isolate);
4813 HandleScope handle_scope(isolate);
4818 TryCatch try_catch(isolate);
4821 if (callback->Call(context, Undefined(isolate), 0, nullptr).IsEmpty()) {
4829 Isolate* isolate,
4832 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
4834 SealHandleScope shs(isolate);
4837 ran_tasks = v8::platform::PumpMessageLoop(g_default_platform, isolate,
4839 if (ran_tasks) MicrotasksScope::PerformCheckpoint(isolate);
4843 // isolate. We execute all background tasks after running one foreground
4854 if (g_default_platform->IdleTasksEnabled(isolate)) {
4855 v8::platform::RunIdleTasks(g_default_platform, isolate,
4859 if (!RunSetTimeoutCallback(isolate, &ran_set_timeout)) return false;
4865 bool Shell::CompleteMessageLoop(Isolate* isolate) {
4866 auto get_waiting_behaviour = [isolate]() {
4868 DCHECK_GT(isolate_status_.count(isolate), 0);
4870 isolate->HasPendingBackgroundTasks()) ||
4871 isolate_status_[isolate] ||
4872 isolate_running_streaming_tasks_[isolate] > 0;
4878 isolate, [] { return platform::MessageLoopBehavior::kDoNotWait; });
4887 return ProcessMessages(isolate, get_waiting_behaviour);
4890 bool Shell::EmptyMessageQueues(Isolate* isolate) {
4892 isolate, []() { return platform::MessageLoopBehavior::kDoNotWait; });
4895 void Shell::PostForegroundTask(Isolate* isolate, std::unique_ptr<Task> task) {
4896 g_default_platform->GetForegroundTaskRunner(isolate)->PostTask(
4904 bool Shell::HandleUnhandledPromiseRejections(Isolate* isolate) {
4906 PerIsolateData* data = PerIsolateData::Get(isolate);
4915 explicit Serializer(Isolate* isolate)
4916 : isolate_(isolate),
4917 serializer_(isolate, this),
4963 Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer) override {
4979 Isolate* isolate, Local<WasmModuleObject> module) override {
5009 Maybe<uint32_t> GetSharedValueId(Isolate* isolate,
5020 // isolate. No code ever runs in the shared Isolate, so locking it does not
5023 DCHECK_EQ(reinterpret_cast<i::Isolate*>(isolate)->shared_isolate(),
5106 Deserializer(Isolate* isolate, std::unique_ptr<SerializationData> data)
5107 : isolate_(isolate),
5108 deserializer_(isolate, data->data(), data->size(), this),
5139 Isolate* isolate, uint32_t clone_id) override {
5149 Isolate* isolate, uint32_t transfer_id) override {
5158 MaybeLocal<Value> GetSharedValueFromId(Isolate* isolate,
5162 return data_->shared_values().at(id).Get(isolate);
5211 static void DeoptimizeAll(Isolate* isolate) {
5212 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5219 Isolate* isolate, Local<Value> value, Local<Value> transfer) {
5221 Local<Context> context = isolate->GetCurrentContext();
5222 Serializer serializer(isolate);
5231 Isolate* isolate, std::unique_ptr<SerializationData> data) {
5233 Local<Context> context = isolate->GetCurrentContext();
5234 Deserializer deserializer(isolate, std::move(data));
5439 Isolate* isolate = Isolate::New(create_params);
5442 D8Console console(isolate);
5443 Isolate::Scope scope(isolate);
5444 Initialize(isolate, &console);
5445 PerIsolateData data(isolate);
5468 isolate, trace_config_json_str);
5482 cpu_profiler = CpuProfiler::New(isolate);
5484 cpu_profiler->StartProfiling(String::Empty(isolate), profile_options);
5494 result = RunMain(isolate, last_run);
5497 D8Testing::DeoptimizeAll(isolate);
5504 result = RunMain(isolate, last_run);
5509 // Park the main thread here in case the new isolate wants to perform
5511 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5544 // Second run to consume the cache in current isolate
5545 result = RunMain(isolate, true);
5550 result = RunMain(isolate, last_run);
5556 RunShell(isolate);
5560 WriteIgnitionDispatchCountersFile(isolate);
5565 cpu_profiler->StopProfiling(String::Empty(isolate));
5580 CollectGarbage(isolate);
5588 reinterpret_cast<i::Isolate*>(isolate));
5611 reinterpret_cast<i::Isolate*>(isolate));
5617 OnExit(isolate, true);