| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ListenerFindOrCreate, | 43 ListenerFindOrCreate, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // This is a container for V8EventListener objects that uses hidden properties o
f v8::Object to speed up lookups. | 46 // This is a container for V8EventListener objects that uses hidden properties o
f v8::Object to speed up lookups. |
| 47 class V8EventListenerList { | 47 class V8EventListenerList { |
| 48 public: | 48 public: |
| 49 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, v
8::Isolate* isolate) | 49 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, v
8::Isolate* isolate) |
| 50 { | 50 { |
| 51 ASSERT(isolate->InContext()); | 51 ASSERT(isolate->InContext()); |
| 52 if (!value->IsObject()) | 52 if (!value->IsObject()) |
| 53 return 0; | 53 return nullptr; |
| 54 | 54 |
| 55 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(false, isolat
e); | 55 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(false, isolat
e); |
| 56 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty
, isolate); | 56 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty
, isolate); |
| 57 } | 57 } |
| 58 | 58 |
| 59 template<typename WrapperType> | 59 template<typename WrapperType> |
| 60 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>,
bool isAttribute, v8::Isolate*); | 60 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>,
bool isAttribute, v8::Isolate*); |
| 61 | 61 |
| 62 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri
bute, v8::Isolate* isolate) | 62 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri
bute, v8::Isolate* isolate) |
| 63 { | 63 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 } | 84 } |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 template<typename WrapperType> | 87 template<typename WrapperType> |
| 88 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v
8::Value> value, bool isAttribute, v8::Isolate* isolate) | 88 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v
8::Value> value, bool isAttribute, v8::Isolate* isolate) |
| 89 { | 89 { |
| 90 ASSERT(isolate->InContext()); | 90 ASSERT(isolate->InContext()); |
| 91 if (!value->IsObject() | 91 if (!value->IsObject() |
| 92 // Non-callable attribute setter input is treated as null (no wrapper) | 92 // Non-callable attribute setter input is treated as null (no wrapper) |
| 93 || (isAttribute && !value->IsFunction())) | 93 || (isAttribute && !value->IsFunction())) |
| 94 return 0; | 94 return nullptr; |
| 95 | 95 |
| 96 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | 96 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); |
| 97 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol
ate); | 97 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol
ate); |
| 98 | 98 |
| 99 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate); | 99 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate); |
| 100 if (wrapper) | 100 if (wrapper) |
| 101 return wrapper; | 101 return wrapper; |
| 102 | 102 |
| 103 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute
, isolate); | 103 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute
, isolate); |
| 104 if (wrapperPtr) | 104 if (wrapperPtr) |
| 105 setHiddenValue(isolate, object, wrapperProperty, v8::External::New(isola
te, wrapperPtr.get())); | 105 setHiddenValue(isolate, object, wrapperProperty, v8::External::New(isola
te, wrapperPtr.get())); |
| 106 | 106 |
| 107 return wrapperPtr; | 107 return wrapperPtr; |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace WebCore | 110 } // namespace WebCore |
| 111 | 111 |
| 112 #endif // V8EventListenerList_h | 112 #endif // V8EventListenerList_h |
| OLD | NEW |