| Index: tonic/dart_converter.h
 | 
| diff --git a/tonic/dart_converter.h b/tonic/dart_converter.h
 | 
| index 47d9f8409d0468fe47ba819950a11769a6dc24a6..f0387b28affe4a8906c94f806ff7d3cee21586bb 100644
 | 
| --- a/tonic/dart_converter.h
 | 
| +++ b/tonic/dart_converter.h
 | 
| @@ -6,12 +6,8 @@
 | 
|  #define SKY_ENGINE_TONIC_DART_CONVERTER_H_
 | 
|  
 | 
|  #include <string>
 | 
| +
 | 
|  #include "tonic/dart_state.h"
 | 
| -#include "tonic/dart_string.h"
 | 
| -#include "tonic/dart_string_cache.h"
 | 
| -#include "tonic/dart_value.h"
 | 
| -#include "sky/engine/wtf/text/StringUTF8Adaptor.h"
 | 
| -#include "sky/engine/wtf/text/WTFString.h"
 | 
|  
 | 
|  namespace blink {
 | 
|  
 | 
| @@ -176,187 +172,6 @@ struct DartConverterEnum {
 | 
|    }
 | 
|  };
 | 
|  
 | 
| -////////////////////////////////////////////////////////////////////////////////
 | 
| -// Strings
 | 
| -
 | 
| -template <>
 | 
| -struct DartConverter<String> {
 | 
| -  static Dart_Handle ToDart(DartState* state, const String& val) {
 | 
| -    if (val.isEmpty())
 | 
| -      return Dart_EmptyString();
 | 
| -    return Dart_HandleFromWeakPersistent(state->string_cache().Get(val.impl()));
 | 
| -  }
 | 
| -
 | 
| -  static void SetReturnValue(Dart_NativeArguments args,
 | 
| -                             const String& val,
 | 
| -                             bool auto_scope = true) {
 | 
| -    // TODO(abarth): What should we do with auto_scope?
 | 
| -    if (val.isEmpty()) {
 | 
| -      Dart_SetReturnValue(args, Dart_EmptyString());
 | 
| -      return;
 | 
| -    }
 | 
| -    DartState* state = DartState::Current();
 | 
| -    Dart_SetWeakHandleReturnValue(args, state->string_cache().Get(val.impl()));
 | 
| -  }
 | 
| -
 | 
| -  static void SetReturnValueWithNullCheck(Dart_NativeArguments args,
 | 
| -                                          const String& val,
 | 
| -                                          bool auto_scope = true) {
 | 
| -    if (val.isNull())
 | 
| -      Dart_SetReturnValue(args, Dart_Null());
 | 
| -    else
 | 
| -      SetReturnValue(args, val, auto_scope);
 | 
| -  }
 | 
| -
 | 
| -  static String FromDart(Dart_Handle handle) {
 | 
| -    intptr_t char_size = 0;
 | 
| -    intptr_t length = 0;
 | 
| -    void* peer = nullptr;
 | 
| -    Dart_Handle result =
 | 
| -        Dart_StringGetProperties(handle, &char_size, &length, &peer);
 | 
| -    if (peer)
 | 
| -      return String(static_cast<StringImpl*>(peer));
 | 
| -    if (Dart_IsError(result))
 | 
| -      return String();
 | 
| -    return ExternalizeDartString(handle);
 | 
| -  }
 | 
| -
 | 
| -  static String FromArguments(Dart_NativeArguments args,
 | 
| -                              int index,
 | 
| -                              Dart_Handle& exception,
 | 
| -                              bool auto_scope = true) {
 | 
| -    // TODO(abarth): What should we do with auto_scope?
 | 
| -    void* peer = nullptr;
 | 
| -    Dart_Handle handle = Dart_GetNativeStringArgument(args, index, &peer);
 | 
| -    if (peer)
 | 
| -      return reinterpret_cast<StringImpl*>(peer);
 | 
| -    if (Dart_IsError(handle))
 | 
| -      return String();
 | 
| -    return ExternalizeDartString(handle);
 | 
| -  }
 | 
| -
 | 
| -  static String FromArgumentsWithNullCheck(Dart_NativeArguments args,
 | 
| -                                           int index,
 | 
| -                                           Dart_Handle& exception,
 | 
| -                                           bool auto_scope = true) {
 | 
| -    // TODO(abarth): What should we do with auto_scope?
 | 
| -    void* peer = nullptr;
 | 
| -    Dart_Handle handle = Dart_GetNativeStringArgument(args, index, &peer);
 | 
| -    if (peer)
 | 
| -      return reinterpret_cast<StringImpl*>(peer);
 | 
| -    if (Dart_IsError(handle) || Dart_IsNull(handle))
 | 
| -      return String();
 | 
| -    return ExternalizeDartString(handle);
 | 
| -  }
 | 
| -};
 | 
| -
 | 
| -template <>
 | 
| -struct DartConverter<AtomicString> {
 | 
| -  static Dart_Handle ToDart(DartState* state, const AtomicString& val) {
 | 
| -    return DartConverter<String>::ToDart(state, val.string());
 | 
| -  }
 | 
| -};
 | 
| -
 | 
| -////////////////////////////////////////////////////////////////////////////////
 | 
| -// Collections
 | 
| -
 | 
| -template <typename T>
 | 
| -struct DartConverter<Vector<T>> {
 | 
| -  using ValueType = typename DartConverterTypes<T>::ValueType;
 | 
| -  using ConverterType = typename DartConverterTypes<T>::ConverterType;
 | 
| -
 | 
| -  static Dart_Handle ToDart(const Vector<ValueType>& val) {
 | 
| -    Dart_Handle list = Dart_NewList(val.size());
 | 
| -    if (Dart_IsError(list))
 | 
| -      return list;
 | 
| -    for (size_t i = 0; i < val.size(); i++) {
 | 
| -      Dart_Handle result =
 | 
| -          Dart_ListSetAt(list, i,
 | 
| -                         DartConverter<ConverterType>::ToDart(val[i]));
 | 
| -      if (Dart_IsError(result))
 | 
| -        return result;
 | 
| -    }
 | 
| -    return list;
 | 
| -  }
 | 
| -
 | 
| -  static Vector<ValueType> FromDart(Dart_Handle handle) {
 | 
| -    Vector<ValueType> result;
 | 
| -    if (!Dart_IsList(handle))
 | 
| -      return result;
 | 
| -    intptr_t length = 0;
 | 
| -    Dart_ListLength(handle, &length);
 | 
| -    result.reserveCapacity(length);
 | 
| -    for (intptr_t i = 0; i < length; ++i) {
 | 
| -      Dart_Handle item = Dart_ListGetAt(handle, i);
 | 
| -      DCHECK(!Dart_IsError(item));
 | 
| -      DCHECK(item);
 | 
| -      result.append(DartConverter<ConverterType>::FromDart(item));
 | 
| -    }
 | 
| -    return result;
 | 
| -  }
 | 
| -
 | 
| -  static Vector<ValueType> FromArguments(Dart_NativeArguments args,
 | 
| -                                          int index,
 | 
| -                                          Dart_Handle& exception,
 | 
| -                                          bool auto_scope = true) {
 | 
| -    // TODO(abarth): What should we do with auto_scope?
 | 
| -    return FromDart(Dart_GetNativeArgument(args, index));
 | 
| -  }
 | 
| -};
 | 
| -
 | 
| -////////////////////////////////////////////////////////////////////////////////
 | 
| -// DartValue
 | 
| -
 | 
| -template <>
 | 
| -struct DartConverter<DartValue*> {
 | 
| -  static Dart_Handle ToDart(DartState* state, DartValue* val) {
 | 
| -    return val->dart_value();
 | 
| -  }
 | 
| -
 | 
| -  static void SetReturnValue(Dart_NativeArguments args, DartValue* val) {
 | 
| -    Dart_SetReturnValue(args, val->dart_value());
 | 
| -  }
 | 
| -
 | 
| -  static PassRefPtr<DartValue> FromDart(Dart_Handle handle) {
 | 
| -    return DartValue::Create(DartState::Current(), handle);
 | 
| -  }
 | 
| -
 | 
| -  static PassRefPtr<DartValue> FromArguments(Dart_NativeArguments args,
 | 
| -                                             int index,
 | 
| -                                             Dart_Handle& exception,
 | 
| -                                             bool auto_scope = true) {
 | 
| -    // TODO(abarth): What should we do with auto_scope?
 | 
| -    return FromDart(Dart_GetNativeArgument(args, index));
 | 
| -  }
 | 
| -};
 | 
| -
 | 
| -////////////////////////////////////////////////////////////////////////////////
 | 
| -// Convience wrappers for commonly used conversions
 | 
| -
 | 
| -inline Dart_Handle StringToDart(DartState* state, const String& val) {
 | 
| -  return DartConverter<String>::ToDart(state, val);
 | 
| -}
 | 
| -
 | 
| -inline Dart_Handle StringToDart(DartState* state, const AtomicString& val) {
 | 
| -  return DartConverter<AtomicString>::ToDart(state, val);
 | 
| -}
 | 
| -
 | 
| -inline String StringFromDart(Dart_Handle handle) {
 | 
| -  return DartConverter<String>::FromDart(handle);
 | 
| -}
 | 
| -
 | 
| -////////////////////////////////////////////////////////////////////////////////
 | 
| -// Convience wrappers using type inference for ease of code generation
 | 
| -
 | 
| -template <typename T>
 | 
| -inline Dart_Handle VectorToDart(const Vector<T>& val) {
 | 
| -  return DartConverter<Vector<T>>::ToDart(val);
 | 
| -}
 | 
| -
 | 
| -template<typename T>
 | 
| -Dart_Handle ToDart(const T& object) {
 | 
| -  return DartConverter<T>::ToDart(object);
 | 
| -}
 | 
|  
 | 
|  ////////////////////////////////////////////////////////////////////////////////
 | 
|  // std::string support (slower, but more convienent for some clients)
 | 
| @@ -367,9 +182,14 @@ inline Dart_Handle StdStringToDart(const std::string& val) {
 | 
|  }
 | 
|  
 | 
|  inline std::string StdStringFromDart(Dart_Handle handle) {
 | 
| -  String string = StringFromDart(handle);
 | 
| -  StringUTF8Adaptor utf8(string);
 | 
| -  return std::string(utf8.data(), utf8.length());
 | 
| +  uint8_t* data = nullptr;
 | 
| +  intptr_t length = 0;
 | 
| +  Dart_Handle r = Dart_StringToUTF8(handle, &data, &length);
 | 
| +  if (Dart_IsError(r)) {
 | 
| +    return std::string();
 | 
| +  }
 | 
| +  return std::string(reinterpret_cast<const char*>(data),
 | 
| +                     static_cast<size_t>(length));
 | 
|  }
 | 
|  
 | 
|  
 | 
| 
 |