2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
34 #include "V8TestEventTarget.h"
36 #include "RuntimeEnabledFeatures.h"
38 #include "bindings/v8/ExceptionState.h"
39 #include "bindings/v8/V8DOMConfiguration.h"
40 #include "bindings/v8/V8ObjectConstructor.h"
41 #include "core/dom/ContextFeatures.h"
42 #include "core/dom/Document.h"
43 #include "platform/TraceEvent.h"
44 #include "wtf/GetPtr.h"
45 #include "wtf/RefPtr.h"
49 static void initializeScriptWrappableForInterface(TestEventTarget* object)
51 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
52 ScriptWrappable::setTypeInfoInObject(object, &V8TestEventTarget::wrapperTypeInfo);
57 } // namespace WebCore
59 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
60 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
61 // in the global namespace.
62 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
63 void webCoreInitializeScriptWrappableForInterface(WebCore::TestEventTarget* object)
65 WebCore::initializeScriptWrappableForInterface(object);
69 const WrapperTypeInfo V8TestEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestEventTarget::domTemplate, V8TestEventTarget::derefObject, 0, V8TestEventTarget::toEventTarget, 0, V8TestEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype };
71 namespace TestEventTargetV8Internal {
73 template <typename T> void V8_USE(T) { }
75 static void itemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
77 ExceptionState exceptionState(ExceptionState::ExecutionContext, "item", "TestEventTarget", info.Holder(), info.GetIsolate());
78 if (UNLIKELY(info.Length() < 1)) {
79 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
80 exceptionState.throwIfNeeded();
83 TestEventTarget* imp = V8TestEventTarget::toNative(info.Holder());
84 V8TRYCATCH_EXCEPTION_VOID(unsigned, index, toUInt32(info[0], exceptionState), exceptionState);
85 v8SetReturnValue(info, imp->item(index));
88 static void itemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
90 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
91 TestEventTargetV8Internal::itemMethod(info);
92 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
95 static void namedItemMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
97 if (UNLIKELY(info.Length() < 1)) {
98 throwTypeError(ExceptionMessages::failedToExecute("namedItem", "TestEventTarget", ExceptionMessages::notEnoughArguments(1, info.Length())), info.GetIsolate());
101 TestEventTarget* imp = V8TestEventTarget::toNative(info.Holder());
102 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]);
103 v8SetReturnValue(info, imp->namedItem(name));
106 static void namedItemMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
108 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
109 TestEventTargetV8Internal::namedItemMethod(info);
110 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
113 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
115 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
116 RefPtr<Node> element = collection->item(index);
119 v8SetReturnValueFast(info, element.release(), collection);
122 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
124 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
125 TestEventTargetV8Internal::indexedPropertyGetter(index, info);
126 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
129 static void indexedPropertySetter(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
131 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
132 V8TRYCATCH_VOID(Node*, propertyValue, V8Node::hasInstance(jsValue, info.GetIsolate()) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(jsValue)) : 0);
133 bool result = collection->anonymousIndexedSetter(index, propertyValue);
136 v8SetReturnValue(info, jsValue);
139 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
141 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
142 TestEventTargetV8Internal::indexedPropertySetter(index, jsValue, info);
143 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
146 static void indexedPropertyDeleter(unsigned index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
148 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
149 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
150 DeleteResult result = collection->anonymousIndexedDeleter(index, exceptionState);
151 if (exceptionState.throwIfNeeded())
153 if (result != DeleteUnknownProperty)
154 return v8SetReturnValueBool(info, result == DeleteSuccess);
157 static void indexedPropertyDeleterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
159 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
160 TestEventTargetV8Internal::indexedPropertyDeleter(index, info);
161 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
164 static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
166 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
168 if (info.Holder()->HasRealNamedCallbackProperty(name))
170 if (info.Holder()->HasRealNamedProperty(name))
173 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
174 AtomicString propertyName = toCoreAtomicString(name);
175 RefPtr<Node> element = collection->namedItem(propertyName);
178 v8SetReturnValueFast(info, element.release(), collection);
181 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
183 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
184 TestEventTargetV8Internal::namedPropertyGetter(name, info);
185 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
188 static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
190 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())
192 if (info.Holder()->HasRealNamedCallbackProperty(name))
194 if (info.Holder()->HasRealNamedProperty(name))
196 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
197 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyName, name);
198 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, propertyValue, jsValue);
200 if (jsValue->IsUndefined())
201 result = collection->anonymousNamedSetterUndefined(propertyName);
203 result = collection->anonymousNamedSetter(propertyName, propertyValue);
206 v8SetReturnValue(info, jsValue);
209 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
211 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
212 TestEventTargetV8Internal::namedPropertySetter(name, jsValue, info);
213 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
216 static void namedPropertyDeleter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
218 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
219 AtomicString propertyName = toCoreAtomicString(name);
220 DeleteResult result = collection->anonymousNamedDeleter(propertyName);
221 if (result != DeleteUnknownProperty)
222 return v8SetReturnValueBool(info, result == DeleteSuccess);
225 static void namedPropertyDeleterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
227 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
228 TestEventTargetV8Internal::namedPropertyDeleter(name, info);
229 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
232 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
234 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
235 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
236 Vector<String> names;
237 collection->namedPropertyEnumerator(names, exceptionState);
238 if (exceptionState.throwIfNeeded())
240 v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
241 for (size_t i = 0; i < names.size(); ++i)
242 v8names->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.GetIsolate(), names[i]));
243 v8SetReturnValue(info, v8names);
246 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
248 TestEventTarget* collection = V8TestEventTarget::toNative(info.Holder());
249 AtomicString propertyName = toCoreAtomicString(name);
250 ExceptionState exceptionState(info.Holder(), info.GetIsolate());
251 bool result = collection->namedPropertyQuery(propertyName, exceptionState);
252 if (exceptionState.throwIfNeeded())
256 v8SetReturnValueInt(info, v8::None);
259 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
261 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
262 TestEventTargetV8Internal::namedPropertyEnumerator(info);
263 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
266 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
268 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
269 TestEventTargetV8Internal::namedPropertyQuery(name, info);
270 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
273 } // namespace TestEventTargetV8Internal
275 static const V8DOMConfiguration::MethodConfiguration V8TestEventTargetMethods[] = {
276 {"item", TestEventTargetV8Internal::itemMethodCallback, 0, 1},
277 {"namedItem", TestEventTargetV8Internal::namedItemMethodCallback, 0, 1},
280 static void configureV8TestEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
282 functionTemplate->ReadOnlyPrototype();
284 v8::Local<v8::Signature> defaultSignature;
285 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestEventTarget", V8EventTarget::domTemplate(isolate, currentWorldType), V8TestEventTarget::internalFieldCount,
288 V8TestEventTargetMethods, WTF_ARRAY_LENGTH(V8TestEventTargetMethods),
289 isolate, currentWorldType);
290 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
291 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
292 functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestEventTargetV8Internal::indexedPropertyGetterCallback, TestEventTargetV8Internal::indexedPropertySetterCallback, 0, TestEventTargetV8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestEventTarget>);
293 functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestEventTargetV8Internal::namedPropertyGetterCallback, TestEventTargetV8Internal::namedPropertySetterCallback, TestEventTargetV8Internal::namedPropertyQueryCallback, TestEventTargetV8Internal::namedPropertyDeleterCallback, TestEventTargetV8Internal::namedPropertyEnumeratorCallback);
295 // Custom toString template
296 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
299 v8::Handle<v8::FunctionTemplate> V8TestEventTarget::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
301 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
302 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
303 if (result != data->templateMap(currentWorldType).end())
304 return result->value.newLocal(isolate);
306 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
307 v8::EscapableHandleScope handleScope(isolate);
308 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
309 configureV8TestEventTargetTemplate(templ, isolate, currentWorldType);
310 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
311 return handleScope.Escape(templ);
314 bool V8TestEventTarget::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
316 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
317 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
320 EventTarget* V8TestEventTarget::toEventTarget(v8::Handle<v8::Object> object)
322 return toNative(object);
325 v8::Handle<v8::Object> V8TestEventTarget::createWrapper(PassRefPtr<TestEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
328 ASSERT(!DOMDataStore::containsWrapper<V8TestEventTarget>(impl.get(), isolate));
329 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
330 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
331 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
332 // the same object de-ref functions, though, so use that as the basis of the check.
333 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
336 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
337 if (UNLIKELY(wrapper.IsEmpty()))
340 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
341 V8DOMWrapper::associateObjectWithWrapper<V8TestEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
345 void V8TestEventTarget::derefObject(void* object)
347 fromInternalPointer(object)->deref();
351 v8::Handle<v8::Value> toV8NoInline(TestEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
353 return toV8(impl, creationContext, isolate);
356 } // namespace WebCore