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

Side by Side Diff: sky/engine/tonic/dart_exception_factory.cc

Issue 1237973004: Port more String and HashMap usages (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 | « sky/engine/tonic/dart_exception_factory.h ('k') | sky/engine/tonic/dart_library_loader.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/engine/tonic/dart_exception_factory.h" 5 #include "sky/engine/tonic/dart_exception_factory.h"
6 6
7 #include "sky/engine/tonic/dart_converter.h" 7 #include "sky/engine/tonic/dart_converter.h"
8 #include "sky/engine/tonic/dart_builtin.h" 8 #include "sky/engine/tonic/dart_builtin.h"
9 #include "sky/engine/wtf/text/StringBuilder.h"
10 9
11 namespace blink { 10 namespace blink {
12 11
13 DartExceptionFactory::DartExceptionFactory(DartState* dart_state) 12 DartExceptionFactory::DartExceptionFactory(DartState* dart_state)
14 : dart_state_(dart_state) { 13 : dart_state_(dart_state) {
15 } 14 }
16 15
17 DartExceptionFactory::~DartExceptionFactory() { 16 DartExceptionFactory::~DartExceptionFactory() {
18 } 17 }
19 18
20 Dart_Handle DartExceptionFactory::CreateNullArgumentException(int index) { 19 Dart_Handle DartExceptionFactory::CreateNullArgumentException(int index) {
21 StringBuilder message; 20 const char* kArgument = "Argument ";
22 message.appendLiteral("Argument "); 21 const intptr_t kArgumentLen = strlen(kArgument);
23 message.appendNumber(index); 22 const char* kCannotBeNull = " cannot be null.";
24 message.appendLiteral(" cannot be null."); 23 const intptr_t kCannotBeNullLen = strlen(kCannotBeNull);
25 return CreateException("ArgumentError", message.toString()); 24 const std::string index_string = std::to_string(index);
25 std::vector<char> message;
26 message.reserve(kArgumentLen + kCannotBeNullLen + index_string.length() + 1);
27 std::copy(kArgument,
28 kArgument + kArgumentLen,
29 back_inserter(message));
30 std::copy(index_string.c_str(),
31 index_string.c_str() + index_string.length(),
32 back_inserter(message));
33 std::copy(kCannotBeNull,
34 kCannotBeNull + kCannotBeNullLen + 1, // +1 for '\0' character.
35 back_inserter(message));
36 return CreateException("ArgumentError", message.data());
abarth-chromium 2015/07/16 00:02:24 So ugly... Sorry to get hung up on this issue. I
Cutch 2015/07/16 14:31:02 Done. We can address any follow up comments you ha
26 } 37 }
27 38
28 Dart_Handle DartExceptionFactory::CreateException(const String& class_name, 39 Dart_Handle DartExceptionFactory::CreateException(const std::string& class_name,
29 const String& message) { 40 const std::string& message) {
30 if (core_library_.is_empty()) { 41 if (core_library_.is_empty()) {
31 Dart_Handle library = DartBuiltin::LookupLibrary("dart:core"); 42 Dart_Handle library = DartBuiltin::LookupLibrary("dart:core");
32 core_library_.Set(dart_state_, library); 43 core_library_.Set(dart_state_, library);
33 } 44 }
34 45
35 Dart_Handle exception_class = Dart_GetType( 46 Dart_Handle exception_class = Dart_GetType(
36 core_library_.value(), StringToDart(dart_state_, class_name), 0, 0); 47 core_library_.value(), StdStringToDart(class_name), 0, 0);
37 Dart_Handle message_handle = StringToDart(dart_state_, message); 48 Dart_Handle message_handle = StdStringToDart(message);
38 return Dart_New(exception_class, Dart_EmptyString(), 1, &message_handle); 49 return Dart_New(exception_class, Dart_EmptyString(), 1, &message_handle);
39 } 50 }
40 51
41 } // namespace blink 52 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/tonic/dart_exception_factory.h ('k') | sky/engine/tonic/dart_library_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698