2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
34 #include "V8TestInterfaceConstructor2.h"
36 #include "RuntimeEnabledFeatures.h"
37 #include "V8TestInterfaceEmpty.h"
38 #include "bindings/v8/Dictionary.h"
39 #include "bindings/v8/ExceptionState.h"
40 #include "bindings/v8/V8DOMConfiguration.h"
41 #include "bindings/v8/V8ObjectConstructor.h"
42 #include "core/dom/ContextFeatures.h"
43 #include "core/dom/Document.h"
44 #include "platform/TraceEvent.h"
45 #include "wtf/GetPtr.h"
46 #include "wtf/RefPtr.h"
50 static void initializeScriptWrappableForInterface(TestInterfaceConstructor2* object)
52 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
53 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceConstructor2::wrapperTypeInfo);
58 } // namespace WebCore
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::TestInterfaceConstructor2* object)
66 WebCore::initializeScriptWrappableForInterface(object);
70 const WrapperTypeInfo V8TestInterfaceConstructor2::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceConstructor2::domTemplate, V8TestInterfaceConstructor2::derefObject, 0, 0, 0, V8TestInterfaceConstructor2::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
72 namespace TestInterfaceConstructor2V8Internal {
74 template <typename T> void V8_USE(T) { }
76 static void constructor1(const v8::FunctionCallbackInfo<v8::Value>& info)
78 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringArg, info[0]);
79 RefPtr<TestInterfaceConstructor2> impl = TestInterfaceConstructor2::create(stringArg);
80 v8::Handle<v8::Object> wrapper = info.Holder();
82 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor2>(impl.release(), &V8TestInterfaceConstructor2::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
83 v8SetReturnValue(info, wrapper);
86 static void constructor2(const v8::FunctionCallbackInfo<v8::Value>& info)
88 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor2", info.Holder(), info.GetIsolate());
89 V8TRYCATCH_VOID(TestInterfaceEmpty*, testInterfaceEmptyArg, V8TestInterfaceEmpty::hasInstance(info[0], info.GetIsolate()) ? V8TestInterfaceEmpty::toNative(v8::Handle<v8::Object>::Cast(info[0])) : 0);
90 V8TRYCATCH_EXCEPTION_VOID(int, longArg, toInt32(info[1], exceptionState), exceptionState);
91 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, defaultUndefinedOptionalStringArg, info[2]);
92 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, defaultNullStringOptionalStringArg, argumentOrNull(info, 3));
93 V8TRYCATCH_VOID(Dictionary, defaultUndefinedOptionalDictionaryArg, Dictionary(info[4], info.GetIsolate()));
94 if (!defaultUndefinedOptionalDictionaryArg.isUndefinedOrNull() && !defaultUndefinedOptionalDictionaryArg.isObject()) {
95 exceptionState.throwTypeError("parameter 5 ('defaultUndefinedOptionalDictionaryArg') is not an object.");
96 exceptionState.throwIfNeeded();
99 RefPtr<TestInterfaceConstructor2> impl = TestInterfaceConstructor2::create(testInterfaceEmptyArg, longArg, defaultUndefinedOptionalStringArg, defaultNullStringOptionalStringArg, defaultUndefinedOptionalDictionaryArg);
100 v8::Handle<v8::Object> wrapper = info.Holder();
102 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor2>(impl.release(), &V8TestInterfaceConstructor2::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Dependent);
103 v8SetReturnValue(info, wrapper);
106 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
108 if (((info.Length() == 1))) {
109 TestInterfaceConstructor2V8Internal::constructor1(info);
112 if (((info.Length() == 2) && (V8TestInterfaceEmpty::hasInstance(info[0], info.GetIsolate()))) || ((info.Length() == 3) && (V8TestInterfaceEmpty::hasInstance(info[0], info.GetIsolate()))) || ((info.Length() == 4) && (V8TestInterfaceEmpty::hasInstance(info[0], info.GetIsolate()))) || ((info.Length() == 5) && (V8TestInterfaceEmpty::hasInstance(info[0], info.GetIsolate())) && (info[4]->IsUndefined() || info[4]->IsObject()))) {
113 TestInterfaceConstructor2V8Internal::constructor2(info);
116 ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor2", info.Holder(), info.GetIsolate());
117 if (UNLIKELY(info.Length() < 1)) {
118 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length()));
119 exceptionState.throwIfNeeded();
122 exceptionState.throwTypeError("No matching constructor signature.");
123 exceptionState.throwIfNeeded();
126 } // namespace TestInterfaceConstructor2V8Internal
128 void V8TestInterfaceConstructor2::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
130 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
131 if (!info.IsConstructCall()) {
132 throwTypeError(ExceptionMessages::failedToConstruct("TestInterfaceConstructor2", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
136 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
137 v8SetReturnValue(info, info.Holder());
141 TestInterfaceConstructor2V8Internal::constructor(info);
144 static void configureV8TestInterfaceConstructor2Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
146 functionTemplate->ReadOnlyPrototype();
148 v8::Local<v8::Signature> defaultSignature;
149 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceConstructor2", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceConstructor2::internalFieldCount,
153 isolate, currentWorldType);
154 functionTemplate->SetCallHandler(V8TestInterfaceConstructor2::constructorCallback);
155 functionTemplate->SetLength(1);
156 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
157 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
159 // Custom toString template
160 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
163 v8::Handle<v8::FunctionTemplate> V8TestInterfaceConstructor2::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
165 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
166 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
167 if (result != data->templateMap(currentWorldType).end())
168 return result->value.newLocal(isolate);
170 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
171 v8::EscapableHandleScope handleScope(isolate);
172 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
173 configureV8TestInterfaceConstructor2Template(templ, isolate, currentWorldType);
174 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
175 return handleScope.Escape(templ);
178 bool V8TestInterfaceConstructor2::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
180 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
181 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
184 v8::Handle<v8::Object> V8TestInterfaceConstructor2::createWrapper(PassRefPtr<TestInterfaceConstructor2> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
187 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceConstructor2>(impl.get(), isolate));
188 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
189 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
190 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
191 // the same object de-ref functions, though, so use that as the basis of the check.
192 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
195 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
196 if (UNLIKELY(wrapper.IsEmpty()))
199 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
200 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceConstructor2>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
204 void V8TestInterfaceConstructor2::derefObject(void* object)
206 fromInternalPointer(object)->deref();
210 v8::Handle<v8::Value> toV8NoInline(TestInterfaceConstructor2* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
212 return toV8(impl, creationContext, isolate);
215 } // namespace WebCore