| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 This file is part of the WebKit open source project. | |
| 3 This file has been generated by generate-bindings.pl. DO NOT MODIFY! | |
| 4 | |
| 5 This library is free software; you can redistribute it and/or | |
| 6 modify it under the terms of the GNU Library General Public | |
| 7 License as published by the Free Software Foundation; either | |
| 8 version 2 of the License, or (at your option) any later version. | |
| 9 | |
| 10 This library is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 Library General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU Library General Public License | |
| 16 along with this library; see the file COPYING.LIB. If not, write to | |
| 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 18 Boston, MA 02111-1307, USA. | |
| 19 */ | |
| 20 | |
| 21 #include "config.h" | |
| 22 #include "V8TestEventTarget.h" | |
| 23 | |
| 24 #include "BindingState.h" | |
| 25 #include "ContextFeatures.h" | |
| 26 #include "ExceptionCode.h" | |
| 27 #include "Frame.h" | |
| 28 #include "RuntimeEnabledFeatures.h" | |
| 29 #include "V8Binding.h" | |
| 30 #include "V8Collection.h" | |
| 31 #include "V8DOMWrapper.h" | |
| 32 #include "V8Event.h" | |
| 33 #include "V8EventListenerList.h" | |
| 34 #include "V8Node.h" | |
| 35 #include <wtf/UnusedParam.h> | |
| 36 | |
| 37 #if ENABLE(BINDING_INTEGRITY) | |
| 38 #if defined(OS_WIN) | |
| 39 #pragma warning(disable: 4483) | |
| 40 extern "C" { extern void (*const __identifier("??_7TestEventTarget@WebCore@@6B@"
)[])(); } | |
| 41 #else | |
| 42 extern "C" { extern void* _ZTVN7WebCore15TestEventTargetE[]; } | |
| 43 #endif | |
| 44 #endif // ENABLE(BINDING_INTEGRITY) | |
| 45 | |
| 46 namespace WebCore { | |
| 47 | |
| 48 #if ENABLE(BINDING_INTEGRITY) | |
| 49 // This checks if a DOM object that is about to be wrapped is valid. | |
| 50 // Specifically, it checks that a vtable of the DOM object is equal to | |
| 51 // a vtable of an expected class. | |
| 52 // Due to a dangling pointer, the DOM object you are wrapping might be | |
| 53 // already freed or realloced. If freed, the check will fail because | |
| 54 // a free list pointer should be stored at the head of the DOM object. | |
| 55 // If realloced, the check will fail because the vtable of the DOM object | |
| 56 // differs from the expected vtable (unless the same class of DOM object | |
| 57 // is realloced on the slot). | |
| 58 inline void checkTypeOrDieTrying(TestEventTarget* object) | |
| 59 { | |
| 60 void* actualVTablePointer = *(reinterpret_cast<void**>(object)); | |
| 61 #if defined(OS_WIN) | |
| 62 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test
EventTarget@WebCore@@6B@")); | |
| 63 #else | |
| 64 void* expectedVTablePointer = &_ZTVN7WebCore15TestEventTargetE[2]; | |
| 65 #endif | |
| 66 if (actualVTablePointer != expectedVTablePointer) | |
| 67 CRASH(); | |
| 68 } | |
| 69 #endif // ENABLE(BINDING_INTEGRITY) | |
| 70 | |
| 71 WrapperTypeInfo V8TestEventTarget::info = { V8TestEventTarget::GetTemplate, V8Te
stEventTarget::derefObject, 0, V8TestEventTarget::toEventTarget, 0, V8TestEventT
arget::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype }; | |
| 72 | |
| 73 namespace TestEventTargetV8Internal { | |
| 74 | |
| 75 template <typename T> void V8_USE(T) { } | |
| 76 | |
| 77 static v8::Handle<v8::Value> itemMethod(const v8::Arguments& args) | |
| 78 { | |
| 79 if (args.Length() < 1) | |
| 80 return throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 81 TestEventTarget* imp = V8TestEventTarget::toNative(args.Holder()); | |
| 82 ExceptionCode ec = 0; | |
| 83 { | |
| 84 V8TRYCATCH(int, index, toUInt32(args[0])); | |
| 85 if (UNLIKELY(index < 0)) { | |
| 86 ec = INDEX_SIZE_ERR; | |
| 87 goto fail; | |
| 88 } | |
| 89 return toV8(imp->item(index), args.Holder(), args.GetIsolate()); | |
| 90 } | |
| 91 fail: | |
| 92 return setDOMException(ec, args.GetIsolate()); | |
| 93 } | |
| 94 | |
| 95 static v8::Handle<v8::Value> itemMethodCallback(const v8::Arguments& args) | |
| 96 { | |
| 97 return TestEventTargetV8Internal::itemMethod(args); | |
| 98 } | |
| 99 | |
| 100 static v8::Handle<v8::Value> addEventListenerMethod(const v8::Arguments& args) | |
| 101 { | |
| 102 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[
1], false, ListenerFindOrCreate); | |
| 103 if (listener) { | |
| 104 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<WithNullCheck>, stringR
esource, args[0]); | |
| 105 V8TestEventTarget::toNative(args.Holder())->addEventListener(stringResou
rce, listener, args[2]->BooleanValue()); | |
| 106 createHiddenDependency(args.Holder(), args[1], V8TestEventTarget::eventL
istenerCacheIndex, args.GetIsolate()); | |
| 107 } | |
| 108 return v8Undefined(); | |
| 109 } | |
| 110 | |
| 111 static v8::Handle<v8::Value> addEventListenerMethodCallback(const v8::Arguments&
args) | |
| 112 { | |
| 113 return TestEventTargetV8Internal::addEventListenerMethod(args); | |
| 114 } | |
| 115 | |
| 116 static v8::Handle<v8::Value> removeEventListenerMethod(const v8::Arguments& args
) | |
| 117 { | |
| 118 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[
1], false, ListenerFindOnly); | |
| 119 if (listener) { | |
| 120 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<WithNullCheck>, stringR
esource, args[0]); | |
| 121 V8TestEventTarget::toNative(args.Holder())->removeEventListener(stringRe
source, listener.get(), args[2]->BooleanValue()); | |
| 122 removeHiddenDependency(args.Holder(), args[1], V8TestEventTarget::eventL
istenerCacheIndex, args.GetIsolate()); | |
| 123 } | |
| 124 return v8Undefined(); | |
| 125 } | |
| 126 | |
| 127 static v8::Handle<v8::Value> removeEventListenerMethodCallback(const v8::Argumen
ts& args) | |
| 128 { | |
| 129 return TestEventTargetV8Internal::removeEventListenerMethod(args); | |
| 130 } | |
| 131 | |
| 132 static v8::Handle<v8::Value> dispatchEventMethod(const v8::Arguments& args) | |
| 133 { | |
| 134 if (args.Length() < 1) | |
| 135 return throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 136 TestEventTarget* imp = V8TestEventTarget::toNative(args.Holder()); | |
| 137 ExceptionCode ec = 0; | |
| 138 { | |
| 139 V8TRYCATCH(Event*, evt, V8Event::HasInstance(args[0], args.GetIsolate(), wor
ldType(args.GetIsolate())) ? V8Event::toNative(v8::Handle<v8::Object>::Cast(args
[0])) : 0); | |
| 140 bool result = imp->dispatchEvent(evt, ec); | |
| 141 if (UNLIKELY(ec)) | |
| 142 goto fail; | |
| 143 return v8Boolean(result, args.GetIsolate()); | |
| 144 } | |
| 145 fail: | |
| 146 return setDOMException(ec, args.GetIsolate()); | |
| 147 } | |
| 148 | |
| 149 static v8::Handle<v8::Value> dispatchEventMethodCallback(const v8::Arguments& ar
gs) | |
| 150 { | |
| 151 return TestEventTargetV8Internal::dispatchEventMethod(args); | |
| 152 } | |
| 153 | |
| 154 } // namespace TestEventTargetV8Internal | |
| 155 | |
| 156 static const V8DOMConfiguration::BatchedMethod V8TestEventTargetMethods[] = { | |
| 157 {"item", TestEventTargetV8Internal::itemMethodCallback, 0}, | |
| 158 {"addEventListener", TestEventTargetV8Internal::addEventListenerMethodCallba
ck, 0}, | |
| 159 {"removeEventListener", TestEventTargetV8Internal::removeEventListenerMethod
Callback, 0}, | |
| 160 }; | |
| 161 | |
| 162 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestEventTargetTemplate(v
8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType
currentWorldType) | |
| 163 { | |
| 164 desc->ReadOnlyPrototype(); | |
| 165 | |
| 166 v8::Local<v8::Signature> defaultSignature; | |
| 167 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestEventTar
get", v8::Persistent<v8::FunctionTemplate>(), V8TestEventTarget::internalFieldCo
unt, | |
| 168 0, 0, | |
| 169 V8TestEventTargetMethods, WTF_ARRAY_LENGTH(V8TestEventTargetMethods), is
olate, currentWorldType); | |
| 170 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. | |
| 171 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); | |
| 172 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); | |
| 173 UNUSED_PARAM(instance); // In some cases, it will not be used. | |
| 174 UNUSED_PARAM(proto); // In some cases, it will not be used. | |
| 175 | |
| 176 setCollectionIndexedGetter<TestEventTarget, Node>(desc); | |
| 177 desc->InstanceTemplate()->SetNamedPropertyHandler(V8TestEventTarget::namedPr
opertyGetter, 0, 0, 0, 0); | |
| 178 desc->InstanceTemplate()->MarkAsUndetectable(); | |
| 179 | |
| 180 // Custom Signature 'dispatchEvent' | |
| 181 const int dispatchEventArgc = 1; | |
| 182 v8::Handle<v8::FunctionTemplate> dispatchEventArgv[dispatchEventArgc] = { V8
PerIsolateData::from(isolate)->rawTemplate(&V8Event::info, currentWorldType) }; | |
| 183 v8::Handle<v8::Signature> dispatchEventSignature = v8::Signature::New(desc,
dispatchEventArgc, dispatchEventArgv); | |
| 184 proto->Set(v8::String::NewSymbol("dispatchEvent"), v8::FunctionTemplate::New
(TestEventTargetV8Internal::dispatchEventMethodCallback, v8Undefined(), dispatch
EventSignature)); | |
| 185 | |
| 186 // Custom toString template | |
| 187 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to
StringTemplate()); | |
| 188 return desc; | |
| 189 } | |
| 190 | |
| 191 v8::Persistent<v8::FunctionTemplate> V8TestEventTarget::GetTemplate(v8::Isolate*
isolate, WrapperWorldType currentWorldType) | |
| 192 { | |
| 193 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | |
| 194 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo
rldType).find(&info); | |
| 195 if (result != data->templateMap(currentWorldType).end()) | |
| 196 return result->value; | |
| 197 | |
| 198 v8::HandleScope handleScope; | |
| 199 v8::Persistent<v8::FunctionTemplate> templ = | |
| 200 ConfigureV8TestEventTargetTemplate(data->rawTemplate(&info, currentWorld
Type), isolate, currentWorldType); | |
| 201 data->templateMap(currentWorldType).add(&info, templ); | |
| 202 return templ; | |
| 203 } | |
| 204 | |
| 205 bool V8TestEventTarget::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* is
olate, WrapperWorldType currentWorldType) | |
| 206 { | |
| 207 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor
ldType); | |
| 208 } | |
| 209 | |
| 210 bool V8TestEventTarget::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::I
solate* isolate) | |
| 211 { | |
| 212 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) | |
| 213 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo
rld) | |
| 214 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl
d); | |
| 215 } | |
| 216 | |
| 217 EventTarget* V8TestEventTarget::toEventTarget(v8::Handle<v8::Object> object) | |
| 218 { | |
| 219 return toNative(object); | |
| 220 } | |
| 221 | |
| 222 | |
| 223 v8::Handle<v8::Object> V8TestEventTarget::createWrapper(PassRefPtr<TestEventTarg
et> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 224 { | |
| 225 ASSERT(impl.get()); | |
| 226 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); | |
| 227 | |
| 228 #if ENABLE(BINDING_INTEGRITY) | |
| 229 checkTypeOrDieTrying(impl.get()); | |
| 230 #endif | |
| 231 | |
| 232 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, &info, impl.get(), isolate); | |
| 233 if (UNLIKELY(wrapper.IsEmpty())) | |
| 234 return wrapper; | |
| 235 | |
| 236 installPerContextProperties(wrapper, impl.get(), isolate); | |
| 237 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD
ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep
endent); | |
| 238 return wrapper; | |
| 239 } | |
| 240 void V8TestEventTarget::derefObject(void* object) | |
| 241 { | |
| 242 static_cast<TestEventTarget*>(object)->deref(); | |
| 243 } | |
| 244 | |
| 245 } // namespace WebCore | |
| OLD | NEW |