mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:47:50 +00:00
[lib] Private API for disabling Isolate.exit().
This is needed to prevent users from closing the platform isolate. Bug: https://github.com/flutter/flutter/issues/136314 Change-Id: I98ab0a847dad245a1f1d6c16e96f2f4add39a84f TEST=runtime/vm/isolate_test.cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352760 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Liam Appelbe <liama@google.com>
This commit is contained in:
parent
4df361c3c3
commit
c3a626f729
|
@ -237,4 +237,56 @@ ISOLATE_UNIT_TEST_CASE(Isolate_Ports) {
|
|||
EXPECT(!isolate->HasLivePorts());
|
||||
}
|
||||
|
||||
ISOLATE_UNIT_TEST_CASE(Isolate_MayExit_True) {
|
||||
TransitionVMToNative transition(thread);
|
||||
|
||||
EXPECT_EQ(false, thread->is_unwind_in_progress());
|
||||
|
||||
Dart_EnterScope();
|
||||
|
||||
Dart_Handle lib =
|
||||
Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate"));
|
||||
EXPECT(!Dart_IsError(lib));
|
||||
|
||||
Dart_Handle isolate_type = Dart_GetNonNullableType(
|
||||
lib, Dart_NewStringFromCString("Isolate"), 0, nullptr);
|
||||
EXPECT(!Dart_IsError(isolate_type));
|
||||
|
||||
Dart_Handle result =
|
||||
Dart_Invoke(isolate_type, Dart_NewStringFromCString("exit"), 0, nullptr);
|
||||
EXPECT(Dart_IsFatalError(result));
|
||||
|
||||
Dart_ExitScope();
|
||||
|
||||
EXPECT_EQ(true, thread->is_unwind_in_progress());
|
||||
}
|
||||
|
||||
ISOLATE_UNIT_TEST_CASE(Isolate_MayExit_False) {
|
||||
TransitionVMToNative transition(thread);
|
||||
|
||||
EXPECT_EQ(false, thread->is_unwind_in_progress());
|
||||
|
||||
Dart_EnterScope();
|
||||
|
||||
Dart_Handle lib =
|
||||
Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate"));
|
||||
EXPECT(!Dart_IsError(lib));
|
||||
|
||||
Dart_Handle isolate_type = Dart_GetNonNullableType(
|
||||
lib, Dart_NewStringFromCString("Isolate"), 0, nullptr);
|
||||
EXPECT(!Dart_IsError(isolate_type));
|
||||
|
||||
Dart_Handle setter_result = Dart_SetField(
|
||||
isolate_type, Dart_NewStringFromCString("_mayExit"), Dart_False());
|
||||
EXPECT(!Dart_IsError(setter_result));
|
||||
|
||||
Dart_Handle result =
|
||||
Dart_Invoke(isolate_type, Dart_NewStringFromCString("exit"), 0, nullptr);
|
||||
EXPECT(Dart_IsUnhandledExceptionError(result));
|
||||
|
||||
Dart_ExitScope();
|
||||
|
||||
EXPECT_EQ(false, thread->is_unwind_in_progress());
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
|
|
@ -652,8 +652,14 @@ final class Isolate {
|
|||
@pragma("vm:external-name", "Isolate_exit_")
|
||||
external static Never _exit(SendPort? finalMessagePort, Object? message);
|
||||
|
||||
@pragma("vm:entry-point")
|
||||
static bool _mayExit = true;
|
||||
|
||||
@patch
|
||||
static Never exit([SendPort? finalMessagePort, Object? message]) {
|
||||
if (!_mayExit) {
|
||||
throw UnsupportedError("Isolate.exit");
|
||||
}
|
||||
_exit(finalMessagePort, message);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue