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 "V8TestInterfaceGarbageCollected.h"
10 #include "RuntimeEnabledFeatures.h"
11 #include "bindings/v8/ExceptionState.h"
12 #include "bindings/v8/V8DOMConfiguration.h"
13 #include "bindings/v8/V8HiddenValue.h"
14 #include "bindings/v8/V8ObjectConstructor.h"
15 #include "core/dom/ContextFeatures.h"
16 #include "core/dom/Document.h"
17 #include "core/frame/DOMWindow.h"
18 #include "platform/TraceEvent.h"
19 #include "wtf/GetPtr.h"
20 #include "wtf/RefPtr.h"
24 static void initializeScriptWrappableForInterface(TestInterfaceGarbageCollected* object)
26 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceGarbageCollected::wrapperTypeInfo);
32 } // namespace WebCore
34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceGarbageCollected* object)
36 WebCore::initializeScriptWrappableForInterface(object);
40 const WrapperTypeInfo V8TestInterfaceGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceGarbageCollected::domTemplate, V8TestInterfaceGarbageCollected::derefObject, 0, V8TestInterfaceGarbageCollected::toEventTarget, 0, V8TestInterfaceGarbageCollected::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, GarbageCollectedObject };
42 namespace TestInterfaceGarbageCollectedV8Internal {
44 template <typename T> void V8_USE(T) { }
46 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
48 v8::Handle<v8::Object> holder = info.Holder();
49 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(holder);
50 v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl);
53 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
55 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
56 TestInterfaceGarbageCollectedV8Internal::attr1AttributeGetter(info);
57 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
60 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
62 v8::Handle<v8::Object> holder = info.Holder();
63 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(holder);
64 TONATIVE_VOID(TestInterfaceGarbageCollected*, cppValue, V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
65 impl->setAttr1(WTF::getPtr(cppValue));
68 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
70 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
71 TestInterfaceGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info);
72 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
75 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
77 if (UNLIKELY(info.Length() < 1)) {
78 throwArityTypeErrorForMethod("func", "TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate());
81 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(info.Holder());
82 TONATIVE_VOID(TestInterfaceGarbageCollected*, arg, V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
86 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
88 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
89 TestInterfaceGarbageCollectedV8Internal::funcMethod(info);
90 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
93 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
95 v8::Isolate* isolate = info.GetIsolate();
96 if (UNLIKELY(info.Length() < 1)) {
97 throwArityTypeErrorForConstructor("TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate());
100 TOSTRING_VOID(V8StringResource<>, str, info[0]);
101 RawPtr<TestInterfaceGarbageCollected> impl = TestInterfaceGarbageCollected::create(str);
103 v8::Handle<v8::Object> wrapper = info.Holder();
104 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl.release(), &V8TestInterfaceGarbageCollected::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
105 v8SetReturnValue(info, wrapper);
108 } // namespace TestInterfaceGarbageCollectedV8Internal
110 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceGarbageCollectedAttributes[] = {
111 {"attr1", TestInterfaceGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
114 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceGarbageCollectedMethods[] = {
115 {"func", TestInterfaceGarbageCollectedV8Internal::funcMethodCallback, 0, 1},
118 void V8TestInterfaceGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
120 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
121 if (!info.IsConstructCall()) {
122 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceGarbageCollected"), info.GetIsolate());
126 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
127 v8SetReturnValue(info, info.Holder());
131 TestInterfaceGarbageCollectedV8Internal::constructor(info);
134 static void configureV8TestInterfaceGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
136 functionTemplate->ReadOnlyPrototype();
138 v8::Local<v8::Signature> defaultSignature;
139 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceGarbageCollected::internalFieldCount,
140 V8TestInterfaceGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedAttributes),
142 V8TestInterfaceGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedMethods),
144 functionTemplate->SetCallHandler(V8TestInterfaceGarbageCollected::constructorCallback);
145 functionTemplate->SetLength(1);
146 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
147 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
149 // Custom toString template
150 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
153 v8::Handle<v8::FunctionTemplate> V8TestInterfaceGarbageCollected::domTemplate(v8::Isolate* isolate)
155 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
156 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
157 if (!result.IsEmpty())
160 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
161 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
162 configureV8TestInterfaceGarbageCollectedTemplate(result, isolate);
163 data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
167 bool V8TestInterfaceGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
169 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
172 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
174 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
177 TestInterfaceGarbageCollected* V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
179 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
182 EventTarget* V8TestInterfaceGarbageCollected::toEventTarget(v8::Handle<v8::Object> object)
184 return toNative(object);
187 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::createWrapper(RawPtr<TestInterfaceGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
190 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceGarbageCollected>(impl.get(), isolate));
191 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
192 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
193 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
194 // the same object de-ref functions, though, so use that as the basis of the check.
195 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
198 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
199 if (UNLIKELY(wrapper.IsEmpty()))
202 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
203 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
207 void V8TestInterfaceGarbageCollected::derefObject(void* object)
212 v8::Handle<v8::Value> toV8NoInline(TestInterfaceGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
214 return toV8(impl, creationContext, isolate);
217 } // namespace WebCore