| OLD | NEW |
| 1 // Copyright 2011, Google Inc. | 1 // Copyright 2011, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include <wtf/text/WTFString.h> | 45 #include <wtf/text/WTFString.h> |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 template<class BindingsClass> | 49 template<class BindingsClass> |
| 50 struct DartDOMWrapperTraits; | 50 struct DartDOMWrapperTraits; |
| 51 | 51 |
| 52 class DartDOMWrapper { | 52 class DartDOMWrapper { |
| 53 public: | 53 public: |
| 54 template <class WebKitClass> | 54 template <class WebKitClass> |
| 55 static Dart_Handle newWrapper(const char* className, const char* libraryName
, WebKitClass* domObject) | 55 static Dart_Handle newWrapper(const char* className, const char* libraryName
, intptr_t cid, WebKitClass* domObject) |
| 56 { | 56 { |
| 57 Dart_Handle wrapper = instantiateWrapper(className, libraryName); | 57 |
| 58 Dart_Handle type = dartClass(className, libraryName, cid); |
| 59 ASSERT(!Dart_IsError(type)); |
| 60 Dart_Handle wrapper = Dart_Allocate(type); |
| 58 writeNativePointer(wrapper, kNativeImplementationIndex, domObject); | 61 writeNativePointer(wrapper, kNativeImplementationIndex, domObject); |
| 59 return wrapper; | 62 return wrapper; |
| 60 } | 63 } |
| 61 | 64 |
| 62 template <class BindingsClass> | 65 template <class BindingsClass> |
| 63 static Dart_Handle toDart(typename BindingsClass::NativeType* domObject) | 66 static Dart_Handle toDart(typename BindingsClass::NativeType* domObject) |
| 64 { | 67 { |
| 65 return toDartWithClassName<BindingsClass>(domObject, BindingsClass::dart
ImplementationClassName, BindingsClass::dartImplementationLibraryName); | 68 return toDartWithClassName<BindingsClass>( |
| 69 domObject, |
| 70 BindingsClass::dartImplementationClassName, |
| 71 BindingsClass::dartImplementationLibraryName, |
| 72 BindingsClass::dartClassId); |
| 66 } | 73 } |
| 67 | 74 |
| 68 template <class BindingsClass> | 75 template <class BindingsClass> |
| 69 static Dart_Handle toDartWithClassName(typename BindingsClass::NativeType* d
omObject, | 76 static Dart_Handle toDartWithClassName(typename BindingsClass::NativeType* d
omObject, |
| 70 const char* className, const char* libraryName) | 77 const char* className, const char* libraryName, intptr_t cid) |
| 71 { | 78 { |
| 72 typedef DartDOMWrapperTraits<BindingsClass> Traits; | 79 typedef DartDOMWrapperTraits<BindingsClass> Traits; |
| 73 | 80 |
| 74 if (!domObject) | 81 if (!domObject) |
| 75 return Dart_Null(); | 82 return Dart_Null(); |
| 76 | 83 |
| 77 Dart_Handle oldInstance = lookupWrapper<BindingsClass>(domObject); | 84 Dart_Handle oldInstance = lookupWrapper<BindingsClass>(domObject); |
| 78 if (oldInstance) | 85 if (oldInstance) |
| 79 return oldInstance; | 86 return oldInstance; |
| 80 | 87 |
| 81 Dart_Handle newInstance = newWrapper(className, libraryName, domObject); | 88 Dart_Handle newInstance = newWrapper(className, libraryName, cid, domObj
ect); |
| 82 return associateWrapper<BindingsClass>(domObject, newInstance); | 89 return associateWrapper<BindingsClass>(domObject, newInstance); |
| 83 } | 90 } |
| 84 | 91 |
| 85 template <class BindingsClass> | 92 template <class BindingsClass> |
| 86 static Dart_Handle lookupWrapper(typename BindingsClass::NativeType* domObje
ct) | 93 static Dart_Handle lookupWrapper(typename BindingsClass::NativeType* domObje
ct) |
| 87 { | 94 { |
| 88 typedef DartDOMWrapperTraits<BindingsClass> Traits; | 95 typedef DartDOMWrapperTraits<BindingsClass> Traits; |
| 89 | 96 |
| 90 DartDOMData* domData = DartDOMData::current(); | 97 DartDOMData* domData = DartDOMData::current(); |
| 91 Dart_WeakPersistentHandle wrapper = Traits::MapTraits::domMap(domData)->
get(domObject); | 98 Dart_WeakPersistentHandle wrapper = Traits::MapTraits::domMap(domData)->
get(domObject); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 static typename BindingsClass::NativeType* unwrapDartWrapper(Dart_NativeArgu
ments args, int index, Dart_Handle& exception) | 179 static typename BindingsClass::NativeType* unwrapDartWrapper(Dart_NativeArgu
ments args, int index, Dart_Handle& exception) |
| 173 { | 180 { |
| 174 ASSERT(!exception); | 181 ASSERT(!exception); |
| 175 Dart_Handle wrapper = Dart_GetNativeArgument(args, index); | 182 Dart_Handle wrapper = Dart_GetNativeArgument(args, index); |
| 176 return unwrapDartWrapper<BindingsClass>(wrapper, exception); | 183 return unwrapDartWrapper<BindingsClass>(wrapper, exception); |
| 177 } | 184 } |
| 178 | 185 |
| 179 template <class BindingsClass> | 186 template <class BindingsClass> |
| 180 static bool instanceOf(Dart_Handle wrapper) | 187 static bool instanceOf(Dart_Handle wrapper) |
| 181 { | 188 { |
| 182 return instanceOf(BindingsClass::dartImplementationClassName, BindingsCl
ass::dartImplementationLibraryName, wrapper); | 189 Dart_Handle type = dartClass<BindingsClass>(); |
| 190 |
| 191 bool isInstanceOf = false; |
| 192 Dart_Handle result = Dart_ObjectIsType(wrapper, type, &isInstanceOf); |
| 193 if (Dart_IsError(result)) |
| 194 return false; |
| 195 return isInstanceOf; |
| 183 } | 196 } |
| 184 | 197 |
| 185 template <class WebKitClass> | 198 template <class WebKitClass> |
| 186 static WebKitClass* receiver(Dart_NativeArguments args) | 199 static WebKitClass* receiver(Dart_NativeArguments args) |
| 187 { | 200 { |
| 188 // Type of receiver is ensured by Dart VM runtime, so bypass additional
checks. | 201 // Type of receiver is ensured by Dart VM runtime, so bypass additional
checks. |
| 189 intptr_t value = 0; | 202 intptr_t value = 0; |
| 190 ASSERT(!kNativeImplementationIndex); | 203 ASSERT(!kNativeImplementationIndex); |
| 191 Dart_Handle result = Dart_GetNativeReceiver(args, &value); | 204 Dart_Handle result = Dart_GetNativeReceiver(args, &value); |
| 192 ASSERT(!Dart_IsError(result)); | 205 ASSERT(!Dart_IsError(result)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 213 | 226 |
| 214 static Dart_Handle exceptionCodeToDartException(ExceptionCode); | 227 static Dart_Handle exceptionCodeToDartException(ExceptionCode); |
| 215 static Dart_Handle exceptionCodeToDartException(DartExceptionState&); | 228 static Dart_Handle exceptionCodeToDartException(DartExceptionState&); |
| 216 | 229 |
| 217 private: | 230 private: |
| 218 enum NativeFieldIndices { | 231 enum NativeFieldIndices { |
| 219 kNativeImplementationIndex = 0, | 232 kNativeImplementationIndex = 0, |
| 220 kNativeFieldCount | 233 kNativeFieldCount |
| 221 }; | 234 }; |
| 222 | 235 |
| 223 static Dart_Handle instantiateWrapper(const char* className, const char* lib
raryName); | 236 static Dart_Handle dartClass(const char* dartImplementationClassName, |
| 224 static bool instanceOf(const char* dartImplementationClassName, | 237 const char* dartImplementationLibraryName, intptr_t classIndex); |
| 225 const char* dartImplementationLibraryName, Dart_Handle wrapper); | 238 |
| 239 template <class BindingsClass> |
| 240 static Dart_Handle dartClass() |
| 241 { |
| 242 return dartClass(BindingsClass::dartImplementationClassName, BindingsCla
ss::dartImplementationLibraryName, BindingsClass::dartClassId); |
| 243 } |
| 226 | 244 |
| 227 static void writeNativePointer(Dart_Handle wrapper, int index, void* pointer
) | 245 static void writeNativePointer(Dart_Handle wrapper, int index, void* pointer
) |
| 228 { | 246 { |
| 229 DartApiScope scope; | 247 DartApiScope scope; |
| 230 Dart_Handle result = Dart_SetNativeInstanceField(wrapper, index, reinter
pret_cast<intptr_t>(pointer)); | 248 Dart_Handle result = Dart_SetNativeInstanceField(wrapper, index, reinter
pret_cast<intptr_t>(pointer)); |
| 231 UNUSED_PARAM(result); | 249 UNUSED_PARAM(result); |
| 232 ASSERT(!Dart_IsError(result)); | 250 ASSERT(!Dart_IsError(result)); |
| 233 } | 251 } |
| 234 | 252 |
| 235 static void* readNativePointer(Dart_Handle wrapper, int index) | 253 static void* readNativePointer(Dart_Handle wrapper, int index) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData
->messagePortMap(); } | 352 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData
->messagePortMap(); } |
| 335 }; | 353 }; |
| 336 typedef MessagePortMapTraits MapTraits; | 354 typedef MessagePortMapTraits MapTraits; |
| 337 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits; | 355 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits; |
| 338 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr
aits; | 356 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr
aits; |
| 339 }; | 357 }; |
| 340 | 358 |
| 341 } | 359 } |
| 342 | 360 |
| 343 #endif // DartDOMWrapper_h | 361 #endif // DartDOMWrapper_h |
| OLD | NEW |