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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sky/engine/config.h"
6 #include "sky/engine/tonic/dart_wrappable.h"
7
8 #include "sky/engine/tonic/dart_class_library.h"
9 #include "sky/engine/tonic/dart_error.h"
10 #include "sky/engine/tonic/dart_state.h"
11 #include "sky/engine/tonic/dart_wrapper_info.h"
12
13 namespace blink {
14
15 DartWrappable::~DartWrappable() {
16 CHECK(!dart_wrapper_);
17 }
18
19 void DartWrappable::AcceptDartGCVisitor(DartGCVisitor& visitor) const {
20 }
21
22 Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) {
23 DCHECK(!dart_wrapper_);
24 const DartWrapperInfo& info = GetDartWrapperInfo();
25
26 Dart_PersistentHandle type = dart_state->class_library().GetClass(info);
27 DCHECK(!LogIfError(type));
28
29 intptr_t native_fields[kNumberOfNativeFields];
30 native_fields[kPeerIndex] = reinterpret_cast<intptr_t>(this);
31 native_fields[kWrapperInfoIndex] = reinterpret_cast<intptr_t>(&info);
32 Dart_Handle wrapper =
33 Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields);
34 DCHECK(!LogIfError(wrapper));
35
36 info.ref_object(this); // Balanced in FinalizeDartWrapper.
37 dart_wrapper_ = Dart_NewPrologueWeakPersistentHandle(
38 wrapper, this, info.size_in_bytes, &FinalizeDartWrapper);
39
40 return wrapper;
41 }
42
43 void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data,
44 Dart_WeakPersistentHandle wrapper,
45 void* peer) {
46 DartWrappable* wrappable = reinterpret_cast<DartWrappable*>(peer);
47 wrappable->dart_wrapper_ = nullptr;
48 const DartWrapperInfo& info = wrappable->GetDartWrapperInfo();
49 info.deref_object(wrappable); // Balanced in CreateDartWrapper.
50 }
51
52 DartWrappable* DartConverterWrappable::FromDart(Dart_Handle handle) {
53 intptr_t* peer = 0;
54 Dart_Handle result =
55 Dart_GetNativeInstanceField(handle, DartWrappable::kPeerIndex, peer);
56 if (Dart_IsError(result))
57 return nullptr;
58 return reinterpret_cast<DartWrappable*>(peer);
59 }
60
61 DartWrappable* DartConverterWrappable::FromArguments(Dart_NativeArguments args,
62 int index,
63 Dart_Handle& exception) {
64 intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
65 Dart_Handle result = Dart_GetNativeFieldsOfArgument(
66 args, index, DartWrappable::kNumberOfNativeFields, native_fields);
67 if (Dart_IsError(result)) {
68 exception = Dart_NewStringFromCString(DartError::kInvalidArgument);
69 return nullptr;
70 }
71 return reinterpret_cast<DartWrappable*>(
72 native_fields[DartWrappable::kPeerIndex]);
73 }
74
75 DartWrappable* DartConverterWrappable::FromArgumentsWithNullCheck(
76 Dart_NativeArguments args, int index, Dart_Handle& exception) {
77 Dart_Handle handle = Dart_GetNativeArgument(args, index);
78 if (Dart_IsNull(handle))
79 return nullptr;
80 intptr_t native_fields[DartWrappable::kNumberOfNativeFields];
81 Dart_Handle result = Dart_GetNativeFieldsOfArgument(
82 args, index, DartWrappable::kNumberOfNativeFields, native_fields);
83 if (Dart_IsError(result)) {
84 exception = Dart_NewStringFromCString(DartError::kInvalidArgument);
85 return nullptr;
86 }
87 return reinterpret_cast<DartWrappable*>(
88 native_fields[DartWrappable::kPeerIndex]);
89 }
90
91 } // namespace blink
OLDNEW
« 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