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

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

Issue 563043003: Don't crash when generating error messages with malformed strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/unicode.cc » ('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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 EXPECT_VALID(utf8_str); 1033 EXPECT_VALID(utf8_str);
1034 EXPECT(Dart_IsString(utf8_str)); 1034 EXPECT(Dart_IsString(utf8_str));
1035 1035
1036 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. 1036 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow.
1037 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, 1037 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid,
1038 ARRAY_SIZE(invalid)); 1038 ARRAY_SIZE(invalid));
1039 EXPECT(Dart_IsError(invalid_str)); 1039 EXPECT(Dart_IsError(invalid_str));
1040 } 1040 }
1041 1041
1042 1042
1043 TEST_CASE(MalformedStringToUTF8) {
1044 const char* kScriptChars =
1045 "String testMain() {"
1046 " return '\\u{1D11E}'[1];"
1047 "}";
1048
1049 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1050 Dart_Handle str1 = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
1051 EXPECT_VALID(str1);
1052
1053 uint8_t* utf8_encoded = NULL;
1054 intptr_t utf8_length = 0;
1055 Dart_Handle result = Dart_StringToUTF8(str1, &utf8_encoded, &utf8_length);
1056 EXPECT_VALID(result);
1057 EXPECT_EQ(3, utf8_length);
1058 EXPECT_EQ(237, static_cast<intptr_t>(utf8_encoded[0]));
1059 EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1]));
1060 EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2]));
1061
1062 Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length);
1063 EXPECT(Dart_IsError(str2)); // Invalid UTF-8.
1064 }
1065
1066
1043 static void ExternalStringCallbackFinalizer(void* peer) { 1067 static void ExternalStringCallbackFinalizer(void* peer) {
1044 *static_cast<int*>(peer) *= 2; 1068 *static_cast<int*>(peer) *= 2;
1045 } 1069 }
1046 1070
1047 1071
1048 TEST_CASE(ExternalStringCallback) { 1072 TEST_CASE(ExternalStringCallback) {
1049 int peer8 = 40; 1073 int peer8 = 40;
1050 int peer16 = 41; 1074 int peer16 = 41;
1051 1075
1052 { 1076 {
(...skipping 7613 matching lines...) Expand 10 before | Expand all | Expand 10 after
8666 NewString("main"), 8690 NewString("main"),
8667 1, 8691 1,
8668 dart_args); 8692 dart_args);
8669 int64_t value = 0; 8693 int64_t value = 0;
8670 result = Dart_IntegerToInt64(result, &value); 8694 result = Dart_IntegerToInt64(result, &value);
8671 EXPECT_VALID(result); 8695 EXPECT_VALID(result);
8672 EXPECT_EQ(6, value); 8696 EXPECT_EQ(6, value);
8673 } 8697 }
8674 8698
8675 } // namespace dart 8699 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/unicode.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698