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

Side by Side Diff: Source/bindings/dart/DartDOMWrapper.h

Issue 23895004: Keep a persistent handle for the bindings classes to avoid repeated lookups that involve performing… (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: preassign Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include <wtf/text/AtomicString.h> 44 #include <wtf/text/AtomicString.h>
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 enum {
55 DOMStringMapBindingCid = 0,
56 NumCustomBindingCids
57 };
58
54 template <class WebKitClass> 59 template <class WebKitClass>
55 static Dart_Handle newWrapper(const char* className, const char* libraryName , WebKitClass* domObject) 60 static Dart_Handle newWrapper(const char* className, const char* libraryName , WebKitClass* domObject)
56 { 61 {
57 Dart_Handle wrapper = instantiateWrapper(className, libraryName); 62 Dart_Handle wrapper = instantiateWrapper(className, libraryName);
58 writeNativePointer(wrapper, kNativeImplementationIndex, domObject); 63 writeNativePointer(wrapper, kNativeImplementationIndex, domObject);
59 return wrapper; 64 return wrapper;
60 } 65 }
61 66
62 template <class BindingsClass> 67 template <class BindingsClass>
63 static Dart_Handle toDart(typename BindingsClass::NativeType* domObject) 68 static Dart_Handle toDart(typename BindingsClass::NativeType* domObject)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 174 }
170 175
171 template <class BindingsClass> 176 template <class BindingsClass>
172 static typename BindingsClass::NativeType* unwrapDartWrapper(Dart_NativeArgu ments args, int index, Dart_Handle& exception) 177 static typename BindingsClass::NativeType* unwrapDartWrapper(Dart_NativeArgu ments args, int index, Dart_Handle& exception)
173 { 178 {
174 ASSERT(!exception); 179 ASSERT(!exception);
175 Dart_Handle wrapper = Dart_GetNativeArgument(args, index); 180 Dart_Handle wrapper = Dart_GetNativeArgument(args, index);
176 return unwrapDartWrapper<BindingsClass>(wrapper, exception); 181 return unwrapDartWrapper<BindingsClass>(wrapper, exception);
177 } 182 }
178 183
184 static intptr_t nextClassIndex;
siva 2013/09/10 00:18:50 Not used anymore right, could be deleted.
rmacnak 2013/09/10 20:09:51 Removed.
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 ASSERT(!Dart_IsError(result));
194 if (Dart_IsError(result))
195 return false;
siva 2013/09/10 00:18:50 Seems to assert and check, I think the ASSERT is n
rmacnak 2013/09/10 20:09:51 Removed.
196 return isInstanceOf;
197 }
198
199 template <class BindingsClass>
200 static Dart_Handle dartClass()
siva 2013/09/10 00:18:50 This can also be private right.
rmacnak 2013/09/10 20:09:51 Hidden.
201 {
202 return dartClass(BindingsClass::dartImplementationClassName, BindingsCla ss::dartImplementationLibraryName, BindingsClass::kBindingCid);
183 } 203 }
184 204
185 template <class WebKitClass> 205 template <class WebKitClass>
186 static WebKitClass* receiver(Dart_NativeArguments args) 206 static WebKitClass* receiver(Dart_NativeArguments args)
187 { 207 {
188 // Type of receiver is ensured by Dart VM runtime, so bypass additional checks. 208 // Type of receiver is ensured by Dart VM runtime, so bypass additional checks.
189 intptr_t value = 0; 209 intptr_t value = 0;
190 ASSERT(!kNativeImplementationIndex); 210 ASSERT(!kNativeImplementationIndex);
191 Dart_Handle result = Dart_GetNativeReceiver(args, &value); 211 Dart_Handle result = Dart_GetNativeReceiver(args, &value);
192 ASSERT(!Dart_IsError(result)); 212 ASSERT(!Dart_IsError(result));
(...skipping 21 matching lines...) Expand all
214 static Dart_Handle exceptionCodeToDartException(ExceptionCode); 234 static Dart_Handle exceptionCodeToDartException(ExceptionCode);
215 static Dart_Handle exceptionCodeToDartException(DartExceptionState&); 235 static Dart_Handle exceptionCodeToDartException(DartExceptionState&);
216 236
217 private: 237 private:
218 enum NativeFieldIndices { 238 enum NativeFieldIndices {
219 kNativeImplementationIndex = 0, 239 kNativeImplementationIndex = 0,
220 kNativeFieldCount 240 kNativeFieldCount
221 }; 241 };
222 242
223 static Dart_Handle instantiateWrapper(const char* className, const char* lib raryName); 243 static Dart_Handle instantiateWrapper(const char* className, const char* lib raryName);
224 static bool instanceOf(const char* dartImplementationClassName, 244 static Dart_Handle dartClass(const char* dartImplementationClassName,
225 const char* dartImplementationLibraryName, Dart_Handle wrapper); 245 const char* dartImplementationLibraryName, intptr_t classIndex);
226 246
227 static void writeNativePointer(Dart_Handle wrapper, int index, void* pointer ) 247 static void writeNativePointer(Dart_Handle wrapper, int index, void* pointer )
228 { 248 {
229 DartApiScope scope; 249 DartApiScope scope;
230 Dart_Handle result = Dart_SetNativeInstanceField(wrapper, index, reinter pret_cast<intptr_t>(pointer)); 250 Dart_Handle result = Dart_SetNativeInstanceField(wrapper, index, reinter pret_cast<intptr_t>(pointer));
231 UNUSED_PARAM(result); 251 UNUSED_PARAM(result);
232 ASSERT(!Dart_IsError(result)); 252 ASSERT(!Dart_IsError(result));
233 } 253 }
234 254
235 static void* readNativePointer(Dart_Handle wrapper, int index) 255 static void* readNativePointer(Dart_Handle wrapper, int index)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData ->messagePortMap(); } 354 static DartMessagePortMap* domMap(DartDOMData* domData) { return domData ->messagePortMap(); }
335 }; 355 };
336 typedef MessagePortMapTraits MapTraits; 356 typedef MessagePortMapTraits MapTraits;
337 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits; 357 typedef DartDOMWrapperActiveTraits<DartMessagePort, false> ActiveTraits;
338 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr aits; 358 typedef DartDOMWrapperEventTargetTraits<DartMessagePort, true> EventTargetTr aits;
339 }; 359 };
340 360
341 } 361 }
342 362
343 #endif // DartDOMWrapper_h 363 #endif // DartDOMWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698