Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestCustomAccessors.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 "V8TestCustomAccessors.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
44 namespace WebCore {
45
46 static void initializeScriptWrappableForInterface(TestCustomAccessors* object)
47 {
48     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
49         ScriptWrappable::setTypeInfoInObject(object, &V8TestCustomAccessors::wrapperTypeInfo);
50     else
51         ASSERT_NOT_REACHED();
52 }
53
54 } // namespace WebCore
55
56 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
57 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
58 // in the global namespace.
59 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
60 void webCoreInitializeScriptWrappableForInterface(WebCore::TestCustomAccessors* object)
61 {
62     WebCore::initializeScriptWrappableForInterface(object);
63 }
64
65 namespace WebCore {
66 const WrapperTypeInfo V8TestCustomAccessors::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestCustomAccessors::domTemplate, V8TestCustomAccessors::derefObject, 0, 0, 0, V8TestCustomAccessors::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype };
67
68 namespace TestCustomAccessorsV8Internal {
69
70 template <typename T> void V8_USE(T) { }
71
72 static void anotherFunctionMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
73 {
74     if (UNLIKELY(info.Length() < 1)) {
75         throwTypeError(ExceptionMessages::failedToExecute("anotherFunction", "TestCustomAccessors", ExceptionMessages::notEnoughArguments(1, info.Length())), info.GetIsolate());
76         return;
77     }
78     TestCustomAccessors* imp = V8TestCustomAccessors::toNative(info.Holder());
79     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, str, info[0]);
80     imp->anotherFunction(str);
81 }
82
83 static void anotherFunctionMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
84 {
85     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
86     TestCustomAccessorsV8Internal::anotherFunctionMethod(info);
87     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
88 }
89
90 static void indexedPropertyGetterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
91 {
92     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
93     V8TestCustomAccessors::indexedPropertyGetterCustom(index, info);
94     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
95 }
96
97 static void indexedPropertySetterCallback(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
98 {
99     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
100     V8TestCustomAccessors::indexedPropertySetterCustom(index, jsValue, info);
101     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
102 }
103
104 static void indexedPropertyDeleterCallback(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)
105 {
106     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMIndexedProperty");
107     V8TestCustomAccessors::indexedPropertyDeleterCustom(index, info);
108     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
109 }
110
111 static void namedPropertyGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
112 {
113     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
114     V8TestCustomAccessors::namedPropertyGetterCustom(name, info);
115     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
116 }
117
118 static void namedPropertySetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)
119 {
120     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
121     V8TestCustomAccessors::namedPropertySetterCustom(name, jsValue, info);
122     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
123 }
124
125 static void namedPropertyDeleterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)
126 {
127     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
128     V8TestCustomAccessors::namedPropertyDeleterCustom(name, info);
129     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
130 }
131
132 static void namedPropertyEnumeratorCallback(const v8::PropertyCallbackInfo<v8::Array>& info)
133 {
134     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
135     V8TestCustomAccessors::namedPropertyEnumeratorCustom(info);
136     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
137 }
138
139 static void namedPropertyQueryCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
140 {
141     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMNamedProperty");
142     V8TestCustomAccessors::namedPropertyQueryCustom(name, info);
143     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
144 }
145
146 } // namespace TestCustomAccessorsV8Internal
147
148 static const V8DOMConfiguration::MethodConfiguration V8TestCustomAccessorsMethods[] = {
149     {"anotherFunction", TestCustomAccessorsV8Internal::anotherFunctionMethodCallback, 0, 1},
150 };
151
152 static void configureV8TestCustomAccessorsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
153 {
154     functionTemplate->ReadOnlyPrototype();
155
156     v8::Local<v8::Signature> defaultSignature;
157     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestCustomAccessors", v8::Local<v8::FunctionTemplate>(), V8TestCustomAccessors::internalFieldCount,
158         0, 0,
159         0, 0,
160         V8TestCustomAccessorsMethods, WTF_ARRAY_LENGTH(V8TestCustomAccessorsMethods),
161         isolate, currentWorldType);
162     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
163     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
164     functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestCustomAccessorsV8Internal::indexedPropertyGetterCallback, TestCustomAccessorsV8Internal::indexedPropertySetterCallback, 0, TestCustomAccessorsV8Internal::indexedPropertyDeleterCallback, 0);
165     functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestCustomAccessorsV8Internal::namedPropertyGetterCallback, TestCustomAccessorsV8Internal::namedPropertySetterCallback, TestCustomAccessorsV8Internal::namedPropertyQueryCallback, TestCustomAccessorsV8Internal::namedPropertyDeleterCallback, TestCustomAccessorsV8Internal::namedPropertyEnumeratorCallback);
166
167     // Custom toString template
168     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
169 }
170
171 v8::Handle<v8::FunctionTemplate> V8TestCustomAccessors::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
172 {
173     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
174     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
175     if (result != data->templateMap(currentWorldType).end())
176         return result->value.newLocal(isolate);
177
178     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
179     v8::EscapableHandleScope handleScope(isolate);
180     v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
181     configureV8TestCustomAccessorsTemplate(templ, isolate, currentWorldType);
182     data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
183     return handleScope.Escape(templ);
184 }
185
186 bool V8TestCustomAccessors::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
187 {
188     return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
189         || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
190 }
191
192 v8::Handle<v8::Object> V8TestCustomAccessors::createWrapper(PassRefPtr<TestCustomAccessors> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
193 {
194     ASSERT(impl);
195     ASSERT(!DOMDataStore::containsWrapper<V8TestCustomAccessors>(impl.get(), isolate));
196     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
197         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
198         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
199         // the same object de-ref functions, though, so use that as the basis of the check.
200         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
201     }
202
203     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
204     if (UNLIKELY(wrapper.IsEmpty()))
205         return wrapper;
206
207     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
208     V8DOMWrapper::associateObjectWithWrapper<V8TestCustomAccessors>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
209     return wrapper;
210 }
211
212 void V8TestCustomAccessors::derefObject(void* object)
213 {
214     fromInternalPointer(object)->deref();
215 }
216
217 template<>
218 v8::Handle<v8::Value> toV8NoInline(TestCustomAccessors* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
219 {
220     return toV8(impl, creationContext, isolate);
221 }
222
223 } // namespace WebCore