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

Side by Side Diff: Source/bindings/v8/V8EventListenerList.h

Issue 293053007: V8AbstractEventListener should hold a ScriptState (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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
« no previous file with comments | « Source/bindings/v8/V8EventListener.cpp ('k') | Source/bindings/v8/V8EventListenerList.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 28 matching lines...) Expand all
39 class LocalFrame; 39 class LocalFrame;
40 40
41 enum ListenerLookupType { 41 enum ListenerLookupType {
42 ListenerFindOnly, 42 ListenerFindOnly,
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, S criptState* scriptState)
50 { 50 {
51 ASSERT(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, isolat e); 55 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(false, script State->isolate());
56 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate); 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, v8::Isolate*); 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::Handle<v8::Object> listenerObject, bool isAttri bute, v8::Isolate* isolate)
63 { 63 {
64 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate); 64 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate);
65 listenerObject->DeleteHiddenValue(wrapperProperty); 65 listenerObject->DeleteHiddenValue(wrapperProperty);
66 } 66 }
67 67
68 static PassRefPtr<EventListener> getEventListener(ScriptState*, v8::Local<v8 ::Value>, bool isAttribute, ListenerLookupType); 68 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, v8::Isolate* isolate) 71 static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Hand le<v8::String> wrapperProperty, ScriptState* scriptState)
72 { 72 {
73 ASSERT(isolate->InContext()); 73 v8::HandleScope scope(scriptState->isolate());
74 v8::HandleScope scope(isolate); 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::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate)
82 { 82 {
83 return isAttribute ? v8AtomicString(isolate, "attributeListener") : v8At omicString(isolate, "listener"); 83 return isAttribute ? v8AtomicString(isolate, "attributeListener") : v8At omicString(isolate, "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, v8::Isolate* isolate) 88 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v 8::Value> value, bool isAttribute, ScriptState* scriptState)
89 { 89 {
90 v8::Isolate* isolate = scriptState->isolate();
90 ASSERT(isolate->InContext()); 91 ASSERT(isolate->InContext());
91 if (!value->IsObject() 92 if (!value->IsObject()
92 // Non-callable attribute setter input is treated as null (no wrapper) 93 // Non-callable attribute setter input is treated as null (no wrapper)
93 || (isAttribute && !value->IsFunction())) 94 || (isAttribute && !value->IsFunction()))
94 return nullptr; 95 return nullptr;
95 96
96 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 97 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
97 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate); 98 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate);
98 99
99 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate); 100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, scriptStat e);
100 if (wrapper) 101 if (wrapper)
101 return wrapper; 102 return wrapper;
102 103
103 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate); 104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , scriptState);
104 if (wrapperPtr) 105 if (wrapperPtr)
105 object->SetHiddenValue(wrapperProperty, v8::External::New(isolate, wrapp erPtr.get())); 106 object->SetHiddenValue(wrapperProperty, v8::External::New(isolate, wrapp erPtr.get()));
106 107
107 return wrapperPtr; 108 return wrapperPtr;
108 } 109 }
109 110
110 } // namespace WebCore 111 } // namespace WebCore
111 112
112 #endif // V8EventListenerList_h 113 #endif // V8EventListenerList_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8EventListener.cpp ('k') | Source/bindings/v8/V8EventListenerList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698