diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index f3ca74d5071..4bd04c85ce3 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -6713,6 +6713,21 @@ char* SnapshotHeaderReader::InitializeGlobalVMFlagsFromSnapshot( #undef CHECK_FLAG #undef SET_FLAG +#if defined(DART_PRECOMPILED_RUNTIME) + if (FLAG_null_safety == kNullSafetyOptionUnspecified) { + if (strncmp(cursor, "null-safety", end - cursor) == 0) { + FLAG_null_safety = kNullSafetyOptionStrong; + cursor = end; + continue; + } + if (strncmp(cursor, "no-null-safety", end - cursor) == 0) { + FLAG_null_safety = kNullSafetyOptionWeak; + cursor = end; + continue; + } + } +#endif // defined(DART_PRECOMPILED_RUNTIME) + cursor = end; } diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index 3ec567d8947..31f297378ad 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -753,12 +753,13 @@ bool Dart::DetectNullSafety(const char* script_uri, intptr_t kernel_buffer_size, const char* package_config, const char* original_working_directory) { +#if !defined(DART_PRECOMPILED_RUNTIME) // Before creating the isolate we first determine the null safety mode // in which the isolate needs to run based on one of these factors : // - if loading from source, based on opt-in status of the source // - if loading from a kernel file, based on the mode used when // generating the kernel file - // - if loading from an appJIT or AOT snapshot, based on the mode used + // - if loading from an appJIT, based on the mode used // when generating the snapshot. ASSERT(FLAG_null_safety == kNullSafetyOptionUnspecified); @@ -772,7 +773,6 @@ bool Dart::DetectNullSafety(const char* script_uri, } } -#if !defined(DART_PRECOMPILED_RUNTIME) // If kernel_buffer is specified, it could be a self contained // kernel file or the kernel file of the application, // figure out the null safety mode by sniffing the kernel file. @@ -791,8 +791,10 @@ bool Dart::DetectNullSafety(const char* script_uri, return KernelIsolate::DetectNullSafety(script_uri, package_config, original_working_directory); } -#endif // !defined(DART_PRECOMPILED_RUNTIME) return false; +#else + UNREACHABLE(); +#endif // !defined(DART_PRECOMPILED_RUNTIME) } #if defined(DART_PRECOMPILED_RUNTIME) diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index b3800b5b45d..78930305403 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -6032,6 +6032,10 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri, const uint8_t* snapshot_instructions, const uint8_t* kernel_buffer, intptr_t kernel_buffer_size) { +#if defined(DART_PRECOMPILED_RUNTIME) + ASSERT(FLAG_null_safety != kNullSafetyOptionUnspecified); + return (FLAG_null_safety == kNullSafetyOptionStrong); +#else bool null_safety; if (FLAG_null_safety == kNullSafetyOptionUnspecified) { null_safety = Dart::DetectNullSafety( @@ -6041,6 +6045,7 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri, null_safety = (FLAG_null_safety == kNullSafetyOptionStrong); } return null_safety; +#endif // defined(DART_PRECOMPILED_RUNTIME) } // --- Service support ---