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

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

Issue 32323012: IDL compiler: move EventHandler null check out of generated bindings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, b ool isAttribute, v8::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);
55 if (!value->IsObject()) 58 if (!value->IsObject())
56 return 0; 59 return 0;
57 60
58 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate); 61 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isolate);
59 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate); 62 return doFindWrapper(v8::Local<v8::Object>::Cast(value), wrapperProperty , isolate);
60 } 63 }
61 64
62 template<typename WrapperType> 65 template<typename WrapperType>
63 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>, bool isAttribute, v8::Isolate*); 66 static PassRefPtr<V8EventListener> findOrCreateWrapper(v8::Local<v8::Value>, bool isAttribute, v8::Isolate*);
64 67
(...skipping 19 matching lines...) Expand all
84 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate) 87 static inline v8::Handle<v8::String> getHiddenProperty(bool isAttribute, v8: :Isolate* isolate)
85 { 88 {
86 return isAttribute ? V8HiddenPropertyName::attributeListener(isolate) : V8HiddenPropertyName::listener(isolate); 89 return isAttribute ? V8HiddenPropertyName::attributeListener(isolate) : V8HiddenPropertyName::listener(isolate);
87 } 90 }
88 }; 91 };
89 92
90 template<typename WrapperType> 93 template<typename WrapperType>
91 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v 8::Value> value, bool isAttribute, v8::Isolate* isolate) 94 PassRefPtr<V8EventListener> V8EventListenerList::findOrCreateWrapper(v8::Local<v 8::Value> value, bool isAttribute, v8::Isolate* isolate)
92 { 95 {
93 ASSERT(v8::Context::InContext()); 96 ASSERT(v8::Context::InContext());
97 // Non-callable attribute setter input should be treated as null
98 if (isAttribute && !value->IsNull() && !value->IsFunction())
Nils Barth (inactive) 2013/10/22 07:29:29 Note the isAttribute check. isAttribute is true fo
99 value = v8::Null(isolate);
94 if (!value->IsObject()) 100 if (!value->IsObject())
95 return 0; 101 return 0;
96 102
97 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 103 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
98 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate); 104 v8::Handle<v8::String> wrapperProperty = getHiddenProperty(isAttribute, isol ate);
99 105
100 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate); 106 V8EventListener* wrapper = doFindWrapper(object, wrapperProperty, isolate);
101 if (wrapper) 107 if (wrapper)
102 return wrapper; 108 return wrapper;
103 109
104 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate); 110 RefPtr<V8EventListener> wrapperPtr = WrapperType::create(object, isAttribute , isolate);
105 if (wrapperPtr) 111 if (wrapperPtr)
106 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ())); 112 object->SetHiddenValue(wrapperProperty, v8::External::New(wrapperPtr.get ()));
107 113
108 return wrapperPtr; 114 return wrapperPtr;
109 } 115 }
110 116
111 } // namespace WebCore 117 } // namespace WebCore
112 118
113 #endif // V8EventListenerList_h 119 #endif // V8EventListenerList_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698