Make mojo dart controller depend on tonic and get building without wtf
R=abarth@chromium.org
Review URL: https://codereview.chromium.org/1244983003 .
diff --git a/mojo/dart/embedder/BUILD.gn b/mojo/dart/embedder/BUILD.gn
index f15e4aa..df63c0c 100644
--- a/mojo/dart/embedder/BUILD.gn
+++ b/mojo/dart/embedder/BUILD.gn
@@ -48,6 +48,7 @@
"//third_party/dart-pkg",
"//mojo/public/c/system",
"//mojo/public/cpp/system",
+ "//tonic",
]
defines = []
diff --git a/tonic/BUILD.gn b/tonic/BUILD.gn
index 4f37841..b3e7dd6 100644
--- a/tonic/BUILD.gn
+++ b/tonic/BUILD.gn
@@ -39,14 +39,8 @@
"dart_snapshot_loader.h",
"dart_state.cc",
"dart_state.h",
- "dart_string.cc",
- "dart_string.h",
- "dart_string_cache.cc",
- "dart_string_cache.h",
"dart_timer_heap.cc",
"dart_timer_heap.h",
- "dart_value.cc",
- "dart_value.h",
"dart_wrappable.cc",
"dart_wrappable.h",
"dart_wrapper_info.h",
@@ -59,7 +53,31 @@
"//base",
"//mojo/common",
"//mojo/public/cpp/system",
- "//sky/engine/wtf",
+ ]
+
+ public_deps = [
+ "//dart/runtime:libdart",
+ "//dart/runtime/vm:libdart_platform",
+ ]
+}
+
+# TODO(johnmccutchan): Move these sources into sky_engine and remove this.
+source_set("tonic_wtf") {
+ sources = [
+ "dart_converter_wtf.cc",
+ "dart_converter_wtf.h",
+ "dart_string.cc",
+ "dart_string.h",
+ "dart_string_cache.cc",
+ "dart_string_cache.h",
+ "dart_value.cc",
+ "dart_value.h",
+ ]
+
+ deps = [
+ "//base",
+ "//mojo/common",
+ "//mojo/public/cpp/system",
]
public_deps = [
diff --git a/tonic/dart_converter.h b/tonic/dart_converter.h
index 47d9f84..f0387b2 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 @@
}
};
-////////////////////////////////////////////////////////////////////////////////
-// 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 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));
}
diff --git a/tonic/dart_converter_wtf.cc b/tonic/dart_converter_wtf.cc
new file mode 100644
index 0000000..6fe5ae7
--- /dev/null
+++ b/tonic/dart_converter_wtf.cc
@@ -0,0 +1,8 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tonic/dart_converter_wtf.h"
+
+// This file exists to ensure dart_converter_wtf.h doesn't miss any
+// dependencies.
diff --git a/tonic/dart_converter_wtf.h b/tonic/dart_converter_wtf.h
new file mode 100644
index 0000000..5a48748
--- /dev/null
+++ b/tonic/dart_converter_wtf.h
@@ -0,0 +1,211 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SKY_ENGINE_TONIC_DART_CONVERTER_WTF_H_
+#define SKY_ENGINE_TONIC_DART_CONVERTER_WTF_H_
+
+#include <string>
+#include "sky/engine/wtf/text/StringUTF8Adaptor.h"
+#include "sky/engine/wtf/text/WTFString.h"
+#include "tonic/dart_converter.h"
+#include "tonic/dart_string.h"
+#include "tonic/dart_string_cache.h"
+#include "tonic/dart_value.h"
+
+namespace blink {
+
+////////////////////////////////////////////////////////////////////////////////
+// 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);
+}
+
+template<typename T>
+struct DartConverter<RefPtr<T>> {
+ static Dart_Handle ToDart(RefPtr<T> val) {
+ return DartConverter<T*>::ToDart(val.get());
+ }
+
+ static RefPtr<T> FromDart(Dart_Handle handle) {
+ return DartConverter<T*>::FromDart(handle);
+ }
+};
+
+#endif // SKY_ENGINE_TONIC_DART_CONVERTER_WTF_H_
diff --git a/tonic/dart_library_loader.cc b/tonic/dart_library_loader.cc
index a6492ad..dbb73f7 100644
--- a/tonic/dart_library_loader.cc
+++ b/tonic/dart_library_loader.cc
@@ -56,7 +56,8 @@
loader_->DidFailJob(this);
return;
}
- drainer_ = adoptPtr(new DataPipeDrainer(this, pipe.Pass()));
+ drainer_ = std::unique_ptr<DataPipeDrainer>(
+ new DataPipeDrainer(this, pipe.Pass()));
}
// DataPipeDrainer::Client
@@ -67,7 +68,7 @@
// Subclasses must implement OnDataComplete.
std::string name_;
- OwnPtr<DataPipeDrainer> drainer_;
+ std::unique_ptr<DataPipeDrainer> drainer_;
base::WeakPtrFactory<Job> weak_factory_;
};
@@ -150,7 +151,8 @@
WatcherSignaler(DartLibraryLoader& loader,
DartDependency* resolved_dependency)
: loader_(loader),
- catcher_(adoptPtr(new DartDependencyCatcher(loader))),
+ catcher_(std::unique_ptr<DartDependencyCatcher>(
+ new DartDependencyCatcher(loader))),
resolved_dependency_(resolved_dependency) {}
~WatcherSignaler() {
@@ -164,7 +166,7 @@
// Notice that we remove the dependency catcher and extract all the
// callbacks before running any of them. We don't want to be re-entered
// below the callbacks and end up in an inconsistent state.
- catcher_.clear();
+ catcher_.reset();
std::vector<base::Closure> callbacks;
for (const auto& watcher : completed_watchers) {
callbacks.push_back(watcher->callback());
@@ -178,7 +180,7 @@
private:
DartLibraryLoader& loader_;
- OwnPtr<DartDependencyCatcher> catcher_;
+ std::unique_ptr<DartDependencyCatcher> catcher_;
DartDependency* resolved_dependency_;
};
diff --git a/tonic/dart_state.cc b/tonic/dart_state.cc
index 60732bd..76851ce 100644
--- a/tonic/dart_state.cc
+++ b/tonic/dart_state.cc
@@ -8,7 +8,6 @@
#include "tonic/dart_converter.h"
#include "tonic/dart_exception_factory.h"
#include "tonic/dart_library_loader.h"
-#include "tonic/dart_string_cache.h"
#include "tonic/dart_timer_heap.h"
namespace blink {
@@ -26,8 +25,6 @@
new DartExceptionFactory(this))),
library_loader_(std::unique_ptr<DartLibraryLoader>(
new DartLibraryLoader(this))),
- string_cache_(std::unique_ptr<DartStringCache>(
- new DartStringCache)),
timer_heap_(std::unique_ptr<DartTimerHeap>(
new DartTimerHeap())),
weak_factory_(this) {
diff --git a/tonic/dart_state.h b/tonic/dart_state.h
index 5eafb55..e56d38a 100644
--- a/tonic/dart_state.h
+++ b/tonic/dart_state.h
@@ -17,7 +17,6 @@
class DartClassLibrary;
class DartExceptionFactory;
class DartLibraryLoader;
-class DartStringCache;
class DartTimerHeap;
// DartState represents the state associated with a given Dart isolate. The
@@ -51,7 +50,6 @@
DartClassLibrary& class_library() { return *class_library_; }
DartExceptionFactory& exception_factory() { return *exception_factory_; }
DartLibraryLoader& library_loader() { return *library_loader_; }
- DartStringCache& string_cache() { return *string_cache_; }
DartTimerHeap& timer_heap() { return *timer_heap_; }
Dart_Handle index_handle() { return index_handle_.value(); }
@@ -63,7 +61,6 @@
std::unique_ptr<DartClassLibrary> class_library_;
std::unique_ptr<DartExceptionFactory> exception_factory_;
std::unique_ptr<DartLibraryLoader> library_loader_;
- std::unique_ptr<DartStringCache> string_cache_;
std::unique_ptr<DartTimerHeap> timer_heap_;
DartPersistentValue index_handle_;
diff --git a/tonic/dart_wrappable.h b/tonic/dart_wrappable.h
index 13feb99..9428601 100644
--- a/tonic/dart_wrappable.h
+++ b/tonic/dart_wrappable.h
@@ -123,17 +123,6 @@
};
template<typename T>
-struct DartConverter<RefPtr<T>> {
- static Dart_Handle ToDart(RefPtr<T> val) {
- return DartConverter<T*>::ToDart(val.get());
- }
-
- static RefPtr<T> FromDart(Dart_Handle handle) {
- return DartConverter<T*>::FromDart(handle);
- }
-};
-
-template<typename T>
inline T* GetReceiver(Dart_NativeArguments args) {
intptr_t receiver;
Dart_Handle result = Dart_GetNativeReceiver(args, &receiver);
diff --git a/tonic/float32_list.cc b/tonic/float32_list.cc
index 6bcfc7a..38e67e5 100644
--- a/tonic/float32_list.cc
+++ b/tonic/float32_list.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/logging.h"
#include "tonic/dart_error.h"
#include "tonic/float32_list.h"
@@ -16,7 +17,7 @@
Dart_TypedDataAcquireData(
list, &type, reinterpret_cast<void**>(&data_), &num_elements_);
DCHECK(!LogIfError(list));
- ASSERT(type == Dart_TypedData_kFloat32);
+ DCHECK(type == Dart_TypedData_kFloat32);
}
Float32List::Float32List(Float32List&& other)