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 "V8TestInterfaceImplementedAs.h"
35
36#include "RuntimeEnabledFeatures.h"
37#include "bindings/v8/ExceptionState.h"
38#include "bindings/v8/V8DOMConfiguration.h"
39#include "core/dom/ContextFeatures.h"
40#include "core/dom/Document.h"
41#include "platform/TraceEvent.h"
42#include "wtf/GetPtr.h"
43#include "wtf/RefPtr.h"
44
45namespace WebCore {
46
47static void initializeScriptWrappableForInterface(RealClass* object)
48{
49    if (ScriptWrappable::wrapperCanBeStoredInObject(object))
50        ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceImplementedAs::wrapperTypeInfo);
51    else
52        ASSERT_NOT_REACHED();
53}
54
55} // namespace WebCore
56
57// In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
58// the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
59// in the global namespace.
60// (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
61void webCoreInitializeScriptWrappableForInterface(WebCore::RealClass* object)
62{
63    WebCore::initializeScriptWrappableForInterface(object);
64}
65
66namespace WebCore {
67const WrapperTypeInfo V8TestInterfaceImplementedAs::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceImplementedAs::domTemplate, V8TestInterfaceImplementedAs::derefObject, 0, 0, 0, V8TestInterfaceImplementedAs::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype };
68
69namespace RealClassV8Internal {
70
71template <typename T> void V8_USE(T) { }
72
73static void aAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
74{
75    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
76    v8SetReturnValueString(info, imp->a(), info.GetIsolate());
77}
78
79static void aAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
80{
81    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
82    RealClassV8Internal::aAttributeGetter(info);
83    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
84}
85
86static void aAttributeSetter(v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
87{
88    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
89    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, cppValue, jsValue);
90    imp->setA(cppValue);
91}
92
93static void aAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
94{
95    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
96    RealClassV8Internal::aAttributeSetter(jsValue, info);
97    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
98}
99
100static void bAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
101{
102    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
103    v8SetReturnValueFast(info, imp->b(), imp);
104}
105
106static void bAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
107{
108    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
109    RealClassV8Internal::bAttributeGetter(info);
110    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
111}
112
113static void bAttributeSetter(v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
114{
115    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
116    V8TRYCATCH_VOID(RealClass*, cppValue, V8TestInterfaceImplementedAs::hasInstance(jsValue, info.GetIsolate(), worldType(info.GetIsolate())) ? V8TestInterfaceImplementedAs::toNative(v8::Handle<v8::Object>::Cast(jsValue)) : 0);
117    imp->setB(WTF::getPtr(cppValue));
118}
119
120static void bAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info)
121{
122    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
123    RealClassV8Internal::bAttributeSetter(jsValue, info);
124    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
125}
126
127static void func1Method(const v8::FunctionCallbackInfo<v8::Value>& info)
128{
129    if (UNLIKELY(info.Length() < 1)) {
130        throwTypeError(ExceptionMessages::failedToExecute("func1", "TestInterfaceImplementedAs", ExceptionMessages::notEnoughArguments(1, info.Length())), info.GetIsolate());
131        return;
132    }
133    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
134    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, a, info[0]);
135    v8SetReturnValueString(info, imp->func1(a), info.GetIsolate());
136}
137
138static void func1MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
139{
140    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
141    RealClassV8Internal::func1Method(info);
142    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
143}
144
145static void funcTestInterfaceImplementedAsParamMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
146{
147    if (UNLIKELY(info.Length() < 1)) {
148        throwTypeError(ExceptionMessages::failedToExecute("funcTestInterfaceImplementedAsParam", "TestInterfaceImplementedAs", ExceptionMessages::notEnoughArguments(1, info.Length())), info.GetIsolate());
149        return;
150    }
151    RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder());
152    V8TRYCATCH_VOID(RealClass*, orange, V8TestInterfaceImplementedAs::hasInstance(info[0], info.GetIsolate(), worldType(info.GetIsolate())) ? V8TestInterfaceImplementedAs::toNative(v8::Handle<v8::Object>::Cast(info[0])) : 0);
153    v8SetReturnValueString(info, imp->funcTestInterfaceImplementedAsParam(orange), info.GetIsolate());
154}
155
156static void funcTestInterfaceImplementedAsParamMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
157{
158    TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
159    RealClassV8Internal::funcTestInterfaceImplementedAsParamMethod(info);
160    TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
161}
162
163} // namespace RealClassV8Internal
164
165static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceImplementedAsAttributes[] = {
166    {"a", RealClassV8Internal::aAttributeGetterCallback, RealClassV8Internal::aAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
167    {"b", RealClassV8Internal::bAttributeGetterCallback, RealClassV8Internal::bAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
168};
169
170static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceImplementedAsMethods[] = {
171    {"func1", RealClassV8Internal::func1MethodCallback, 0, 1},
172};
173
174static v8::Handle<v8::FunctionTemplate> ConfigureV8TestInterfaceImplementedAsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
175{
176    functionTemplate->ReadOnlyPrototype();
177
178    v8::Local<v8::Signature> defaultSignature;
179    defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceImplementedAs", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceImplementedAs::internalFieldCount,
180        V8TestInterfaceImplementedAsAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceImplementedAsAttributes),
181        0, 0,
182        V8TestInterfaceImplementedAsMethods, WTF_ARRAY_LENGTH(V8TestInterfaceImplementedAsMethods),
183        isolate, currentWorldType);
184    v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
185    v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
186
187    // Custom Signature 'funcTestInterfaceImplementedAsParam'
188    const int funcTestInterfaceImplementedAsParamArgc = 1;
189    v8::Handle<v8::FunctionTemplate> funcTestInterfaceImplementedAsParamArgv[funcTestInterfaceImplementedAsParamArgc] = { V8PerIsolateData::from(isolate)->rawDOMTemplate(&V8TestInterfaceImplementedAs::wrapperTypeInfo, currentWorldType) };
190    v8::Handle<v8::Signature> funcTestInterfaceImplementedAsParamSignature = v8::Signature::New(isolate, functionTemplate, funcTestInterfaceImplementedAsParamArgc, funcTestInterfaceImplementedAsParamArgv);
191    prototypeTemplate->Set(v8::String::NewFromUtf8(isolate, "funcTestInterfaceImplementedAsParam", v8::String::kInternalizedString), v8::FunctionTemplate::New(isolate, RealClassV8Internal::funcTestInterfaceImplementedAsParamMethodCallback, v8Undefined(), funcTestInterfaceImplementedAsParamSignature, 1));
192
193    // Custom toString template
194    functionTemplate->Set(v8::String::NewFromUtf8(isolate, "toString", v8::String::kInternalizedString), V8PerIsolateData::current()->toStringTemplate());
195    return functionTemplate;
196}
197
198v8::Handle<v8::FunctionTemplate> V8TestInterfaceImplementedAs::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
199{
200    V8PerIsolateData* data = V8PerIsolateData::from(isolate);
201    V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
202    if (result != data->templateMap(currentWorldType).end())
203        return result->value.newLocal(isolate);
204
205    TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
206    v8::EscapableHandleScope handleScope(isolate);
207    v8::Local<v8::FunctionTemplate> templ =
208        ConfigureV8TestInterfaceImplementedAsTemplate(data->rawDOMTemplate(&wrapperTypeInfo, currentWorldType), isolate, currentWorldType);
209    data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
210    return handleScope.Escape(templ);
211}
212
213bool V8TestInterfaceImplementedAs::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate, WrapperWorldType currentWorldType)
214{
215    return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, jsValue, currentWorldType);
216}
217
218bool V8TestInterfaceImplementedAs::hasInstanceInAnyWorld(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
219{
220    return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, jsValue, MainWorld)
221        || V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, jsValue, IsolatedWorld)
222        || V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, jsValue, WorkerWorld);
223}
224
225v8::Handle<v8::Object> V8TestInterfaceImplementedAs::createWrapper(PassRefPtr<RealClass> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
226{
227    ASSERT(impl);
228    ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceImplementedAs>(impl.get(), isolate));
229    if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
230        const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
231        // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
232        // the same object de-ref functions, though, so use that as the basis of the check.
233        RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
234    }
235
236    v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
237    if (UNLIKELY(wrapper.IsEmpty()))
238        return wrapper;
239
240    installPerContextEnabledProperties(wrapper, impl.get(), isolate);
241    V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceImplementedAs>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
242    return wrapper;
243}
244
245void V8TestInterfaceImplementedAs::derefObject(void* object)
246{
247    fromInternalPointer(object)->deref();
248}
249
250template<>
251v8::Handle<v8::Value> toV8NoInline(RealClass* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
252{
253    return toV8(impl, creationContext, isolate);
254}
255
256} // namespace WebCore
257