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