OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
6 #include "sky/engine/tonic/dart_wrappable.h" | 6 #include "sky/engine/tonic/dart_wrappable.h" |
7 | 7 |
8 #include "sky/engine/tonic/dart_class_library.h" | 8 #include "sky/engine/tonic/dart_class_library.h" |
9 #include "sky/engine/tonic/dart_error.h" | 9 #include "sky/engine/tonic/dart_error.h" |
10 #include "sky/engine/tonic/dart_exception_factory.h" | 10 #include "sky/engine/tonic/dart_exception_factory.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields); | 34 Dart_AllocateWithNativeFields(type, kNumberOfNativeFields, native_fields); |
35 DCHECK(!LogIfError(wrapper)); | 35 DCHECK(!LogIfError(wrapper)); |
36 | 36 |
37 info.ref_object(this); // Balanced in FinalizeDartWrapper. | 37 info.ref_object(this); // Balanced in FinalizeDartWrapper. |
38 dart_wrapper_ = Dart_NewPrologueWeakPersistentHandle( | 38 dart_wrapper_ = Dart_NewPrologueWeakPersistentHandle( |
39 wrapper, this, info.size_in_bytes, &FinalizeDartWrapper); | 39 wrapper, this, info.size_in_bytes, &FinalizeDartWrapper); |
40 | 40 |
41 return wrapper; | 41 return wrapper; |
42 } | 42 } |
43 | 43 |
44 void DartWrappable::AssociateWithDartWrapper(Dart_NativeArguments args) { | |
45 DCHECK(!dart_wrapper_); | |
46 | |
47 Dart_Handle wrapper = Dart_GetNativeArgument(args, 0); | |
48 CHECK(!LogIfError(wrapper)); | |
49 | |
50 intptr_t native_fields[kNumberOfNativeFields]; | |
51 CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument( | |
52 args, 0, kNumberOfNativeFields, native_fields))); | |
esprehn
2015/02/20 06:56:10
So all things have the same number of native field
abarth-chromium
2015/02/20 07:00:34
Yes. Always two there are.
| |
53 CHECK(!native_fields[kPeerIndex]); | |
54 CHECK(!native_fields[kWrapperInfoIndex]); | |
55 | |
56 const DartWrapperInfo& info = GetDartWrapperInfo(); | |
57 CHECK(!LogIfError(Dart_SetNativeInstanceField( | |
58 wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this)))); | |
59 CHECK(!LogIfError(Dart_SetNativeInstanceField( | |
60 wrapper, kWrapperInfoIndex, reinterpret_cast<intptr_t>(&info)))); | |
61 | |
62 info.ref_object(this); // Balanced in FinalizeDartWrapper. | |
63 dart_wrapper_ = Dart_NewPrologueWeakPersistentHandle( | |
64 wrapper, this, info.size_in_bytes, &FinalizeDartWrapper); | |
65 } | |
66 | |
44 void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data, | 67 void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data, |
45 Dart_WeakPersistentHandle wrapper, | 68 Dart_WeakPersistentHandle wrapper, |
46 void* peer) { | 69 void* peer) { |
47 DartWrappable* wrappable = reinterpret_cast<DartWrappable*>(peer); | 70 DartWrappable* wrappable = reinterpret_cast<DartWrappable*>(peer); |
48 wrappable->dart_wrapper_ = nullptr; | 71 wrappable->dart_wrapper_ = nullptr; |
49 const DartWrapperInfo& info = wrappable->GetDartWrapperInfo(); | 72 const DartWrapperInfo& info = wrappable->GetDartWrapperInfo(); |
50 info.deref_object(wrappable); // Balanced in CreateDartWrapper. | 73 info.deref_object(wrappable); // Balanced in CreateDartWrapper. |
51 } | 74 } |
52 | 75 |
53 DartWrappable* DartConverterWrappable::FromDart(Dart_Handle handle) { | 76 DartWrappable* DartConverterWrappable::FromDart(Dart_Handle handle) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 args, index, DartWrappable::kNumberOfNativeFields, native_fields); | 109 args, index, DartWrappable::kNumberOfNativeFields, native_fields); |
87 if (Dart_IsError(result)) { | 110 if (Dart_IsError(result)) { |
88 exception = Dart_NewStringFromCString(DartError::kInvalidArgument); | 111 exception = Dart_NewStringFromCString(DartError::kInvalidArgument); |
89 return nullptr; | 112 return nullptr; |
90 } | 113 } |
91 return reinterpret_cast<DartWrappable*>( | 114 return reinterpret_cast<DartWrappable*>( |
92 native_fields[DartWrappable::kPeerIndex]); | 115 native_fields[DartWrappable::kPeerIndex]); |
93 } | 116 } |
94 | 117 |
95 } // namespace blink | 118 } // namespace blink |
OLD | NEW |