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

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

Issue 34393005: IDL compiler: merge and simplify EventHandler non-callable value check (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Comment (reupload) Created 7 years, 2 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 | « no previous file | 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, v8::Isolate* isolate) 52 static PassRefPtr<V8EventListener> findWrapper(v8::Local<v8::Value> value, v 8::Isolate* isolate)
53 { 53 {
54 ASSERT(v8::Context::InContext()); 54 ASSERT(v8::Context::InContext());
55 // Non-callable input should be treated as null
56 if (!value->IsNull() && !value->IsFunction())
57 value = v8::Null(isolate);
58 if (!value->IsObject()) 55 if (!value->IsObject())
59 return 0; 56 return 0;
60 57
61 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate); 58 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(false, isolat e);
62 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate); 59 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate);
63 } 60 }
64 61
65 template<typename WrapperType> 62 template<typename WrapperType>
66 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*);
67 64
68 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri bute, v8::Isolate* isolate) 65 static void clearWrapper(v8::Handle<v8::Object> listenerObject, bool isAttri bute, v8::Isolate* isolate)
69 { 66 {
70 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate); 67 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate);
71 listenerObject->DeleteHiddenValue(wrapperProperty); 68 listenerObject->DeleteHiddenValue(wrapperProperty);
(...skipping 15 matching lines...) Expand all
87 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate) 84 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate)
88 { 85 {
89 return isAttribute ? V8HiddenPropertyName::attributeListener(isolate) : V8HiddenPropertyName::listener(isolate); 86 return isAttribute ? V8HiddenPropertyName::attributeListener(isolate) : V8HiddenPropertyName::listener(isolate);
90 } 87 }
91 }; 88 };
92 89
93 template<typename WrapperType> 90 template<typename WrapperType>
94 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)
95 { 92 {
96 ASSERT(v8::Context::InContext()); 93 ASSERT(v8::Context::InContext());
97 // Non-callable attribute setter input should be treated as null 94 if (!value->IsObject()
98 if (isAttribute && !value->IsNull() && !value->IsFunction()) 95 // Non-callable attribute setter input is treated as null (no wrapper)
99 value = v8::Null(isolate); 96 || (isAttribute && !value->IsFunction()))
100 if (!value->IsObject())
101 return 0; 97 return 0;
102 98
103 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 99 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
104 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate); 100 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate);
105 101
106 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate); 102 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate);
107 if (wrapper) 103 if (wrapper)
108 return wrapper; 104 return wrapper;
109 105
110 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate); 106 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate);
111 if (wrapperPtr) 107 if (wrapperPtr)
112 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ())); 108 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ()));
113 109
114 return wrapperPtr; 110 return wrapperPtr;
115 } 111 }
116 112
117 } // namespace WebCore 113 } // namespace WebCore
118 114
119 #endif // V8EventListenerList_h 115 #endif // V8EventListenerList_h
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/V8EventListenerList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698