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 "V8TestInterfaceWillBeGarbageCollected.h"
10 #include "bindings/core/v8/ExceptionState.h"
11 #include "bindings/core/v8/V8DOMConfiguration.h"
12 #include "bindings/core/v8/V8HiddenValue.h"
13 #include "bindings/core/v8/V8ObjectConstructor.h"
14 #include "bindings/tests/v8/V8TestInterfaceWillBeGarbageCollected.h"
15 #include "core/dom/ContextFeatures.h"
16 #include "core/dom/Document.h"
17 #include "core/frame/LocalDOMWindow.h"
18 #include "platform/RuntimeEnabledFeatures.h"
19 #include "platform/TraceEvent.h"
20 #include "wtf/GetPtr.h"
21 #include "wtf/RefPtr.h"
25 static void initializeScriptWrappableForInterface(TestInterfaceWillBeGarbageCollected* object)
27 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
28 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo);
35 void webCoreInitializeScriptWrappableForInterface(blink::TestInterfaceWillBeGarbageCollected* object)
37 blink::initializeScriptWrappableForInterface(object);
41 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollected::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject };
43 namespace TestInterfaceWillBeGarbageCollectedV8Internal {
45 template <typename T> void V8_USE(T) { }
47 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
49 v8::Handle<v8::Object> holder = info.Holder();
50 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(holder);
51 v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl);
54 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
56 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
57 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetter(info);
58 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
61 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
63 v8::Handle<v8::Object> holder = info.Holder();
64 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(holder);
65 TONATIVE_VOID(TestInterfaceWillBeGarbageCollected*, cppValue, V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), v8Value));
66 impl->setAttr1(WTF::getPtr(cppValue));
69 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
71 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter");
72 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info);
73 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
76 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
78 if (UNLIKELY(info.Length() < 1)) {
79 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("func", "TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
82 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(info.Holder());
83 TestInterfaceWillBeGarbageCollected* arg;
86 V8RethrowTryCatchScope rethrow(block);
87 TONATIVE_VOID_INTERNAL(arg, V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), info[0]));
92 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
94 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
95 TestInterfaceWillBeGarbageCollectedV8Internal::funcMethod(info);
96 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
99 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
101 if (UNLIKELY(info.Length() < 1)) {
102 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
105 V8StringResource<> str;
107 TOSTRING_VOID_INTERNAL(str, info[0]);
109 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::create(str);
110 v8::Handle<v8::Object> wrapper = info.Holder();
111 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
112 v8SetReturnValue(info, wrapper);
115 } // namespace TestInterfaceWillBeGarbageCollectedV8Internal
117 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceWillBeGarbageCollectedAttributes[] = {
118 {"attr1", TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance},
121 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceWillBeGarbageCollectedMethods[] = {
122 {"func", TestInterfaceWillBeGarbageCollectedV8Internal::funcMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
125 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, 0, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject };
127 static void V8TestInterfaceWillBeGarbageCollectedConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
129 if (!info.IsConstructCall()) {
130 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterface"), info.GetIsolate());
134 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
135 v8SetReturnValue(info, info.Holder());
138 if (UNLIKELY(info.Length() < 1)) {
139 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate());
142 V8StringResource<> str;
144 TOSTRING_VOID_INTERNAL(str, info[0]);
146 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::createForJSConstructor(str);
147 v8::Handle<v8::Object> wrapper = info.Holder();
148 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo, wrapper, info.GetIsolate(), WrapperConfiguration::Independent);
149 v8SetReturnValue(info, wrapper);
152 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate(v8::Isolate* isolate)
154 static int domTemplateKey; // This address is used for a key to look up the dom template.
155 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
156 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
157 if (!result.IsEmpty())
160 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate");
161 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceWillBeGarbageCollectedConstructorCallback);
162 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
163 instanceTemplate->SetInternalFieldCount(V8TestInterfaceWillBeGarbageCollected::internalFieldCount);
164 result->SetClassName(v8AtomicString(isolate, "TestInterfaceWillBeGarbageCollected"));
165 result->Inherit(V8TestInterfaceWillBeGarbageCollected::domTemplate(isolate));
166 data->setDOMTemplate(&domTemplateKey, result);
170 void V8TestInterfaceWillBeGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
172 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
173 if (!info.IsConstructCall()) {
174 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceWillBeGarbageCollected"), info.GetIsolate());
178 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
179 v8SetReturnValue(info, info.Holder());
183 TestInterfaceWillBeGarbageCollectedV8Internal::constructor(info);
186 static void installV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
188 functionTemplate->ReadOnlyPrototype();
190 v8::Local<v8::Signature> defaultSignature;
191 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount,
192 V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes),
194 V8TestInterfaceWillBeGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedMethods),
196 functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback);
197 functionTemplate->SetLength(1);
198 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
199 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
201 // Custom toString template
202 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
205 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollected::domTemplate(v8::Isolate* isolate)
207 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceWillBeGarbageCollectedTemplate);
210 bool V8TestInterfaceWillBeGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
212 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
215 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
217 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
220 TestInterfaceWillBeGarbageCollected* V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
222 return hasInstance(value, isolate) ? fromInternalPointer(blink::toInternalPointer(v8::Handle<v8::Object>::Cast(value))) : 0;
225 EventTarget* V8TestInterfaceWillBeGarbageCollected::toEventTarget(v8::Handle<v8::Object> object)
227 return toNative(object);
230 v8::Handle<v8::Object> wrap(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
233 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, isolate));
234 return V8TestInterfaceWillBeGarbageCollected::createWrapper(impl, creationContext, isolate);
237 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::createWrapper(PassRefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
240 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.get(), isolate));
241 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
242 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
243 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
244 // the same object de-ref functions, though, so use that as the basis of the check.
245 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
248 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
249 if (UNLIKELY(wrapper.IsEmpty()))
252 installConditionallyEnabledProperties(wrapper, isolate);
253 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
257 void V8TestInterfaceWillBeGarbageCollected::derefObject(ScriptWrappableBase* internalPointer)
260 fromInternalPointer(internalPointer)->deref();
261 #endif // !ENABLE(OILPAN)
265 v8::Handle<v8::Value> toV8NoInline(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
267 return toV8(impl, creationContext, isolate);