Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1232)

Side by Side Diff: runtime/vm/exceptions_test.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/exceptions.cc ('k') | runtime/vm/fixed_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12
13 #define FUNCTION_NAME(name) UnhandledExcp_##name 12 #define FUNCTION_NAME(name) UnhandledExcp_##name
14 #define REGISTER_FUNCTION(name, count) {"" #name, FUNCTION_NAME(name), count}, 13 #define REGISTER_FUNCTION(name, count) {"" #name, FUNCTION_NAME(name), count},
15 14
16
17 void FUNCTION_NAME(Unhandled_equals)(Dart_NativeArguments args) { 15 void FUNCTION_NAME(Unhandled_equals)(Dart_NativeArguments args) {
18 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 16 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
19 const Instance& expected = Instance::CheckedHandle(arguments->NativeArgAt(0)); 17 const Instance& expected = Instance::CheckedHandle(arguments->NativeArgAt(0));
20 const Instance& actual = Instance::CheckedHandle(arguments->NativeArgAt(1)); 18 const Instance& actual = Instance::CheckedHandle(arguments->NativeArgAt(1));
21 if (!expected.CanonicalizeEquals(actual)) { 19 if (!expected.CanonicalizeEquals(actual)) {
22 OS::Print("expected: '%s' actual: '%s'\n", expected.ToCString(), 20 OS::Print("expected: '%s' actual: '%s'\n", expected.ToCString(),
23 actual.ToCString()); 21 actual.ToCString());
24 FATAL("Unhandled_equals fails.\n"); 22 FATAL("Unhandled_equals fails.\n");
25 } 23 }
26 } 24 }
27 25
28
29 void FUNCTION_NAME(Unhandled_invoke)(Dart_NativeArguments args) { 26 void FUNCTION_NAME(Unhandled_invoke)(Dart_NativeArguments args) {
30 // Invoke the specified entry point. 27 // Invoke the specified entry point.
31 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second")); 28 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second"));
32 Dart_Handle result = Dart_Invoke(cls, NewString("method2"), 0, NULL); 29 Dart_Handle result = Dart_Invoke(cls, NewString("method2"), 0, NULL);
33 ASSERT(Dart_IsError(result)); 30 ASSERT(Dart_IsError(result));
34 ASSERT(Dart_ErrorHasException(result)); 31 ASSERT(Dart_ErrorHasException(result));
35 return; 32 return;
36 } 33 }
37 34
38
39 void FUNCTION_NAME(Unhandled_invoke2)(Dart_NativeArguments args) { 35 void FUNCTION_NAME(Unhandled_invoke2)(Dart_NativeArguments args) {
40 // Invoke the specified entry point. 36 // Invoke the specified entry point.
41 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second")); 37 Dart_Handle cls = Dart_GetClass(TestCase::lib(), NewString("Second"));
42 Dart_Handle result = Dart_Invoke(cls, NewString("method2"), 0, NULL); 38 Dart_Handle result = Dart_Invoke(cls, NewString("method2"), 0, NULL);
43 ASSERT(Dart_IsError(result)); 39 ASSERT(Dart_IsError(result));
44 ASSERT(Dart_ErrorHasException(result)); 40 ASSERT(Dart_ErrorHasException(result));
45 Dart_Handle exception = Dart_ErrorGetException(result); 41 Dart_Handle exception = Dart_ErrorGetException(result);
46 ASSERT(!Dart_IsError(exception)); 42 ASSERT(!Dart_IsError(exception));
47 Dart_ThrowException(exception); 43 Dart_ThrowException(exception);
48 UNREACHABLE(); 44 UNREACHABLE();
49 return; 45 return;
50 } 46 }
51 47
52
53 // List all native functions implemented in the vm or core boot strap dart 48 // List all native functions implemented in the vm or core boot strap dart
54 // libraries so that we can resolve the native function to it's entry 49 // libraries so that we can resolve the native function to it's entry
55 // point. 50 // point.
56 #define UNHANDLED_NATIVE_LIST(V) \ 51 #define UNHANDLED_NATIVE_LIST(V) \
57 V(Unhandled_equals, 2) \ 52 V(Unhandled_equals, 2) \
58 V(Unhandled_invoke, 0) \ 53 V(Unhandled_invoke, 0) \
59 V(Unhandled_invoke2, 0) 54 V(Unhandled_invoke2, 0)
60 55
61
62 static struct NativeEntries { 56 static struct NativeEntries {
63 const char* name_; 57 const char* name_;
64 Dart_NativeFunction function_; 58 Dart_NativeFunction function_;
65 int argument_count_; 59 int argument_count_;
66 } BuiltinEntries[] = {UNHANDLED_NATIVE_LIST(REGISTER_FUNCTION)}; 60 } BuiltinEntries[] = {UNHANDLED_NATIVE_LIST(REGISTER_FUNCTION)};
67 61
68
69 static Dart_NativeFunction native_lookup(Dart_Handle name, 62 static Dart_NativeFunction native_lookup(Dart_Handle name,
70 int argument_count, 63 int argument_count,
71 bool* auto_setup_scope) { 64 bool* auto_setup_scope) {
72 ASSERT(auto_setup_scope != NULL); 65 ASSERT(auto_setup_scope != NULL);
73 *auto_setup_scope = true; 66 *auto_setup_scope = true;
74 const Object& obj = Object::Handle(Api::UnwrapHandle(name)); 67 const Object& obj = Object::Handle(Api::UnwrapHandle(name));
75 ASSERT(obj.IsString()); 68 ASSERT(obj.IsString());
76 const char* function_name = obj.ToCString(); 69 const char* function_name = obj.ToCString();
77 ASSERT(function_name != NULL); 70 ASSERT(function_name != NULL);
78 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries); 71 int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
79 for (int i = 0; i < num_entries; i++) { 72 for (int i = 0; i < num_entries; i++) {
80 struct NativeEntries* entry = &(BuiltinEntries[i]); 73 struct NativeEntries* entry = &(BuiltinEntries[i]);
81 if (!strcmp(function_name, entry->name_) && 74 if (!strcmp(function_name, entry->name_) &&
82 (argument_count == entry->argument_count_)) { 75 (argument_count == entry->argument_count_)) {
83 return reinterpret_cast<Dart_NativeFunction>(entry->function_); 76 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
84 } 77 }
85 } 78 }
86 return NULL; 79 return NULL;
87 } 80 }
88 81
89
90 // Unit test case to verify unhandled exceptions. 82 // Unit test case to verify unhandled exceptions.
91 TEST_CASE(UnhandledExceptions) { 83 TEST_CASE(UnhandledExceptions) {
92 const char* kScriptChars = 84 const char* kScriptChars =
93 "class UnhandledExceptions {\n" 85 "class UnhandledExceptions {\n"
94 " static equals(var obj1, var obj2) native \"Unhandled_equals\";" 86 " static equals(var obj1, var obj2) native \"Unhandled_equals\";"
95 " static invoke() native \"Unhandled_invoke\";\n" 87 " static invoke() native \"Unhandled_invoke\";\n"
96 " static invoke2() native \"Unhandled_invoke2\";\n" 88 " static invoke2() native \"Unhandled_invoke2\";\n"
97 "}\n" 89 "}\n"
98 "class Second {\n" 90 "class Second {\n"
99 " Second() { }\n" 91 " Second() { }\n"
(...skipping 16 matching lines...) Expand all
116 "testMain() {\n" 108 "testMain() {\n"
117 " UnhandledExceptions.equals(2, Second.method1(1));\n" 109 " UnhandledExceptions.equals(2, Second.method1(1));\n"
118 " UnhandledExceptions.equals(3, Second.method3(1));\n" 110 " UnhandledExceptions.equals(3, Second.method3(1));\n"
119 "}"; 111 "}";
120 Dart_Handle lib = TestCase::LoadTestScript( 112 Dart_Handle lib = TestCase::LoadTestScript(
121 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); 113 kScriptChars, reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
122 EXPECT_VALID(Dart_Invoke(lib, NewString("testMain"), 0, NULL)); 114 EXPECT_VALID(Dart_Invoke(lib, NewString("testMain"), 0, NULL));
123 } 115 }
124 116
125 } // namespace dart 117 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/exceptions.cc ('k') | runtime/vm/fixed_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698