Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions runtime/dart_isolate_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/runtime/dart_vm.h"
#include "flutter/testing/testing.h"
#include "flutter/testing/thread_test.h"
#include "third_party/tonic/scopes/dart_isolate_scope.h"

#define CURRENT_TEST_NAME \
std::string { \
Expand Down Expand Up @@ -99,6 +100,19 @@ class AutoIsolateShutdown {

bool IsValid() const { return isolate_ != nullptr; }

FML_WARN_UNUSED_RESULT
bool RunInIsolateScope(std::function<bool(void)> closure) {
if (!isolate_) {
return false;
}
tonic::DartIsolateScope scope(isolate_->isolate());
tonic::DartApiScope api_scope;
if (closure) {
return closure();
}
return true;
}

blink::DartIsolate* get() {
FML_CHECK(isolate_);
return isolate_.get();
Expand Down Expand Up @@ -210,4 +224,18 @@ TEST_F(DartIsolateTest, IsolateCannotLoadAndRunUnknownDartEntrypoint) {
ASSERT_FALSE(isolate);
}

TEST_F(DartIsolateTest, CanRunDartCodeCodeSynchronously) {
auto isolate = RunDartCodeInIsolate(GetCurrentTaskRunner(), "main");

ASSERT_TRUE(isolate);

ASSERT_TRUE(isolate->RunInIsolateScope([]() -> bool {
if (tonic::LogIfError(::Dart_Invoke(Dart_RootLibrary(),
tonic::ToDart("sayHi"), 0, nullptr))) {
return false;
}
return true;
}));
}

} // namespace blink
9 changes: 8 additions & 1 deletion runtime/fixtures/simple_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
// found in the LICENSE file.

void main() {
print('Hello');
}

void sayHi() {
print("Hi");
}

void throwExceptionNow() {
throw("Hello");
}