| OLD | NEW |
| 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 "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 27 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 28 | 28 |
| 29 Dart_Handle instance = Dart_True(); | 29 Dart_Handle instance = Dart_True(); |
| 30 Dart_Handle error = Api::NewError("myerror"); | 30 Dart_Handle error = Api::NewError("myerror"); |
| 31 Dart_Handle exception = Dart_Invoke(lib, | 31 Dart_Handle exception = Dart_Invoke(lib, |
| 32 Dart_NewString("testMain"), | 32 Dart_NewString("testMain"), |
| 33 0, | 33 0, |
| 34 NULL); | 34 NULL); |
| 35 | 35 |
| 36 EXPECT(!Dart_IsError(instance)); | 36 EXPECT_VALID(instance); |
| 37 EXPECT(Dart_IsError(error)); | 37 EXPECT(Dart_IsError(error)); |
| 38 EXPECT(Dart_IsError(exception)); | 38 EXPECT(Dart_IsError(exception)); |
| 39 | 39 |
| 40 EXPECT(!Dart_ErrorHasException(instance)); | 40 EXPECT(!Dart_ErrorHasException(instance)); |
| 41 EXPECT(!Dart_ErrorHasException(error)); | 41 EXPECT(!Dart_ErrorHasException(error)); |
| 42 EXPECT(Dart_ErrorHasException(exception)); | 42 EXPECT(Dart_ErrorHasException(exception)); |
| 43 | 43 |
| 44 EXPECT_STREQ("", Dart_GetError(instance)); | 44 EXPECT_STREQ("", Dart_GetError(instance)); |
| 45 EXPECT_STREQ("myerror", Dart_GetError(error)); | 45 EXPECT_STREQ("myerror", Dart_GetError(error)); |
| 46 EXPECT_STREQ( | 46 EXPECT_STREQ( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 66 | 66 |
| 67 Dart_Handle not_error = Dart_NewString("NotError"); | 67 Dart_Handle not_error = Dart_NewString("NotError"); |
| 68 Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); | 68 Dart_Handle api_error = Dart_NewApiError("Api%s", "Error"); |
| 69 Dart_Handle exception_error = | 69 Dart_Handle exception_error = |
| 70 Dart_NewUnhandledExceptionError(Dart_NewString("ExceptionError")); | 70 Dart_NewUnhandledExceptionError(Dart_NewString("ExceptionError")); |
| 71 Dart_Handle compile_error = | 71 Dart_Handle compile_error = |
| 72 Api::NewHandle(isolate, LanguageError::New(compile_message)); | 72 Api::NewHandle(isolate, LanguageError::New(compile_message)); |
| 73 Dart_Handle fatal_error = | 73 Dart_Handle fatal_error = |
| 74 Api::NewHandle(isolate, UnwindError::New(fatal_message)); | 74 Api::NewHandle(isolate, UnwindError::New(fatal_message)); |
| 75 | 75 |
| 76 EXPECT(!Dart_IsError(not_error)); | 76 EXPECT_VALID(not_error); |
| 77 EXPECT(Dart_IsError(api_error)); | 77 EXPECT(Dart_IsError(api_error)); |
| 78 EXPECT(Dart_IsError(exception_error)); | 78 EXPECT(Dart_IsError(exception_error)); |
| 79 EXPECT(Dart_IsError(compile_error)); | 79 EXPECT(Dart_IsError(compile_error)); |
| 80 EXPECT(Dart_IsError(fatal_error)); | 80 EXPECT(Dart_IsError(fatal_error)); |
| 81 | 81 |
| 82 EXPECT(!Dart_IsApiError(not_error)); | 82 EXPECT(!Dart_IsApiError(not_error)); |
| 83 EXPECT(Dart_IsApiError(api_error)); | 83 EXPECT(Dart_IsApiError(api_error)); |
| 84 EXPECT(!Dart_IsApiError(exception_error)); | 84 EXPECT(!Dart_IsApiError(exception_error)); |
| 85 EXPECT(!Dart_IsApiError(compile_error)); | 85 EXPECT(!Dart_IsApiError(compile_error)); |
| 86 EXPECT(!Dart_IsApiError(fatal_error)); | 86 EXPECT(!Dart_IsApiError(fatal_error)); |
| (...skipping 4801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4888 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); | 4888 intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0])); |
| 4889 Dart_Handle import_map = Dart_NewList(length); | 4889 Dart_Handle import_map = Dart_NewList(length); |
| 4890 for (intptr_t i = 0; i < length; i++) { | 4890 for (intptr_t i = 0; i < length; i++) { |
| 4891 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); | 4891 Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i])); |
| 4892 } | 4892 } |
| 4893 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); | 4893 Dart_Handle result = Dart_SetLibraryTagHandler(import_library_handler); |
| 4894 EXPECT_VALID(result); | 4894 EXPECT_VALID(result); |
| 4895 result = Dart_SetImportMap(import_map); | 4895 result = Dart_SetImportMap(import_map); |
| 4896 EXPECT_VALID(result); | 4896 EXPECT_VALID(result); |
| 4897 result = Dart_LoadScript(url, source); | 4897 result = Dart_LoadScript(url, source); |
| 4898 EXPECT(!Dart_IsError(result)); | 4898 EXPECT_VALID(result); |
| 4899 } | 4899 } |
| 4900 | 4900 |
| 4901 | 4901 |
| 4902 TEST_CASE(LoadImportScriptError1) { | 4902 TEST_CASE(LoadImportScriptError1) { |
| 4903 const char* kScriptChars = | 4903 const char* kScriptChars = |
| 4904 "#import('abc${DEF}def/extra_weird.dart');" | 4904 "#import('abc${DEF}def/extra_weird.dart');" |
| 4905 "main() {" | 4905 "main() {" |
| 4906 " return 12345;" | 4906 " return 12345;" |
| 4907 "}"; | 4907 "}"; |
| 4908 Dart_Handle url = Dart_NewString(TestCase::url()); | 4908 Dart_Handle url = Dart_NewString(TestCase::url()); |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6198 // Shutdown the isolate. | 6198 // Shutdown the isolate. |
| 6199 Dart_ShutdownIsolate(); | 6199 Dart_ShutdownIsolate(); |
| 6200 | 6200 |
| 6201 // The shutdown callback has been called. | 6201 // The shutdown callback has been called. |
| 6202 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); | 6202 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); |
| 6203 | 6203 |
| 6204 Isolate::SetShutdownCallback(saved); | 6204 Isolate::SetShutdownCallback(saved); |
| 6205 } | 6205 } |
| 6206 | 6206 |
| 6207 static int64_t GetValue(Dart_Handle arg) { | 6207 static int64_t GetValue(Dart_Handle arg) { |
| 6208 EXPECT(!Dart_IsError(arg)); | 6208 EXPECT_VALID(arg); |
| 6209 EXPECT(Dart_IsInteger(arg)); | 6209 EXPECT(Dart_IsInteger(arg)); |
| 6210 int64_t value; | 6210 int64_t value; |
| 6211 EXPECT_VALID(Dart_IntegerToInt64(arg, &value)); | 6211 EXPECT_VALID(Dart_IntegerToInt64(arg, &value)); |
| 6212 return value; | 6212 return value; |
| 6213 } | 6213 } |
| 6214 | 6214 |
| 6215 static void NativeFoo1(Dart_NativeArguments args) { | 6215 static void NativeFoo1(Dart_NativeArguments args) { |
| 6216 Dart_EnterScope(); | 6216 Dart_EnterScope(); |
| 6217 intptr_t i = Dart_GetNativeArgumentCount(args); | 6217 intptr_t i = Dart_GetNativeArgumentCount(args); |
| 6218 EXPECT_EQ(1, i); | 6218 EXPECT_EQ(1, i); |
| 6219 Dart_Handle arg = Dart_GetNativeArgument(args, 0); | 6219 Dart_Handle arg = Dart_GetNativeArgument(args, 0); |
| 6220 EXPECT(!Dart_IsError(arg)); | 6220 EXPECT_VALID(arg); |
| 6221 Dart_SetReturnValue(args, Dart_NewInteger(1)); | 6221 Dart_SetReturnValue(args, Dart_NewInteger(1)); |
| 6222 Dart_ExitScope(); | 6222 Dart_ExitScope(); |
| 6223 } | 6223 } |
| 6224 | 6224 |
| 6225 | 6225 |
| 6226 static void NativeFoo2(Dart_NativeArguments args) { | 6226 static void NativeFoo2(Dart_NativeArguments args) { |
| 6227 Dart_EnterScope(); | 6227 Dart_EnterScope(); |
| 6228 intptr_t i = Dart_GetNativeArgumentCount(args); | 6228 intptr_t i = Dart_GetNativeArgumentCount(args); |
| 6229 EXPECT_EQ(2, i); | 6229 EXPECT_EQ(2, i); |
| 6230 Dart_Handle arg = Dart_GetNativeArgument(args, 1); | 6230 Dart_Handle arg = Dart_GetNativeArgument(args, 1); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6533 EXPECT(Dart_IsString(str)); | 6533 EXPECT(Dart_IsString(str)); |
| 6534 len = -1; | 6534 len = -1; |
| 6535 EXPECT_VALID(Dart_StringLength(str, &len)); | 6535 EXPECT_VALID(Dart_StringLength(str, &len)); |
| 6536 EXPECT_EQ(0, len); | 6536 EXPECT_EQ(0, len); |
| 6537 } | 6537 } |
| 6538 | 6538 |
| 6539 | 6539 |
| 6540 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6540 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6541 | 6541 |
| 6542 } // namespace dart | 6542 } // namespace dart |
| OLD | NEW |