Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions | Variables
exceptions_test.cc File Reference
#include "include/dart_api.h"
#include "platform/assert.h"
#include "vm/dart_api_impl.h"
#include "vm/unit_test.h"

Go to the source code of this file.

Classes

struct  dart::NativeEntries
 

Namespaces

namespace  dart
 

Macros

#define FUNCTION_NAME(name)   UnhandledExcp_##name
 
#define REGISTER_FUNCTION(name, count)   {"" #name, FUNCTION_NAME(name), count},
 
#define UNHANDLED_NATIVE_LIST(V)
 

Functions

void FUNCTION_NAME() dart::Unhandled_equals (Dart_NativeArguments args)
 
void FUNCTION_NAME() dart::Unhandled_invoke (Dart_NativeArguments args)
 
void FUNCTION_NAME() dart::Unhandled_invoke2 (Dart_NativeArguments args)
 
static Dart_NativeFunction dart::native_lookup (Dart_Handle name, int argument_count, bool *auto_setup_scope)
 
 dart::TEST_CASE (UnhandledExceptions)
 

Variables

static struct dart::NativeEntries dart::BuiltinEntries [] = {UNHANDLED_NATIVE_LIST(REGISTER_FUNCTION)}
 

Macro Definition Documentation

◆ FUNCTION_NAME

#define FUNCTION_NAME (   name)    UnhandledExcp_##name

Definition at line 12 of file exceptions_test.cc.

◆ REGISTER_FUNCTION

#define REGISTER_FUNCTION (   name,
  count 
)    {"" #name, FUNCTION_NAME(name), count},

Definition at line 13 of file exceptions_test.cc.

◆ UNHANDLED_NATIVE_LIST

#define UNHANDLED_NATIVE_LIST (   V)
Value:
V(Unhandled_equals, 2) \
V(Unhandled_invoke, 0) \
V(Unhandled_invoke2, 0)
#define V(name)
Definition raw_object.h:124

Definition at line 55 of file exceptions_test.cc.

59 {
60 const char* name_;
61 Dart_NativeFunction function_;
62 int argument_count_;
64
67 bool* auto_setup_scope) {
68 ASSERT(auto_setup_scope != nullptr);
69 *auto_setup_scope = true;
70 TransitionNativeToVM transition(Thread::Current());
71 const Object& obj = Object::Handle(Api::UnwrapHandle(name));
72 ASSERT(obj.IsString());
73 const char* function_name = obj.ToCString();
74 ASSERT(function_name != nullptr);
75 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
76 for (int i = 0; i < num_entries; i++) {
77 struct NativeEntries* entry = &(BuiltinEntries[i]);
78 if ((strcmp(function_name, entry->name_) == 0) &&
79 (argument_count == entry->argument_count_)) {
80 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
81 }
82 }
83 return nullptr;
84}
85
86// Unit test case to verify unhandled exceptions.
87TEST_CASE(UnhandledExceptions) {
88 const char* kScriptChars =
89 R"(
90 class UnhandledExceptions {
91 @pragma('vm:external-name', 'Unhandled_equals')
92 external static equals(var obj1, var obj2);
93
94 @pragma('vm:external-name', 'Unhandled_invoke')
95 external static invoke();
96
97 @pragma('vm:external-name', 'Unhandled_invoke2')
98 external static invoke2();
99 }
100 class Second {
101 Second() { }
102 static int method1(int param) {
103 UnhandledExceptions.invoke();
104 return 2;
105 }
106 static int method2() {
107 throw new Second();
108 }
109 static int method3(int param) {
110 try {
111 UnhandledExceptions.invoke2();
112 } on Second catch (e) {
113 return 3;
114 }
115 return 2;
116 }
117 }
118 testMain() {
119 UnhandledExceptions.equals(2, Second.method1(1));
120 UnhandledExceptions.equals(3, Second.method3(1));
121 }
122 )";
123 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, native_lookup);
124 EXPECT_VALID(Dart_Invoke(lib, NewString("testMain"), 0, nullptr));
125}
126
127} // namespace dart
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition dart_api.h:3198
#define ASSERT(E)
#define UNHANDLED_NATIVE_LIST(V)
#define REGISTER_FUNCTION(name, count)
const char * name
Definition fuchsia.cc:50
int argument_count
Definition fuchsia.cc:52
static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count, bool *auto_setup_scope)
static struct dart::NativeEntries BuiltinEntries[]
const char *const function_name
Dart_Handle NewString(const char *str)
Definition unit_test.h:229
#define TEST_CASE(name)
Definition unit_test.h:85
#define EXPECT_VALID(handle)
Definition unit_test.h:650