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 "V8TestInterfaceConstructor.h"
10 #include "bindings/tests/v8/V8TestInterfaceEmpty.h"
11 #include "bindings/v8/Dictionary.h"
12 #include "bindings/v8/ExceptionState.h"
13 #include "bindings/v8/V8DOMConfiguration.h"
14 #include "bindings/v8/V8HiddenValue.h"
15 #include "bindings/v8/V8ObjectConstructor.h"
16 #include "core/dom/ContextFeatures.h"
17 #include "core/dom/Document.h"
18 #include "core/frame/LocalDOMWindow.h"
19 #include "core/frame/UseCounter.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(TestInterfaceConstructor* object)
29 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
30 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceConstructor::wrapperTypeInfo);
35 } // namespace WebCore
37 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceConstructor* object)
39 WebCore::initializeScriptWrappableForInterface(object);
43 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
45 namespace TestInterfaceConstructorV8Internal {
47 template <typename T> void V8_USE(T) { }
49 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
51 v8::Isolate* isolate = info.GetIsolate();
52 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
53 ExecutionContext* executionContext = currentExecutionContext(isolate);
54 Document& document = *toDocument(currentExecutionContext(isolate));
55 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, exceptionState);
56 if (exceptionState.throwIfNeeded())
59 v8::Handle<v8::Object> wrapper = info.Holder();
60 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
61 v8SetReturnValue(info, wrapper);
64 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
66 v8::Isolate* isolate = info.GetIsolate();
67 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
69 V8StringResource<> stringArg;
70 TestInterfaceEmpty* testInterfaceEmptyArg;
71 Dictionary dictionaryArg;
72 Vector<String> sequenceStringArg;
73 Vector<Dictionary> sequenceDictionaryArg;
74 Dictionary optionalDictionaryArg;
75 TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
78 V8RethrowTryCatchScope rethrow(block);
79 TONATIVE_VOID_INTERNAL(doubleArg, static_cast<double>(info[0]->NumberValue()));
80 TOSTRING_VOID_INTERNAL(stringArg, info[1]);
81 TONATIVE_VOID_INTERNAL(testInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[2]));
82 TONATIVE_VOID_INTERNAL(dictionaryArg, Dictionary(info[3], info.GetIsolate()));
83 if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
84 exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
85 exceptionState.throwIfNeeded();
88 TONATIVE_VOID_INTERNAL(sequenceStringArg, toNativeArray<String>(info[4], 5, info.GetIsolate()));
89 TONATIVE_VOID_INTERNAL(sequenceDictionaryArg, toNativeArray<Dictionary>(info[5], 6, info.GetIsolate()));
90 TONATIVE_VOID_INTERNAL(optionalDictionaryArg, Dictionary(info[6], info.GetIsolate()));
91 if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isObject()) {
92 exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
93 exceptionState.throwIfNeeded();
96 TONATIVE_VOID_INTERNAL(optionalTestInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[7]));
98 ExecutionContext* executionContext = currentExecutionContext(isolate);
99 Document& document = *toDocument(currentExecutionContext(isolate));
100 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
101 if (exceptionState.throwIfNeeded())
104 v8::Handle<v8::Object> wrapper = info.Holder();
105 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
106 v8SetReturnValue(info, wrapper);
109 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
111 v8::Isolate* isolate = info.GetIsolate();
112 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), isolate);
113 switch (std::min(8, info.Length())) {
116 TestInterfaceConstructorV8Internal::constructor1(info);
122 TestInterfaceConstructorV8Internal::constructor2(info);
128 TestInterfaceConstructorV8Internal::constructor2(info);
134 TestInterfaceConstructorV8Internal::constructor2(info);
139 if (info.Length() >= 0) {
140 throwArityTypeError(exceptionState, "[0, 6, 7, 8]", info.Length());
143 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(0, info.Length()));
144 exceptionState.throwIfNeeded();
147 exceptionState.throwTypeError("No matching constructor signature.");
148 exceptionState.throwIfNeeded();
151 } // namespace TestInterfaceConstructorV8Internal
153 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
155 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
156 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
157 if (!info.IsConstructCall()) {
158 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"), info.GetIsolate());
162 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
163 v8SetReturnValue(info, info.Holder());
167 TestInterfaceConstructorV8Internal::constructor(info);
170 static void configureV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
172 functionTemplate->ReadOnlyPrototype();
174 v8::Local<v8::Signature> defaultSignature;
175 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
180 functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
181 functionTemplate->SetLength(0);
182 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
183 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
185 // Custom toString template
186 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
189 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate)
191 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceConstructorTemplate);
194 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
196 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
199 v8::Handle<v8::Object> V8TestInterfaceConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
201 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
204 TestInterfaceConstructor* V8TestInterfaceConstructor::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
206 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
209 v8::Handle<v8::Object> wrap(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
212 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl, isolate));
213 return V8TestInterfaceConstructor::createWrapper(impl, creationContext, isolate);
216 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<TestInterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
219 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get(), isolate));
220 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
221 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
222 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
223 // the same object de-ref functions, though, so use that as the basis of the check.
224 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
227 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
228 if (UNLIKELY(wrapper.IsEmpty()))
231 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
232 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
236 void V8TestInterfaceConstructor::derefObject(void* object)
238 fromInternalPointer(object)->deref();
242 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
244 return toV8(impl, creationContext, isolate);
247 } // namespace WebCore