1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY!
8 #include "V8TestTypedefs.h"
10 #include "bindings/core/v8/ExceptionState.h"
11 #include "bindings/core/v8/V8DOMConfiguration.h"
12 #include "bindings/core/v8/V8HiddenValue.h"
13 #include "bindings/core/v8/V8ObjectConstructor.h"
14 #include "bindings/tests/v8/V8TestCallbackInterface.h"
15 #include "bindings/tests/v8/V8TestInterface.h"
16 #include "bindings/tests/v8/V8TestInterfaceEmpty.h"
17 #include "core/dom/ContextFeatures.h"
18 #include "core/dom/Document.h"
19 #include "core/frame/LocalDOMWindow.h"
20 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/TraceEvent.h"
22 #include "wtf/GetPtr.h"
23 #include "wtf/RefPtr.h"
27 static void initializeScriptWrappableForInterface(TestTypedefs* object)
29 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
30 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestTypedefs::wrapperTypeInfo);
37 void webCoreInitializeScriptWrappableForInterface(blink::TestTypedefs* object)
39 blink::initializeScriptWrappableForInterface(object);
43 const WrapperTypeInfo V8TestTypedefs::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestTypedefs::domTemplate, V8TestTypedefs::derefObject, 0, 0, 0, V8TestTypedefs::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
45 namespace TestTypedefsV8Internal {
47 template <typename T> void V8_USE(T) { }
49 static void uLongLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
51 v8::Handle<v8::Object> holder = info.Holder();
52 TestTypedefs* impl = V8TestTypedefs::toNative(holder);
53 v8SetReturnValue(info, static_cast<double>(impl->uLongLongAttribute()));
56 static void uLongLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
58 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
59 TestTypedefsV8Internal::uLongLongAttributeAttributeGetter(info);
60 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
63 static void uLongLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
65 v8::Handle<v8::Object> holder = info.Holder();
66 ExceptionState exceptionState(ExceptionState::SetterContext, "uLongLongAttribute", "TestTypedefs", holder, info.GetIsolate());
67 TestTypedefs* impl = V8TestTypedefs::toNative(holder);
68 TONATIVE_VOID_EXCEPTIONSTATE(unsigned long long, cppValue, toUInt64(v8Value, exceptionState), exceptionState);
69 impl->setULongLongAttribute(cppValue);
72 static void uLongLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
74 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
75 TestTypedefsV8Internal::uLongLongAttributeAttributeSetter(v8Value, info);
76 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
79 static void TestTypedefsConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
81 v8::Handle<v8::Value> data = info.Data();
82 ASSERT(data->IsExternal());
83 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext());
86 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data)));
89 static void TestTypedefsForceSetAttributeOnThis(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
91 if (info.This()->IsObject())
92 v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value);
95 static void TestTypedefsForceSetAttributeOnThisCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
97 TestTypedefsV8Internal::TestTypedefsForceSetAttributeOnThis(name, v8Value, info);
100 static void voidMethodArrayOfLongsArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
102 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
103 Vector<int> arrayOfLongsArg;
106 V8RethrowTryCatchScope rethrow(block);
107 if (UNLIKELY(info.Length() <= 0)) {
108 impl->voidMethodArrayOfLongsArg();
111 TONATIVE_VOID_INTERNAL(arrayOfLongsArg, toNativeArray<int>(info[0], 1, info.GetIsolate()));
113 impl->voidMethodArrayOfLongsArg(arrayOfLongsArg);
116 static void voidMethodArrayOfLongsArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
118 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
119 TestTypedefsV8Internal::voidMethodArrayOfLongsArgMethod(info);
120 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
123 static void voidMethodFloatArgStringArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
125 if (UNLIKELY(info.Length() < 2)) {
126 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("voidMethodFloatArgStringArg", "TestTypedefs", 2, info.Length(), info.GetIsolate()), info.GetIsolate());
129 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
131 V8StringResource<> stringArg;
134 V8RethrowTryCatchScope rethrow(block);
135 TONATIVE_VOID_INTERNAL(floatArg, static_cast<float>(info[0]->NumberValue()));
136 TOSTRING_VOID_INTERNAL(stringArg, info[1]);
138 impl->voidMethodFloatArgStringArg(floatArg, stringArg);
141 static void voidMethodFloatArgStringArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
143 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
144 TestTypedefsV8Internal::voidMethodFloatArgStringArgMethod(info);
145 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
148 static void voidMethodTestCallbackInterfaceTypeArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
150 if (UNLIKELY(info.Length() < 1)) {
151 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("voidMethodTestCallbackInterfaceTypeArg", "TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
154 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
155 OwnPtr<TestCallbackInterface> testCallbackInterfaceTypeArg;
157 if (info.Length() <= 0 || !info[0]->IsFunction()) {
158 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("voidMethodTestCallbackInterfaceTypeArg", "TestTypedefs", "The callback provided as parameter 1 is not a function."), info.GetIsolate());
161 testCallbackInterfaceTypeArg = V8TestCallbackInterface::create(v8::Handle<v8::Function>::Cast(info[0]), ScriptState::current(info.GetIsolate()));
163 impl->voidMethodTestCallbackInterfaceTypeArg(testCallbackInterfaceTypeArg.release());
166 static void voidMethodTestCallbackInterfaceTypeArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
168 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
169 TestTypedefsV8Internal::voidMethodTestCallbackInterfaceTypeArgMethod(info);
170 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
173 static void uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
175 if (UNLIKELY(info.Length() < 1)) {
176 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("uLongLongMethodTestInterfaceEmptyTypeSequenceArg", "TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
179 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
180 Vector<RefPtr<TestInterfaceEmpty> > testInterfaceEmptyTypeSequenceArg;
183 V8RethrowTryCatchScope rethrow(block);
184 TONATIVE_VOID_INTERNAL(testInterfaceEmptyTypeSequenceArg, (toRefPtrNativeArray<TestInterfaceEmpty, V8TestInterfaceEmpty>(info[0], 1, info.GetIsolate())));
186 v8SetReturnValue(info, static_cast<double>(impl->uLongLongMethodTestInterfaceEmptyTypeSequenceArg(testInterfaceEmptyTypeSequenceArg)));
189 static void uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
191 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
192 TestTypedefsV8Internal::uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethod(info);
193 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
196 static void testInterfaceOrTestInterfaceEmptyMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
198 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
199 RefPtr<TestInterfaceImplementation> result0;
200 RefPtr<TestInterfaceEmpty> result1;
201 impl->testInterfaceOrTestInterfaceEmptyMethod(result0, result1);
203 v8SetReturnValue(info, result0.release());
207 v8SetReturnValue(info, result1.release());
210 v8SetReturnValueNull(info);
213 static void testInterfaceOrTestInterfaceEmptyMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
215 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
216 TestTypedefsV8Internal::testInterfaceOrTestInterfaceEmptyMethodMethod(info);
217 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
220 static void domStringOrDoubleMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
222 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
224 Nullable<double> result1;
225 impl->domStringOrDoubleMethod(result0, result1);
226 if (!result0.isNull()) {
227 v8SetReturnValueString(info, result0, info.GetIsolate());
231 v8SetReturnValue(info, result1.get());
234 v8SetReturnValueNull(info);
237 static void domStringOrDoubleMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
239 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
240 TestTypedefsV8Internal::domStringOrDoubleMethodMethod(info);
241 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
244 static void arrayOfStringsMethodArrayOfStringsArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
246 if (UNLIKELY(info.Length() < 1)) {
247 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("arrayOfStringsMethodArrayOfStringsArg", "TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
250 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
251 Vector<String> arrayOfStringsArg;
254 V8RethrowTryCatchScope rethrow(block);
255 TONATIVE_VOID_INTERNAL(arrayOfStringsArg, toNativeArray<String>(info[0], 1, info.GetIsolate()));
257 v8SetReturnValue(info, v8Array(impl->arrayOfStringsMethodArrayOfStringsArg(arrayOfStringsArg), info.Holder(), info.GetIsolate()));
260 static void arrayOfStringsMethodArrayOfStringsArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
262 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
263 TestTypedefsV8Internal::arrayOfStringsMethodArrayOfStringsArgMethod(info);
264 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
267 static void stringArrayMethodStringArrayArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
269 if (UNLIKELY(info.Length() < 1)) {
270 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("stringArrayMethodStringArrayArg", "TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
273 TestTypedefs* impl = V8TestTypedefs::toNative(info.Holder());
274 Vector<String> stringArrayArg;
277 V8RethrowTryCatchScope rethrow(block);
278 TONATIVE_VOID_INTERNAL(stringArrayArg, toNativeArray<String>(info[0], 1, info.GetIsolate()));
280 v8SetReturnValue(info, v8Array(impl->stringArrayMethodStringArrayArg(stringArrayArg), info.Holder(), info.GetIsolate()));
283 static void stringArrayMethodStringArrayArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
285 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
286 TestTypedefsV8Internal::stringArrayMethodStringArrayArgMethod(info);
287 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
290 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
292 if (UNLIKELY(info.Length() < 1)) {
293 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
296 V8StringResource<> stringArg;
298 TOSTRING_VOID_INTERNAL(stringArg, info[0]);
300 RefPtr<TestTypedefs> impl = TestTypedefs::create(stringArg);
301 v8::Handle<v8::Object> wrapper = info.Holder();
302 V8DOMWrapper::associateObjectWithWrapper<V8TestTypedefs>(impl.release(), &V8TestTypedefs::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
303 v8SetReturnValue(info, wrapper);
306 } // namespace TestTypedefsV8Internal
308 static const V8DOMConfiguration::AttributeConfiguration V8TestTypedefsAttributes[] = {
309 {"uLongLongAttribute", TestTypedefsV8Internal::uLongLongAttributeAttributeGetterCallback, TestTypedefsV8Internal::uLongLongAttributeAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
310 {"tAttribute", TestTypedefsV8Internal::TestTypedefsConstructorGetter, TestTypedefsV8Internal::TestTypedefsForceSetAttributeOnThisCallback, 0, 0, const_cast<WrapperTypeInfo*>(&V8TestInterface::wrapperTypeInfo), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::DontEnum), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
313 static const V8DOMConfiguration::MethodConfiguration V8TestTypedefsMethods[] = {
314 {"voidMethodArrayOfLongsArg", TestTypedefsV8Internal::voidMethodArrayOfLongsArgMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
315 {"voidMethodFloatArgStringArg", TestTypedefsV8Internal::voidMethodFloatArgStringArgMethodCallback, 0, 2, V8DOMConfiguration::ExposedToAllScripts},
316 {"voidMethodTestCallbackInterfaceTypeArg", TestTypedefsV8Internal::voidMethodTestCallbackInterfaceTypeArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
317 {"uLongLongMethodTestInterfaceEmptyTypeSequenceArg", TestTypedefsV8Internal::uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
318 {"testInterfaceOrTestInterfaceEmptyMethod", TestTypedefsV8Internal::testInterfaceOrTestInterfaceEmptyMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
319 {"domStringOrDoubleMethod", TestTypedefsV8Internal::domStringOrDoubleMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
320 {"arrayOfStringsMethodArrayOfStringsArg", TestTypedefsV8Internal::arrayOfStringsMethodArrayOfStringsArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
321 {"stringArrayMethodStringArrayArg", TestTypedefsV8Internal::stringArrayMethodStringArrayArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
324 void V8TestTypedefs::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
326 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
327 if (!info.IsConstructCall()) {
328 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestTypedefs"), info.GetIsolate());
332 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
333 v8SetReturnValue(info, info.Holder());
337 TestTypedefsV8Internal::constructor(info);
340 static void installV8TestTypedefsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
342 functionTemplate->ReadOnlyPrototype();
344 v8::Local<v8::Signature> defaultSignature;
345 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestTypedefs", v8::Local<v8::FunctionTemplate>(), V8TestTypedefs::internalFieldCount,
346 V8TestTypedefsAttributes, WTF_ARRAY_LENGTH(V8TestTypedefsAttributes),
348 V8TestTypedefsMethods, WTF_ARRAY_LENGTH(V8TestTypedefsMethods),
350 functionTemplate->SetCallHandler(V8TestTypedefs::constructorCallback);
351 functionTemplate->SetLength(1);
352 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
353 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
355 // Custom toString template
356 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
359 v8::Handle<v8::FunctionTemplate> V8TestTypedefs::domTemplate(v8::Isolate* isolate)
361 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestTypedefsTemplate);
364 bool V8TestTypedefs::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
366 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
369 v8::Handle<v8::Object> V8TestTypedefs::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
371 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
374 TestTypedefs* V8TestTypedefs::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
376 return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
379 v8::Handle<v8::Object> wrap(TestTypedefs* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
382 ASSERT(!DOMDataStore::containsWrapper<V8TestTypedefs>(impl, isolate));
383 return V8TestTypedefs::createWrapper(impl, creationContext, isolate);
386 v8::Handle<v8::Object> V8TestTypedefs::createWrapper(PassRefPtr<TestTypedefs> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
389 ASSERT(!DOMDataStore::containsWrapper<V8TestTypedefs>(impl.get(), isolate));
390 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
391 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
392 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
393 // the same object de-ref functions, though, so use that as the basis of the check.
394 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
397 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
398 if (UNLIKELY(wrapper.IsEmpty()))
401 installConditionallyEnabledProperties(wrapper, isolate);
402 V8DOMWrapper::associateObjectWithWrapper<V8TestTypedefs>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
406 void V8TestTypedefs::derefObject(ScriptWrappableBase* internalPointer)
408 fromInternalPointer(internalPointer)->deref();
412 v8::Handle<v8::Value> toV8NoInline(TestTypedefs* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
414 return toV8(impl, creationContext, isolate);