Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceNamedConstructor.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
32
33 #include "config.h"
34 #include "V8TestInterfaceNamedConstructor.h"
35
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"
45
46 namespace WebCore {
47
48 static void initializeScriptWrappableForInterface(TestInterfaceNamedConstructor* object)
49 {
50     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
51         ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceNamedConstructor::wrapperTypeInfo);
52     else
53         ASSERT_NOT_REACHED();
54 }
55
56 } // namespace WebCore
57
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::TestInterfaceNamedConstructor* object)
63 {
64     WebCore::initializeScriptWrappableForInterface(object);
65 }
66
67 namespace WebCore {
68 const WrapperTypeInfo V8TestInterfaceNamedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructor::domTemplate, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
69
70 namespace TestInterfaceNamedConstructorV8Internal {
71
72 template <typename T> void V8_USE(T) { }
73
74 static void TestInterfaceNamedConstructorConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
75 {
76     v8::Handle<v8::Value> data = info.Data();
77     ASSERT(data->IsExternal());
78     V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext());
79     if (!perContextData)
80         return;
81     v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
82 }
83
84 static void TestInterfaceNamedConstructorReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
85 {
86     info.This()->ForceSet(name, jsValue);
87 }
88
89 static void TestInterfaceNamedConstructorReplaceableAttributeSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
90 {
91     TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorReplaceableAttributeSetter(name, jsValue, info);
92 }
93
94 } // namespace TestInterfaceNamedConstructorV8Internal
95
96 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceNamedConstructorAttributes[] = {
97     {"testNamedConstructorConstructorAttribute", TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorConstructorGetter, TestInterfaceNamedConstructorV8Internal::TestInterfaceNamedConstructorReplaceableAttributeSetterCallback, 0, 0, const_cast<WrapperTypeInfo*>(&V8TestNamedConstructor::wrapperTypeInfo), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::DontEnum), 0 /* on instance */},
98 };
99
100 const WrapperTypeInfo V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceNamedConstructorConstructor::domTemplate, V8TestInterfaceNamedConstructor::derefObject, V8TestInterfaceNamedConstructor::toActiveDOMObject, 0, 0, V8TestInterfaceNamedConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
101
102 static void V8TestInterfaceNamedConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
103 {
104     if (!info.IsConstructCall()) {
105         throwTypeError(ExceptionMessages::failedToConstruct("Audio", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
106         return;
107     }
108
109     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
110         v8SetReturnValue(info, info.Holder());
111         return;
112     }
113
114     Document* document = currentDocument(info.GetIsolate());
115     ASSERT(document);
116
117     // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceNamedConstructor instance
118     // may end up being the only node in the map and get garbage-collected prematurely.
119     toV8(document, info.Holder(), info.GetIsolate());
120
121     ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceNamedConstructor", info.Holder(), info.GetIsolate());
122     if (UNLIKELY(info.Length() < 1)) {
123         exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
124         exceptionState.throwIfNeeded();
125         return;
126     }
127     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringArg, info[0]);
128     V8TRYCATCH_VOID(bool, defaultUndefinedOptionalBooleanArg, info[1]->BooleanValue());
129     V8TRYCATCH_EXCEPTION_VOID(int, defaultUndefinedOptionalLongArg, toInt32(info[2], exceptionState), exceptionState);
130     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, defaultUndefinedOptionalStringArg, info[3]);
131     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, defaultNullStringOptionalstringArg, argumentOrNull(info, 4));
132     RefPtr<TestInterfaceNamedConstructor> impl = TestInterfaceNamedConstructor::createForJSConstructor(*document, stringArg, defaultUndefinedOptionalBooleanArg, defaultUndefinedOptionalLongArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalstringArg, exceptionState);
133     v8::Handle<v8::Object> wrapper = info.Holder();
134     if (exceptionState.throwIfNeeded())
135         return;
136
137     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceNamedConstructor>(impl.release(), &V8TestInterfaceNamedConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
138     v8SetReturnValue(info, wrapper);
139 }
140
141 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructorConstructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
142 {
143     // This is only for getting a unique pointer which we can pass to privateTemplate.
144     static int privateTemplateUniqueKey;
145     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
146     v8::Local<v8::FunctionTemplate> result = data->privateTemplateIfExists(currentWorldType, &privateTemplateUniqueKey);
147     if (!result.IsEmpty())
148         return result;
149
150     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
151     v8::EscapableHandleScope scope(isolate);
152     result = v8::FunctionTemplate::New(isolate, V8TestInterfaceNamedConstructorConstructorCallback);
153
154     v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
155     instanceTemplate->SetInternalFieldCount(V8TestInterfaceNamedConstructor::internalFieldCount);
156     result->SetClassName(v8AtomicString(isolate, "TestInterfaceNamedConstructor"));
157     result->Inherit(V8TestInterfaceNamedConstructor::domTemplate(isolate, currentWorldType));
158     data->setPrivateTemplate(currentWorldType, &privateTemplateUniqueKey, result);
159
160     return scope.Escape(result);
161 }
162
163 static void configureV8TestInterfaceNamedConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
164 {
165     functionTemplate->ReadOnlyPrototype();
166
167     v8::Local<v8::Signature> defaultSignature;
168     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceNamedConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceNamedConstructor::internalFieldCount,
169         V8TestInterfaceNamedConstructorAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceNamedConstructorAttributes),
170         0, 0,
171         0, 0,
172         isolate, currentWorldType);
173     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
174     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
175
176     // Custom toString template
177     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
178 }
179
180 v8::Handle<v8::FunctionTemplate> V8TestInterfaceNamedConstructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
181 {
182     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
183     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
184     if (result != data->templateMap(currentWorldType).end())
185         return result->value.newLocal(isolate);
186
187     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
188     v8::EscapableHandleScope handleScope(isolate);
189     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
190     configureV8TestInterfaceNamedConstructorTemplate(templ, isolate, currentWorldType);
191     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
192     return handleScope.Escape(templ);
193 }
194
195 bool V8TestInterfaceNamedConstructor::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
196 {
197     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
198         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
199 }
200
201 ActiveDOMObject* V8TestInterfaceNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> wrapper)
202 {
203     return toNative(wrapper);
204 }
205
206 v8::Handle<v8::Object> V8TestInterfaceNamedConstructor::createWrapper(PassRefPtr<TestInterfaceNamedConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
207 {
208     ASSERT(impl);
209     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceNamedConstructor>(impl.get(), isolate));
210     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
211         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
212         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
213         // the same object de-ref functions, though, so use that as the basis of the check.
214         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
215     }
216
217     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
218     if (UNLIKELY(wrapper.IsEmpty()))
219         return wrapper;
220
221     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
222     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceNamedConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Dependent);
223     return wrapper;
224 }
225
226 void V8TestInterfaceNamedConstructor::derefObject(void* object)
227 {
228     fromInternalPointer(object)->deref();
229 }
230
231 template<>
232 v8::Handle<v8::Value> toV8NoInline(TestInterfaceNamedConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
233 {
234     return toV8(impl, creationContext, isolate);
235 }
236
237 } // namespace WebCore