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

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

Issue 23637014: Have V8HiddenPropertyName static functions take an isolate in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
« no previous file with comments | « Source/bindings/v8/V8ErrorHandler.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class Frame; 42 class Frame;
43 43
44 enum ListenerLookupType { 44 enum ListenerLookupType {
45 ListenerFindOnly, 45 ListenerFindOnly,
46 ListenerFindOrCreate, 46 ListenerFindOrCreate,
47 }; 47 };
48 48
49 // This is a container for V8EventListener objects that uses hidden properties o f v8::Object to speed up lookups. 49 // This is a container for V8EventListener objects that uses hidden properties o f v8::Object to speed up lookups.
50 class V8EventListenerList { 50 class V8EventListenerList {
51 public: 51 public:
52 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, b ool isAttribute) 52 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, b ool isAttribute, v8::Isolate* isolate)
53 { 53 {
54 ASSERT(v8::Context::InContext()); 54 ASSERT(v8::Context::InContext());
55 if (!value->IsObject()) 55 if (!value->IsObject())
56 return 0; 56 return 0;
57 57
58 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute); 58 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate);
59 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty ); 59 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate);
60 } 60 }
61 61
62 template<typename WrapperType> 62 template<typename WrapperType>
63 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>, bool isAttribute, v8::Isolate*); 63 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>, bool isAttribute, v8::Isolate*);
64 64
65 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri bute) 65 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri bute, v8::Isolate* isolate)
66 { 66 {
67 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute); 67 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate);
68 listenerObject->DeleteHiddenValue(wrapperProperty); 68 listenerObject->DeleteHiddenValue(wrapperProperty);
69 } 69 }
70 70
71 static PassRefPtr<EventListener> getEventListener(v8::Local<v8::Value>, bool isAttribute, ListenerLookupType); 71 static PassRefPtr<EventListener> getEventListener(v8::Local<v8::Value>, bool isAttribute, ListenerLookupType);
72 72
73 private: 73 private:
74 static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Hand le<v8::String> wrapperProperty) 74 static V8EventListener* doFindWrapper(v8::Local<v8::Object> object, v8::Hand le<v8::String> wrapperProperty, v8::Isolate* isolate)
75 { 75 {
76 ASSERT(v8::Context::InContext()); 76 ASSERT(v8::Context::InContext());
77 v8::HandleScope scope(v8::Isolate::GetCurrent()); 77 v8::HandleScope scope(isolate);
78 v8::Local<v8::Value> listener = object->GetHiddenValue(wrapperProperty); 78 v8::Local<v8::Value> listener = object->GetHiddenValue(wrapperProperty);
79 if (listener.IsEmpty()) 79 if (listener.IsEmpty())
80 return 0; 80 return 0;
81 return static_cast<V8EventListener*>(v8::External::Cast(*listener)->Valu e()); 81 return static_cast<V8EventListener*>(v8::External::Cast(*listener)->Valu e());
82 } 82 }
83 83
84 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute) 84 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate)
85 { 85 {
86 return isAttribute ? V8HiddenPropertyName::attributeListener() : V8Hidde nPropertyName::listener(); 86 return isAttribute ? V8HiddenPropertyName::attributeListener(isolate) : V8HiddenPropertyName::listener(isolate);
87 } 87 }
88 }; 88 };
89 89
90 template<typename WrapperType> 90 template<typename WrapperType>
91 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v 8::Value> value, bool isAttribute, v8::Isolate* isolate) 91 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v 8::Value> value, bool isAttribute, v8::Isolate* isolate)
92 { 92 {
93 ASSERT(v8::Context::InContext()); 93 ASSERT(v8::Context::InContext());
94 if (!value->IsObject()) 94 if (!value->IsObject())
95 return 0; 95 return 0;
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); 98 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate);
99 99
100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty); 100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate);
101 if (wrapper) 101 if (wrapper)
102 return wrapper; 102 return wrapper;
103 103
104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate); 104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate);
105 if (wrapperPtr) 105 if (wrapperPtr)
106 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ())); 106 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ()));
107 107
108 return wrapperPtr; 108 return wrapperPtr;
109 } 109 }
110 110
111 } // namespace WebCore 111 } // namespace WebCore
112 112
113 #endif // V8EventListenerList_h 113 #endif // V8EventListenerList_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8ErrorHandler.cpp ('k') | Source/bindings/v8/V8EventListenerList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698