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/core/v8/Dictionary.h"
11 #include "bindings/core/v8/ExceptionState.h"
12 #include "bindings/core/v8/V8DOMConfiguration.h"
13 #include "bindings/core/v8/V8HiddenValue.h"
14 #include "bindings/core/v8/V8ObjectConstructor.h"
15 #include "bindings/tests/v8/V8TestInterfaceEmpty.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);
37 void webCoreInitializeScriptWrappableForInterface(blink::TestInterfaceConstructor* object)
39 blink::initializeScriptWrappableForInterface(object);
43 const WrapperTypeInfo V8TestInterfaceConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, 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 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
52 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
53 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
54 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, exceptionState);
55 if (exceptionState.hadException()) {
56 exceptionState.throwIfNeeded();
59 v8::Handle<v8::Object> wrapper = info.Holder();
60 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
61 v8SetReturnValue(info, wrapper);
64 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
66 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
68 V8StringResource<> stringArg;
69 TestInterfaceEmpty* testInterfaceEmptyArg;
70 Dictionary dictionaryArg;
71 Vector<String> sequenceStringArg;
72 Vector<Dictionary> sequenceDictionaryArg;
73 Dictionary optionalDictionaryArg;
74 TestInterfaceEmpty* optionalTestInterfaceEmptyArg;
77 V8RethrowTryCatchScope rethrow(block);
78 TONATIVE_VOID_INTERNAL(doubleArg, static_cast<double>(info[0]->NumberValue()));
79 TOSTRING_VOID_INTERNAL(stringArg, info[1]);
80 TONATIVE_VOID_INTERNAL(testInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[2]));
81 TONATIVE_VOID_INTERNAL(dictionaryArg, Dictionary(info[3], info.GetIsolate()));
82 if (!dictionaryArg.isUndefinedOrNull() && !dictionaryArg.isObject()) {
83 exceptionState.throwTypeError("parameter 4 ('dictionaryArg') is not an object.");
84 exceptionState.throwIfNeeded();
87 TONATIVE_VOID_INTERNAL(sequenceStringArg, toNativeArray<String>(info[4], 5, info.GetIsolate()));
88 TONATIVE_VOID_INTERNAL(sequenceDictionaryArg, toNativeArray<Dictionary>(info[5], 6, info.GetIsolate()));
89 TONATIVE_VOID_INTERNAL(optionalDictionaryArg, Dictionary(info[6], info.GetIsolate()));
90 if (!optionalDictionaryArg.isUndefinedOrNull() && !optionalDictionaryArg.isObject()) {
91 exceptionState.throwTypeError("parameter 7 ('optionalDictionaryArg') is not an object.");
92 exceptionState.throwIfNeeded();
95 TONATIVE_VOID_INTERNAL(optionalTestInterfaceEmptyArg, V8TestInterfaceEmpty::toNativeWithTypeCheck(info.GetIsolate(), info[7]));
97 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
98 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
99 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, doubleArg, stringArg, testInterfaceEmptyArg, dictionaryArg, sequenceStringArg, sequenceDictionaryArg, optionalDictionaryArg, optionalTestInterfaceEmptyArg, exceptionState);
100 if (exceptionState.hadException()) {
101 exceptionState.throwIfNeeded();
104 v8::Handle<v8::Object> wrapper = info.Holder();
105 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
106 v8SetReturnValue(info, wrapper);
109 static void constructor3(const v8::FunctionCallbackInfo<v8::Value>& info)
111 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
112 V8StringResource<> arg;
113 V8StringResource<> optArg;
115 TOSTRING_VOID_INTERNAL(arg, info[0]);
116 if (UNLIKELY(info.Length() <= 1)) {
117 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
118 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
119 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, exceptionState);
120 if (exceptionState.hadException()) {
121 exceptionState.throwIfNeeded();
124 v8::Handle<v8::Object> wrapper = info.Holder();
125 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
126 v8SetReturnValue(info, wrapper);
129 TOSTRING_VOID_INTERNAL(optArg, info[1]);
131 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
132 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
133 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, optArg, exceptionState);
134 if (exceptionState.hadException()) {
135 exceptionState.throwIfNeeded();
138 v8::Handle<v8::Object> wrapper = info.Holder();
139 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
140 v8SetReturnValue(info, wrapper);
143 static void constructor4(const v8::FunctionCallbackInfo<v8::Value>& info)
145 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
146 V8StringResource<> arg;
147 V8StringResource<> arg2;
148 V8StringResource<> arg3;
150 TOSTRING_VOID_INTERNAL(arg, info[0]);
151 TOSTRING_VOID_INTERNAL(arg2, info[1]);
152 TOSTRING_VOID_INTERNAL(arg3, info[2]);
154 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
155 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
156 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::create(executionContext, document, arg, arg2, arg3, exceptionState);
157 if (exceptionState.hadException()) {
158 exceptionState.throwIfNeeded();
161 v8::Handle<v8::Object> wrapper = info.Holder();
162 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
163 v8SetReturnValue(info, wrapper);
166 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
168 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
169 switch (std::min(8, info.Length())) {
172 TestInterfaceConstructorV8Internal::constructor1(info);
178 TestInterfaceConstructorV8Internal::constructor3(info);
184 TestInterfaceConstructorV8Internal::constructor3(info);
190 TestInterfaceConstructorV8Internal::constructor4(info);
196 TestInterfaceConstructorV8Internal::constructor2(info);
202 TestInterfaceConstructorV8Internal::constructor2(info);
208 TestInterfaceConstructorV8Internal::constructor2(info);
213 if (info.Length() >= 0) {
214 throwArityTypeError(exceptionState, "[0, 1, 2, 3, 6, 7, 8]", info.Length());
217 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(0, info.Length()));
218 exceptionState.throwIfNeeded();
221 exceptionState.throwTypeError("No matching constructor signature.");
222 exceptionState.throwIfNeeded();
225 } // namespace TestInterfaceConstructorV8Internal
227 const WrapperTypeInfo V8TestInterfaceConstructorConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructorConstructor::domTemplate, V8TestInterfaceConstructor::derefObject, 0, 0, 0, V8TestInterfaceConstructor::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
229 static void V8TestInterfaceConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
231 if (!info.IsConstructCall()) {
232 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Audio"), info.GetIsolate());
236 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
237 v8SetReturnValue(info, info.Holder());
240 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
241 if (UNLIKELY(info.Length() < 1)) {
242 setMinimumArityTypeError(exceptionState, 1, info.Length());
243 exceptionState.throwIfNeeded();
246 V8StringResource<> arg;
247 V8StringResource<> optArg;
249 TOSTRING_VOID_INTERNAL(arg, info[0]);
250 if (UNLIKELY(info.Length() <= 1)) {
251 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
252 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
253 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, exceptionState);
254 if (exceptionState.hadException()) {
255 exceptionState.throwIfNeeded();
258 v8::Handle<v8::Object> wrapper = info.Holder();
259 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
260 v8SetReturnValue(info, wrapper);
263 TOSTRING_VOID_INTERNAL(optArg, info[1]);
265 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
266 Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
267 RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(executionContext, document, arg, optArg, exceptionState);
268 if (exceptionState.hadException()) {
269 exceptionState.throwIfNeeded();
272 v8::Handle<v8::Object> wrapper = info.Holder();
273 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl.release(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
274 v8SetReturnValue(info, wrapper);
277 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructorConstructor::domTemplate(v8::Isolate* isolate)
279 static int domTemplateKey; // This address is used for a key to look up the dom template.
280 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
281 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
282 if (!result.IsEmpty())
285 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
286 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceConstructorConstructorCallback);
287 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
288 instanceTemplate->SetInternalFieldCount(V8TestInterfaceConstructor::internalFieldCount);
289 result->SetClassName(v8AtomicString(isolate, "TestInterfaceConstructor"));
290 result->Inherit(V8TestInterfaceConstructor::domTemplate(isolate));
291 data->setDOMTemplate(&domTemplateKey, result);
295 void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
297 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
298 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
299 if (!info.IsConstructCall()) {
300 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"), info.GetIsolate());
304 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
305 v8SetReturnValue(info, info.Holder());
309 TestInterfaceConstructorV8Internal::constructor(info);
312 static void installV8TestInterfaceConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
314 functionTemplate->ReadOnlyPrototype();
316 v8::Local<v8::Signature> defaultSignature;
317 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor::internalFieldCount,
322 functionTemplate->SetCallHandler(V8TestInterfaceConstructor::constructorCallback);
323 functionTemplate->SetLength(0);
324 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
325 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
327 // Custom toString template
328 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
331 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor::domTemplate(v8::Isolate* isolate)
333 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceConstructorTemplate);
336 bool V8TestInterfaceConstructor::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
338 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
341 v8::Handle<v8::Object> V8TestInterfaceConstructor::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
343 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
346 TestInterfaceConstructor* V8TestInterfaceConstructor::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
348 return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
351 v8::Handle<v8::Object> wrap(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
354 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl, isolate));
355 return V8TestInterfaceConstructor::createWrapper(impl, creationContext, isolate);
358 v8::Handle<v8::Object> V8TestInterfaceConstructor::createWrapper(PassRefPtr<TestInterfaceConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
361 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor>(impl.get(), isolate));
362 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
363 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
364 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
365 // the same object de-ref functions, though, so use that as the basis of the check.
366 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
369 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
370 if (UNLIKELY(wrapper.IsEmpty()))
373 installConditionallyEnabledProperties(wrapper, isolate);
374 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
378 void V8TestInterfaceConstructor::derefObject(ScriptWrappableBase* internalPointer)
380 fromInternalPointer(internalPointer)->deref();
384 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
386 return toV8(impl, creationContext, isolate);