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 "V8TestInterfaceCustomConstructor.h"
36 #include "RuntimeEnabledFeatures.h"
37 #include "bindings/v8/ExceptionState.h"
38 #include "bindings/v8/V8DOMConfiguration.h"
39 #include "bindings/v8/V8ObjectConstructor.h"
40 #include "core/dom/ContextFeatures.h"
41 #include "core/dom/Document.h"
42 #include "platform/TraceEvent.h"
43 #include "wtf/GetPtr.h"
44 #include "wtf/RefPtr.h"
48 static void initializeScriptWrappableForInterface(TestInterfaceCustomConstructor* object)
50 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
51 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceCustomConstructor::wrapperTypeInfo);
56 } // namespace WebCore
58 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
59 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
60 // in the global namespace.
61 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
62 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceCustomConstructor* object)
64 WebCore::initializeScriptWrappableForInterface(object);
68 const WrapperTypeInfo V8TestInterfaceCustomConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceCustomConstructor::domTemplate, V8TestInterfaceCustomConstructor::derefObject, 0, 0, 0, V8TestInterfaceCustomConstructor::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
70 namespace TestInterfaceCustomConstructorV8Internal {
72 template <typename T> void V8_USE(T) { }
74 } // namespace TestInterfaceCustomConstructorV8Internal
76 void V8TestInterfaceCustomConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
78 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
79 if (!info.IsConstructCall()) {
80 throwTypeError(ExceptionMessages::failedToConstruct("TestInterfaceCustomConstructor", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
84 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
85 v8SetReturnValue(info, info.Holder());
89 V8TestInterfaceCustomConstructor::constructorCustom(info);
92 static void configureV8TestInterfaceCustomConstructorTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate, WrapperWorldType currentWorldType)
94 functionTemplate->ReadOnlyPrototype();
96 v8::Local<v8::Signature> defaultSignature;
97 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceCustomConstructor", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceCustomConstructor::internalFieldCount,
101 isolate, currentWorldType);
102 functionTemplate->SetCallHandler(V8TestInterfaceCustomConstructor::constructorCallback);
103 functionTemplate->SetLength(0);
104 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
105 v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
107 // Custom toString template
108 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
111 v8::Handle<v8::FunctionTemplate> V8TestInterfaceCustomConstructor::domTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
113 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
114 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&wrapperTypeInfo);
115 if (result != data->templateMap(currentWorldType).end())
116 return result->value.newLocal(isolate);
118 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
119 v8::EscapableHandleScope handleScope(isolate);
120 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
121 configureV8TestInterfaceCustomConstructorTemplate(templ, isolate, currentWorldType);
122 data->templateMap(currentWorldType).add(&wrapperTypeInfo, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
123 return handleScope.Escape(templ);
126 bool V8TestInterfaceCustomConstructor::hasInstance(v8::Handle<v8::Value> jsValue, v8::Isolate* isolate)
128 return V8PerIsolateData::from(isolate)->hasInstanceInMainWorld(&wrapperTypeInfo, jsValue)
129 || V8PerIsolateData::from(isolate)->hasInstanceInNonMainWorld(&wrapperTypeInfo, jsValue);
132 v8::Handle<v8::Object> V8TestInterfaceCustomConstructor::createWrapper(PassRefPtr<TestInterfaceCustomConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
135 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceCustomConstructor>(impl.get(), isolate));
136 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
137 const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
138 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
139 // the same object de-ref functions, though, so use that as the basis of the check.
140 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
143 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
144 if (UNLIKELY(wrapper.IsEmpty()))
147 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
148 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceCustomConstructor>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
152 void V8TestInterfaceCustomConstructor::derefObject(void* object)
154 fromInternalPointer(object)->deref();
158 v8::Handle<v8::Value> toV8NoInline(TestInterfaceCustomConstructor* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
160 return toV8(impl, creationContext, isolate);
163 } // namespace WebCore