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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/tonic/dart_exception_factory.cc
diff --git a/sky/engine/tonic/dart_exception_factory.cc b/sky/engine/tonic/dart_exception_factory.cc
index e439a45393cad0e5d3af5b42fedb5ecc60d850fa..5742a1a0b6c16496df0fb0286e177ac508a33af3 100644
--- a/sky/engine/tonic/dart_exception_factory.cc
+++ b/sky/engine/tonic/dart_exception_factory.cc
@@ -6,10 +6,84 @@
#include "sky/engine/tonic/dart_converter.h"
#include "sky/engine/tonic/dart_builtin.h"
-#include "sky/engine/wtf/text/StringBuilder.h"
namespace blink {
+// TODO(johnmccutchan): Move this into another file.
+class StdStringBuilder {
+ public:
+ StdStringBuilder() {
+ }
+
+ void Append(const char* s, intptr_t length) {
+ if (s == NULL) {
+ return;
+ }
+ for (intptr_t i = 0; i < length; i++) {
+ buffer_.push_back(s[i]);
+ }
+ }
+
+ void Append(const char* s) {
+ if (s == NULL) {
+ return;
+ }
+ for (intptr_t i = 0; s[i] != '\0'; i++) {
+ buffer_.push_back(s[i]);
+ }
+ }
+
+ void Append(char ch) {
+ buffer_.push_back(ch);
+ }
+
+ void Append(std::string s) {
+ if (s.length() == 0) {
+ return;
+ }
+ const char* c_str = s.data();
+ intptr_t c_str_length = s.size();
+ Append(c_str, c_str_length);
+ }
+
+ void AppendNumber(int num) {
+ Append(std::to_string(num));
+ }
+
+ void Clear() {
+ buffer_.resize(0);
+ }
+
+ void ShrinkToFit() {
+ buffer_.shrink_to_fit();
+ }
+
+ void Reserve(intptr_t capacity) {
+ buffer_.reserve(capacity);
+ }
+
+ std::string ToString() {
+ return std::string(buffer_.data(), buffer_.size());
+ }
+
+ const char* data() const {
+ return buffer_.data();
+ }
+
+ char* data() {
+ return buffer_.data();
+ }
+
+ intptr_t size() const {
+ return buffer_.size();
+ }
+
+ private:
+ std::vector<char> buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(StdStringBuilder);
+};
+
DartExceptionFactory::DartExceptionFactory(DartState* dart_state)
: dart_state_(dart_state) {
}
@@ -18,24 +92,30 @@ DartExceptionFactory::~DartExceptionFactory() {
}
Dart_Handle DartExceptionFactory::CreateNullArgumentException(int index) {
- StringBuilder message;
- message.appendLiteral("Argument ");
- message.appendNumber(index);
- message.appendLiteral(" cannot be null.");
- return CreateException("ArgumentError", message.toString());
+ StdStringBuilder builder;
+ builder.Append("Argument ");
+ builder.AppendNumber(index);
+ builder.Append(" cannot be null.");
+ Dart_Handle message_handle = Dart_NewStringFromUTF8(
+ reinterpret_cast<const uint8_t*>(builder.data()), builder.size());
+ return CreateException("ArgumentError", message_handle);
+}
+
+Dart_Handle DartExceptionFactory::CreateException(const std::string& class_name,
+ const std::string& message) {
+ return CreateException(class_name, StdStringToDart(message));
}
-Dart_Handle DartExceptionFactory::CreateException(const String& class_name,
- const String& message) {
+Dart_Handle DartExceptionFactory::CreateException(const std::string& class_name,
+ Dart_Handle message) {
if (core_library_.is_empty()) {
Dart_Handle library = DartBuiltin::LookupLibrary("dart:core");
core_library_.Set(dart_state_, library);
}
Dart_Handle exception_class = Dart_GetType(
- core_library_.value(), StringToDart(dart_state_, class_name), 0, 0);
- Dart_Handle message_handle = StringToDart(dart_state_, message);
- return Dart_New(exception_class, Dart_EmptyString(), 1, &message_handle);
+ core_library_.value(), StdStringToDart(class_name), 0, 0);
+ return Dart_New(exception_class, Dart_EmptyString(), 1, &message);
}
} // namespace blink
« 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