| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, S
criptState* scriptState) | 49 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, S
criptState* scriptState) |
| 50 { | 50 { |
| 51 ASSERT(scriptState->isolate()->InContext()); | 51 ASSERT(scriptState->isolate()->InContext()); |
| 52 if (!value->IsObject()) | 52 if (!value->IsObject()) |
| 53 return nullptr; | 53 return nullptr; |
| 54 | 54 |
| 55 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(false, script
State->isolate()); | 55 v8::Local<v8::String> wrapperProperty = getHiddenProperty(false, scriptS
tate->isolate()); |
| 56 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty
, scriptState); | 56 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty
, scriptState); |
| 57 } | 57 } |
| 58 | 58 |
| 59 template<typename WrapperType> | 59 template<typename WrapperType> |
| 60 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>,
bool isAttribute, ScriptState*); | 60 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>,
bool isAttribute, ScriptState*); |
| 61 | 61 |
| 62 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri
bute, v8::Isolate* isolate) | 62 static void clearWrapper(v8::Local<v8::Object> listenerObject, bool isAttrib
ute, v8::Isolate* isolate) |
| 63 { | 63 { |
| 64 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute,
isolate); | 64 v8::Local<v8::String> wrapperProperty = getHiddenProperty(isAttribute, i
solate); |
| 65 listenerObject->DeleteHiddenValue(wrapperProperty); | 65 listenerObject->DeleteHiddenValue(wrapperProperty); |
| 66 } | 66 } |
| 67 | 67 |
| 68 CORE_EXPORT static PassRefPtr<EventListener> getEventListener(ScriptState*,
v8::Local<v8::Value>, bool isAttribute, ListenerLookupType); | 68 CORE_EXPORT static PassRefPtr<EventListener> getEventListener(ScriptState*,
v8::Local<v8::Value>, bool isAttribute, ListenerLookupType); |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Hand
le<v8::String> wrapperProperty, ScriptState* scriptState) | 71 static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Loca
l<v8::String> wrapperProperty, ScriptState* scriptState) |
| 72 { | 72 { |
| 73 v8::HandleScope scope(scriptState->isolate()); | 73 v8::HandleScope scope(scriptState->isolate()); |
| 74 ASSERT(scriptState->isolate()->InContext()); | 74 ASSERT(scriptState->isolate()->InContext()); |
| 75 v8::Local<v8::Value> listener = object->GetHiddenValue(wrapperProperty); | 75 v8::Local<v8::Value> listener = object->GetHiddenValue(wrapperProperty); |
| 76 if (listener.IsEmpty()) | 76 if (listener.IsEmpty()) |
| 77 return 0; | 77 return 0; |
| 78 return static_cast<V8EventListener*>(v8::External::Cast(*listener)->Valu
e()); | 78 return static_cast<V8EventListener*>(v8::External::Cast(*listener)->Valu
e()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8:
:Isolate* isolate) | 81 static inline v8::Local<v8::String> getHiddenProperty(bool isAttribute, v8::
Isolate* isolate) |
| 82 { | 82 { |
| 83 return isAttribute ? v8AtomicString(isolate, "EventListenerList::attribu
teListener") : v8AtomicString(isolate, "EventListenerList::listener"); | 83 return isAttribute ? v8AtomicString(isolate, "EventListenerList::attribu
teListener") : v8AtomicString(isolate, "EventListenerList::listener"); |
| 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, ScriptState* scriptState) | 88 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v
8::Value> value, bool isAttribute, ScriptState* scriptState) |
| 89 { | 89 { |
| 90 v8::Isolate* isolate = scriptState->isolate(); | 90 v8::Isolate* isolate = scriptState->isolate(); |
| 91 ASSERT(isolate->InContext()); | 91 ASSERT(isolate->InContext()); |
| 92 if (!value->IsObject() | 92 if (!value->IsObject() |
| 93 // Non-callable attribute setter input is treated as null (no wrapper) | 93 // Non-callable attribute setter input is treated as null (no wrapper) |
| 94 || (isAttribute && !value->IsFunction())) | 94 || (isAttribute && !value->IsFunction())) |
| 95 return nullptr; | 95 return nullptr; |
| 96 | 96 |
| 97 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | 97 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); |
| 98 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol
ate); | 98 v8::Local<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isola
te); |
| 99 | 99 |
| 100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, scriptStat
e); | 100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, scriptStat
e); |
| 101 if (wrapper) | 101 if (wrapper) |
| 102 return wrapper; | 102 return wrapper; |
| 103 | 103 |
| 104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute
, scriptState); | 104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute
, scriptState); |
| 105 if (wrapperPtr) | 105 if (wrapperPtr) |
| 106 object->SetHiddenValue(wrapperProperty, v8::External::New(isolate, wrapp
erPtr.get())); | 106 object->SetHiddenValue(wrapperProperty, v8::External::New(isolate, wrapp
erPtr.get())); |
| 107 | 107 |
| 108 return wrapperPtr; | 108 return wrapperPtr; |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace blink | 111 } // namespace blink |
| 112 | 112 |
| 113 #endif // V8EventListenerList_h | 113 #endif // V8EventListenerList_h |
| OLD | NEW |