Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 std::string message; |
| 22 message.appendLiteral("Argument "); | 21 message.append("Argument "); |
| 23 message.appendNumber(index); | 22 message.append(std::to_string(index)); |
| 24 message.appendLiteral(" cannot be null."); | 23 message.append(" cannot be null."); |
|
abarth-chromium
2015/07/15 20:42:52
This is super inefficient. Is there no StringBuil
| |
| 25 return CreateException("ArgumentError", message.toString()); | 24 return CreateException("ArgumentError", message); |
| 26 } | 25 } |
| 27 | 26 |
| 28 Dart_Handle DartExceptionFactory::CreateException(const String& class_name, | 27 Dart_Handle DartExceptionFactory::CreateException(const std::string& class_name, |
| 29 const String& message) { | 28 const std::string& message) { |
| 30 if (core_library_.is_empty()) { | 29 if (core_library_.is_empty()) { |
| 31 Dart_Handle library = DartBuiltin::LookupLibrary("dart:core"); | 30 Dart_Handle library = DartBuiltin::LookupLibrary("dart:core"); |
| 32 core_library_.Set(dart_state_, library); | 31 core_library_.Set(dart_state_, library); |
| 33 } | 32 } |
| 34 | 33 |
| 35 Dart_Handle exception_class = Dart_GetType( | 34 Dart_Handle exception_class = Dart_GetType( |
| 36 core_library_.value(), StringToDart(dart_state_, class_name), 0, 0); | 35 core_library_.value(), StdStringToDart(class_name), 0, 0); |
| 37 Dart_Handle message_handle = StringToDart(dart_state_, message); | 36 Dart_Handle message_handle = StdStringToDart(message); |
| 38 return Dart_New(exception_class, Dart_EmptyString(), 1, &message_handle); | 37 return Dart_New(exception_class, Dart_EmptyString(), 1, &message_handle); |
| 39 } | 38 } |
| 40 | 39 |
| 41 } // namespace blink | 40 } // namespace blink |
| OLD | NEW |