|
6 | 6 | import 'dart:ffi';
|
7 | 7 |
|
8 | 8 | import 'package:ffi/ffi.dart';
|
| 9 | +import 'package:webf/bridge.dart'; |
9 | 10 |
|
10 | 11 | import 'native_value.dart';
|
11 | 12 |
|
@@ -109,27 +110,64 @@ class NativeTouch extends Struct {
|
109 | 110 | external double azimuthAngle;
|
110 | 111 | }
|
111 | 112 |
|
112 |
| -typedef InvokeBindingsMethodsFromNative = Void Function(Double contextId, Int64 profileId, Pointer<NativeBindingObject> binding_object, |
113 |
| - Pointer<NativeValue> return_value, Pointer<NativeValue> method, Int32 argc, Pointer<NativeValue> argv); |
| 113 | +typedef InvokeBindingsMethodsFromNative = Void Function( |
| 114 | + Double contextId, |
| 115 | + Int64 profileId, |
| 116 | + Pointer<NativeBindingObject> binding_object, |
| 117 | + Pointer<NativeValue> return_value, |
| 118 | + Pointer<NativeValue> method, |
| 119 | + Int32 argc, |
| 120 | + Pointer<NativeValue> argv); |
114 | 121 | typedef NativeInvokeResultCallback = Void Function(Handle object, Pointer<NativeValue> result);
|
115 | 122 |
|
116 |
| -typedef InvokeBindingMethodsFromDart = Void Function(Pointer<NativeBindingObject> binding_object, Int64 profileId, Pointer<NativeValue> method, Int32 argc, Pointer<NativeValue> argv, Handle bindingDartObject, Pointer<NativeFunction<NativeInvokeResultCallback>> result_callback); |
117 |
| -typedef DartInvokeBindingMethodsFromDart = void Function(Pointer<NativeBindingObject> binding_object, int profileId, Pointer<NativeValue> method, int argc, Pointer<NativeValue> argv, Object bindingDartObject, Pointer<NativeFunction<NativeInvokeResultCallback>> result_callback); |
| 123 | +typedef InvokeBindingMethodsFromDart = Void Function( |
| 124 | + Pointer<NativeBindingObject> binding_object, |
| 125 | + Int64 profileId, |
| 126 | + Pointer<NativeValue> method, |
| 127 | + Int32 argc, |
| 128 | + Pointer<NativeValue> argv, |
| 129 | + Handle bindingDartObject, |
| 130 | + Pointer<NativeFunction<NativeInvokeResultCallback>> result_callback); |
| 131 | +typedef DartInvokeBindingMethodsFromDart = void Function( |
| 132 | + Pointer<NativeBindingObject> binding_object, |
| 133 | + int profileId, |
| 134 | + Pointer<NativeValue> method, |
| 135 | + int argc, |
| 136 | + Pointer<NativeValue> argv, |
| 137 | + Object bindingDartObject, |
| 138 | + Pointer<NativeFunction<NativeInvokeResultCallback>> result_callback); |
118 | 139 |
|
119 | 140 | class NativeBindingObject extends Struct {
|
120 |
| - @Bool() |
121 |
| - external bool disposed; |
122 | 141 | external Pointer<Void> instance;
|
123 | 142 | external Pointer<NativeFunction<InvokeBindingMethodsFromDart>> invokeBindingMethodFromDart;
|
124 | 143 | // Shared method called by JS side.
|
125 | 144 | external Pointer<NativeFunction<InvokeBindingsMethodsFromNative>> invokeBindingMethodFromNative;
|
126 | 145 | external Pointer<Void> extra;
|
| 146 | + @Bool() |
| 147 | + external bool _disposed; |
127 | 148 | }
|
128 | 149 |
|
| 150 | +typedef NativeAllocateNativeBindingObject = Pointer<NativeBindingObject> Function(); |
| 151 | +typedef DartAllocateNativeBindingObject = Pointer<NativeBindingObject> Function(); |
| 152 | + |
| 153 | +final DartAllocateNativeBindingObject _allocateNativeBindingObject = WebFDynamicLibrary.ref |
| 154 | + .lookup<NativeFunction<NativeAllocateNativeBindingObject>>('allocateNativeBindingObject') |
| 155 | + .asFunction(); |
| 156 | + |
| 157 | +typedef NativeIsNativeBindingObjectDisposed = Bool Function(Pointer<NativeBindingObject>); |
| 158 | +typedef DartIsNativeBindingObjectDisposed = bool Function(Pointer<NativeBindingObject>); |
| 159 | + |
| 160 | +final DartIsNativeBindingObjectDisposed _isNativeBindingObjectDisposed = WebFDynamicLibrary.ref |
| 161 | + .lookup<NativeFunction<NativeIsNativeBindingObjectDisposed>>('isNativeBindingObjectDisposed') |
| 162 | + .asFunction(); |
| 163 | + |
129 | 164 | Pointer<NativeBindingObject> allocateNewBindingObject() {
|
130 |
| - Pointer<NativeBindingObject> pointer = malloc.allocate(sizeOf<NativeBindingObject>()); |
131 |
| - pointer.ref.disposed = false; |
132 |
| - return pointer; |
| 165 | + return _allocateNativeBindingObject(); |
| 166 | +} |
| 167 | + |
| 168 | +bool isBindingObjectDisposed(Pointer<NativeBindingObject>? nativeBindingObject) { |
| 169 | + if (nativeBindingObject == null) return true; |
| 170 | + return _isNativeBindingObjectDisposed(nativeBindingObject); |
133 | 171 | }
|
134 | 172 |
|
135 | 173 | class NativePerformanceEntry extends Struct {
|
|
0 commit comments