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

Unified Diff: sky/engine/tonic/dart_wrappable.cc

Issue 924593002: Merge the tonic layer from skydart branch back to master (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix Created 5 years, 10 months 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
« no previous file with comments | « sky/engine/tonic/dart_wrappable.h ('k') | sky/engine/tonic/dart_wrapper_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/tonic/dart_wrappable.cc
diff --git a/sky/engine/tonic/dart_wrappable.cc b/sky/engine/tonic/dart_wrappable.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6c7e3a15267fff3b4a7c22cbbdb5dafe79cffc24
--- /dev/null
+++ b/sky/engine/tonic/dart_wrappable.cc
@@ -0,0 +1,91 @@
+// 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 "sky/engine/config.h"
+#include "sky/engine/tonic/dart_wrappable.h"
+
+#include "sky/engine/tonic/dart_class_library.h"
+#include "sky/engine/tonic/dart_error.h"
+#include "sky/engine/tonic/dart_state.h"
+#include "sky/engine/tonic/dart_wrapper_info.h"
+
+namespace blink {
+
+DartWrappable::~DartWrappable() {
+ CHECK(!dart_wrapper_);
+}
+
+void DartWrappable::AcceptDartGCVisitor(DartGCVisitor& visitor) const {
+}
+
+Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) {
+ DCHECK(!dart_wrapper_);
+ const DartWrapperInfo& info = GetDartWrapperInfo();
+
+ Dart_PersistentHandle type = dart_state->class_library().GetClass(info);
+ DCHECK(!LogIfError(type));
+
+ intptr_t native_fields[kNumberOfNativeFields];
+ native_fields[kPeerIndex] = reinterpret_cast<intptr_t>(this);
+ native_fields[kWrapperInfoIndex] = reinterpret_cast<intptr_t>(&info);
+ Dart_Handle wrapper =
+ Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields);
+ DCHECK(!LogIfError(wrapper));
+
+ info.ref_object(this); // Balanced in FinalizeDartWrapper.
+ dart_wrapper_ = Dart_NewPrologueWeakPersistentHandle(
+ wrapper, this, info.size_in_bytes, &FinalizeDartWrapper);
+
+ return wrapper;
+}
+
+void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data,
+ Dart_WeakPersistentHandle wrapper,
+ void* peer) {
+ DartWrappable* wrappable = reinterpret_cast<DartWrappable*>(peer);
+ wrappable->dart_wrapper_ = nullptr;
+ const DartWrapperInfo& info = wrappable->GetDartWrapperInfo();
+ info.deref_object(wrappable); // Balanced in CreateDartWrapper.
+}
+
+DartWrappable* DartConverterWrappable::FromDart(Dart_Handle handle) {
+ intptr_t* peer = 0;
+ Dart_Handle result =
+ Dart_GetNativeInstanceField(handle, DartWrappable::kPeerIndex, peer);
+ if (Dart_IsError(result))
+ return nullptr;
+ return reinterpret_cast<DartWrappable*>(peer);
+}
+
+DartWrappable* DartConverterWrappable::FromArguments(Dart_NativeArguments args,
+ int index,
+ Dart_Handle& exception) {
+ intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
+ Dart_Handle result = Dart_GetNativeFieldsOfArgument(
+ args, index, DartWrappable::kNumberOfNativeFields, native_fields);
+ if (Dart_IsError(result)) {
+ exception = Dart_NewStringFromCString(DartError::kInvalidArgument);
+ return nullptr;
+ }
+ return reinterpret_cast<DartWrappable*>(
+ native_fields[DartWrappable::kPeerIndex]);
+}
+
+DartWrappable* DartConverterWrappable::FromArgumentsWithNullCheck(
+ Dart_NativeArguments args, int index, Dart_Handle& exception) {
+ Dart_Handle handle = Dart_GetNativeArgument(args, index);
+ if (Dart_IsNull(handle))
+ return nullptr;
+ intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
+ Dart_Handle result = Dart_GetNativeFieldsOfArgument(
+ args, index, DartWrappable::kNumberOfNativeFields, native_fields);
+ if (Dart_IsError(result)) {
+ exception = Dart_NewStringFromCString(DartError::kInvalidArgument);
+ return nullptr;
+ }
+ return reinterpret_cast<DartWrappable*>(
+ native_fields[DartWrappable::kPeerIndex]);
+}
+
+} // namespace blink
« no previous file with comments | « sky/engine/tonic/dart_wrappable.h ('k') | sky/engine/tonic/dart_wrapper_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698