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

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: 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..64edc8e737a49be57f929d13a1d7b2d735106d47 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,49 @@ 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(raw_obj, c_obj);
+ } else if (raw_obj == Object::null()) {
+ ConvertNull(raw_obj, c_obj);
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ private:
+ static void ConvertSmi(RawObject* raw_obj, Dart_CObject* c_obj) {
Ivan Posva 2015/12/11 21:02:38 ConvertSmi(RawSmi* raw_smi, ...)
zra 2015/12/11 22:01:31 Done.
+ ASSERT(!raw_obj->IsHeapObject());
+ intptr_t value = reinterpret_cast<intptr_t>(raw_obj) >> kSmiTagShift;
Ivan Posva 2015/12/11 21:02:38 Smi::Value(raw_smi)
zra 2015/12/11 22:01:31 Done.
+ if (Utils::IsInt(32, 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(RawObject* raw_obj, Dart_CObject* c_obj) {
Ivan Posva 2015/12/11 21:02:38 Drop the raw_obj parameter.
zra 2015/12/11 22:01:31 Done.
+ ASSERT(raw_obj == Object::null());
+ 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