Index: mojo/dart/dart_snapshotter/logging.cc |
diff --git a/tonic/dart_error.cc b/mojo/dart/dart_snapshotter/logging.cc |
similarity index 57% |
copy from tonic/dart_error.cc |
copy to mojo/dart/dart_snapshotter/logging.cc |
index c44877dcca428d2cede45b5f9f7fc0f6e624a374..7fb04834cc231067caa6c0aa950fc1bef3b3100a 100644 |
--- a/tonic/dart_error.cc |
+++ b/mojo/dart/dart_snapshotter/logging.cc |
@@ -2,18 +2,10 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "tonic/dart_error.h" |
+#include "mojo/dart/dart_snapshotter/logging.h" |
#include "base/logging.h" |
-namespace tonic { |
- |
-namespace DartError { |
- |
-const char kInvalidArgument[] = "Invalid argument."; |
- |
-} // namespace DartError |
- |
bool LogIfError(Dart_Handle handle) { |
if (Dart_IsError(handle)) { |
LOG(ERROR) << Dart_GetError(handle); |
@@ -31,4 +23,15 @@ bool LogIfError(Dart_Handle handle) { |
return false; |
} |
-} // namespace tonic |
+std::string StringFromDart(Dart_Handle string) { |
+ CHECK(Dart_IsString(string)); |
+ uint8_t* utf8_array; |
+ intptr_t length; |
+ Dart_StringToUTF8(string, &utf8_array, &length); |
+ return std::string(reinterpret_cast<const char*>(utf8_array), length); |
+} |
+ |
+Dart_Handle StringToDart(const std::string& string) { |
+ return Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(string.data()), |
+ string.length()); |
+} |