Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 135 |
| 136 template <class BindingsClass> | 136 template <class BindingsClass> |
| 137 static typename BindingsClass::NativeType* unwrapDartWrapper( | 137 static typename BindingsClass::NativeType* unwrapDartWrapper( |
| 138 DartDOMData* domData, Dart_Handle wrapper, Dart_Handle& exception) | 138 DartDOMData* domData, Dart_Handle wrapper, Dart_Handle& exception) |
| 139 { | 139 { |
| 140 ASSERT(!exception); | 140 ASSERT(!exception); |
| 141 | 141 |
| 142 if (Dart_IsNull(wrapper)) | 142 if (Dart_IsNull(wrapper)) |
| 143 return 0; | 143 return 0; |
| 144 | 144 |
| 145 // FIXME: support cross-domain wrappers. | 145 if (!subtypeOf<BindingsClass>(domData, wrapper)) { |
| 146 if (!instanceOf<BindingsClass>(domData, wrapper)) { | |
| 147 String message = String("Invalid class: expected instance of ") + Bi ndingsClass::dartImplementationClassName; | 146 String message = String("Invalid class: expected instance of ") + Bi ndingsClass::dartImplementationClassName; |
| 148 exception = DartUtilities::stringToDartString(message); | 147 exception = DartUtilities::stringToDartString(message); |
| 149 return 0; | 148 return 0; |
| 150 } | 149 } |
| 151 void* nativePointer = readNativePointer(wrapper, kNativeImplementationIn dex); | 150 void* nativePointer = readNativePointer(wrapper, kNativeImplementationIn dex); |
| 152 return static_cast<typename BindingsClass::NativeType*>(nativePointer); | 151 return static_cast<typename BindingsClass::NativeType*>(nativePointer); |
| 153 } | 152 } |
| 154 | 153 |
| 155 template <class BindingsClass> | 154 template <class BindingsClass> |
| 156 static typename BindingsClass::NativeType* unwrapDartWrapper( | 155 static typename BindingsClass::NativeType* unwrapDartWrapper( |
| 157 Dart_NativeArguments args, int index, Dart_Handle& exception) | 156 Dart_NativeArguments args, int index, Dart_Handle& exception) |
| 158 { | 157 { |
| 159 ASSERT(!exception); | 158 ASSERT(!exception); |
| 160 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa ta(args)); | 159 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa ta(args)); |
| 161 Dart_Handle wrapper = Dart_GetNativeArgument(args, index); | 160 Dart_Handle wrapper = Dart_GetNativeArgument(args, index); |
| 162 return unwrapDartWrapper<BindingsClass>(domData, wrapper, exception); | 161 return unwrapDartWrapper<BindingsClass>(domData, wrapper, exception); |
| 163 } | 162 } |
| 164 | 163 |
| 165 template <class BindingsClass> | 164 template <class BindingsClass> |
| 166 static bool instanceOf(DartDOMData* domData, Dart_Handle wrapper) | 165 static bool subtypeOf(DartDOMData* domData, Dart_Handle wrapper) |
| 167 { | 166 { |
| 168 Dart_PersistentHandle type = dartClass<BindingsClass>(domData); | 167 Dart_PersistentHandle type = dartClass<BindingsClass>(domData); |
| 169 | 168 |
| 170 bool isInstanceOf = false; | 169 bool isSubtypeOf = false; |
| 171 Dart_Handle result = Dart_ObjectIsType(wrapper, type, &isInstanceOf); | 170 Dart_Handle result = Dart_InstanceIsSubtypeOf(wrapper, type, &isSubtypeO f); |
|
vsm
2013/10/14 15:44:09
Siva: Just curious, what's the semantic difference
siva
2013/10/14 15:55:06
Dart_InstanceIsSubtypeOf just does a straight sub
| |
| 172 return isInstanceOf; | 171 ASSERT(!Dart_IsError(result)); |
| 172 return isSubtypeOf; | |
| 173 } | 173 } |
| 174 | 174 |
| 175 template <class WebKitClass> | 175 template <class WebKitClass> |
| 176 static WebKitClass* receiver(Dart_NativeArguments args) | 176 static WebKitClass* receiver(Dart_NativeArguments args) |
| 177 { | 177 { |
| 178 // Type of receiver is ensured by Dart VM runtime, so bypass additional checks. | 178 // Type of receiver is ensured by Dart VM runtime, so bypass additional checks. |
| 179 intptr_t value = 0; | 179 intptr_t value = 0; |
| 180 ASSERT(!kNativeImplementationIndex); | 180 ASSERT(!kNativeImplementationIndex); |
| 181 Dart_Handle result = Dart_GetNativeReceiver(args, &value); | 181 Dart_Handle result = Dart_GetNativeReceiver(args, &value); |
| 182 ASSERT(!Dart_IsError(result)); | 182 ASSERT(!Dart_IsError(result)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData ->messagePortMap(); } | 372 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData ->messagePortMap(); } |
| 373 }; | 373 }; |
| 374 typedef MessagePortMapTraits MapTraits; | 374 typedef MessagePortMapTraits MapTraits; |
| 375 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits; | 375 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits; |
| 376 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr aits; | 376 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr aits; |
| 377 }; | 377 }; |
| 378 | 378 |
| 379 } | 379 } |
| 380 | 380 |
| 381 #endif // DartDOMWrapper_h | 381 #endif // DartDOMWrapper_h |
| OLD | NEW |