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

Unified Diff: runtime/vm/dart_api_message.h

Issue 1499853004: Adds a special case for sending an int over a port with the native API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Cleanup Created 5 years 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
Index: runtime/vm/dart_api_message.h
diff --git a/runtime/vm/dart_api_message.h b/runtime/vm/dart_api_message.h
index 16a138bc44b80786a6bc730a9091adfab0a6faff..de1b5c3c5b53da215395c7f375e5c59db4a2bd2d 100644
--- a/runtime/vm/dart_api_message.h
+++ b/runtime/vm/dart_api_message.h
@@ -6,7 +6,10 @@
#define VM_DART_API_MESSAGE_H_
#include "include/dart_native_api.h"
+#include "platform/utils.h"
+#include "vm/allocation.h"
#include "vm/dart_api_state.h"
+#include "vm/raw_object.h"
#include "vm/snapshot.h"
namespace dart {
@@ -201,6 +204,48 @@ class ApiMessageWriter : public BaseWriter {
DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter);
};
+
+// This class handles translation of certain RawObjects to CObjects for
+// NativeMessageHandlers.
+//
+// TODO(zra): Expand to support not only null, but also other VM heap objects
+// as well.
+class ApiObjectConverter : public AllStatic {
+ public:
+ static bool CanConvert(RawObject* raw_obj) {
+ return !raw_obj->IsHeapObject() || (raw_obj == Object::null());
+ }
+
+ static bool Convert(RawObject* raw_obj, Dart_CObject* c_obj) {
+ if (!raw_obj->IsHeapObject()) {
+ ConvertSmi(reinterpret_cast<RawSmi*>(raw_obj), c_obj);
+ } else if (raw_obj == Object::null()) {
+ ConvertNull(c_obj);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ private:
+ static void ConvertSmi(RawSmi* raw_smi, Dart_CObject* c_obj) {
+ ASSERT(!raw_smi->IsHeapObject());
+ intptr_t value = Smi::Value(raw_smi);
+ if (Utils::IsInt(31, value)) {
+ c_obj->type = Dart_CObject_kInt32;
+ c_obj->value.as_int32 = static_cast<int32_t>(value);
+ } else {
+ c_obj->type = Dart_CObject_kInt64;
+ c_obj->value.as_int64 = static_cast<int64_t>(value);
+ }
+ }
+
+ static void ConvertNull(Dart_CObject* c_obj) {
+ c_obj->type = Dart_CObject_kNull;
+ c_obj->value.as_int64 = 0;
+ }
+};
+
} // namespace dart
#endif // VM_DART_API_MESSAGE_H_

Powered by Google App Engine
This is Rietveld 408576698