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 "V8TestInterfaceEventTarget.h"
36 #include "RuntimeEnabledFeatures.h"
37 #include "bindings/v8/ExceptionState.h"
38 #include "bindings/v8/V8DOMConfiguration.h"
39 #include "bindings/v8/V8ObjectConstructor.h"
40 #include "core/dom/ContextFeatures.h"
41 #include "core/dom/Document.h"
42 #include "platform/TraceEvent.h"
43 #include "wtf/GetPtr.h"
44 #include "wtf/RefPtr.h"
48 static void initializeScriptWrappableForInterface(TestInterfaceEventTarget* object)
50 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
51 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceEventTarget::wrapperTypeInfo);
56 } // namespace WebCore
58 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
59 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
60 // in the global namespace.
61 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
62 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceEventTarget* object)
64 WebCore::initializeScriptWrappableForInterface(object);
68 const WrapperTypeInfo V8TestInterfaceEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTarget::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, false };
70 namespace TestInterfaceEventTargetV8Internal {
72 template <typename T> void V8_USE(T) { }
74 } // namespace TestInterfaceEventTargetV8Internal
76 const WrapperTypeInfo V8TestInterfaceEventTargetConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTargetConstructor::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
78 static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
80 if (!info.IsConstructCall()) {
81 throwTypeError(ExceptionMessages::failedToConstruct("Name", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
85 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
86 v8SetReturnValue(info, info.Holder());
90 Document* document = currentDocument(info.GetIsolate());
93 // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceEventTarget instance
94 // may end up being the only node in the map and get garbage-collected prematurely.
95 toV8(document, info.Holder(), info.GetIsolate());
97 RefPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(*document);
98 v8::Handle<v8::Object> wrapper = info.Holder();
100 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl.release(), &V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
101 v8SetReturnValue(info, wrapper);
104 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTargetConstructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
106 // This is only for getting a unique pointer which we can pass to privateTemplate.
107 static int privateTemplateUniqueKey;
108 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
109 v8::Local<v8::FunctionTemplate> result = data->privateTemplateIfExists(currentWorldType, &privateTemplateUniqueKey);
110 if (!result.IsEmpty())
113 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
114 v8::EscapableHandleScope scope(isolate);
115 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceEventTargetConstructorCallback);
117 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
118 instanceTemplate->SetInternalFieldCount(V8TestInterfaceEventTarget::internalFieldCount);
119 result->SetClassName(v8AtomicString(isolate, "TestInterfaceEventTarget"));
120 result->Inherit(V8TestInterfaceEventTarget::domTemplate(isolate, currentWorldType));
121 data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result);
123 return scope.Escape(result);
126 static void configureV8TestInterfaceEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
128 functionTemplate->ReadOnlyPrototype();
130 v8::Local<v8::Signature> defaultSignature;
131 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceEventTarget", V8EventTarget::domTemplate(isolate, currentWorldType), V8TestInterfaceEventTarget::internalFieldCount,
135 isolate, currentWorldType);
136 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
137 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
139 // Custom toString template
140 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
143 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTarget::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
145 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
146 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
147 if (result != data->templateMap(currentWorldType).end())
148 return result->value.newLocal(isolate);
150 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
151 v8::EscapableHandleScope handleScope(isolate);
152 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
153 configureV8TestInterfaceEventTargetTemplate(templ, isolate, currentWorldType);
154 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
155 return handleScope.Escape(templ);
158 bool V8TestInterfaceEventTarget::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
160 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
161 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
164 EventTarget* V8TestInterfaceEventTarget::toEventTarget(v8::Handle<v8::Object> object)
166 return toNative(object);
169 v8::Handle<v8::Object> V8TestInterfaceEventTarget::createWrapper(PassRefPtr<TestInterfaceEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
172 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceEventTarget>(impl.get(), isolate));
173 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
174 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
175 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
176 // the same object de-ref functions, though, so use that as the basis of the check.
177 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
180 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
181 if (UNLIKELY(wrapper.IsEmpty()))
184 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
185 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
189 void V8TestInterfaceEventTarget::derefObject(void* object)
191 fromInternalPointer(object)->deref();
195 v8::Handle<v8::Value> toV8NoInline(TestInterfaceEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
197 return toV8(impl, creationContext, isolate);
200 } // namespace WebCore