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. 4 5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! 6 7 #include "config.h" 8 #include "V8TestInterfaceWillBeGarbageCollected.h" 9 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/core/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" 22 23 namespace blink { 24 25 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollected::domTemplate, V8TestInterfaceWillBeGarbageCollected::refObject, V8TestInterfaceWillBeGarbageCollected::derefObject, V8TestInterfaceWillBeGarbageCollected::createPersistentHandle, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledProperties, &V8EventTarget::wrapperTypeInfo, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::WillBeGarbageCollectedObject }; 26 27 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in TestInterfaceWillBeGarbageCollected.h. 28 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in 29 // bindings/core/v8/ScriptWrappable.h. 30 const WrapperTypeInfo& TestInterfaceWillBeGarbageCollected::s_wrapperTypeInfo = V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo; 31 32 namespace TestInterfaceWillBeGarbageCollectedV8Internal { 33 34 template <typename T> void V8_USE(T) { } 35 36 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 37 { 38 v8::Handle<v8::Object> holder = info.Holder(); 39 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toImpl(holder); 40 v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl); 41 } 42 43 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 44 { 45 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 46 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetter(info); 47 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 48 } 49 50 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 51 { 52 v8::Handle<v8::Object> holder = info.Holder(); 53 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toImpl(holder); 54 TestInterfaceWillBeGarbageCollected* cppValue = V8TestInterfaceWillBeGarbageCollected::toImplWithTypeCheck(info.GetIsolate(), v8Value); 55 impl->setAttr1(WTF::getPtr(cppValue)); 56 } 57 58 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 59 { 60 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter"); 61 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info); 62 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 63 } 64 65 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 66 { 67 if (UNLIKELY(info.Length() < 1)) { 68 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("func", "TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate()); 69 return; 70 } 71 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toImpl(info.Holder()); 72 TestInterfaceWillBeGarbageCollected* arg; 73 { 74 arg = V8TestInterfaceWillBeGarbageCollected::toImplWithTypeCheck(info.GetIsolate(), info[0]); 75 } 76 impl->func(arg); 77 } 78 79 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 80 { 81 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 82 TestInterfaceWillBeGarbageCollectedV8Internal::funcMethod(info); 83 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 84 } 85 86 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 87 { 88 if (UNLIKELY(info.Length() < 1)) { 89 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate()); 90 return; 91 } 92 V8StringResource<> str; 93 { 94 TOSTRING_VOID_INTERNAL(str, info[0]); 95 } 96 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::create(str); 97 v8::Handle<v8::Object> wrapper = info.Holder(); 98 impl->associateWithWrapper(&V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo, wrapper, info.GetIsolate()); 99 v8SetReturnValue(info, wrapper); 100 } 101 102 } // namespace TestInterfaceWillBeGarbageCollectedV8Internal 103 104 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceWillBeGarbageCollectedAttributes[] = { 105 {"attr1", TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 106 }; 107 108 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceWillBeGarbageCollectedMethods[] = { 109 {"func", TestInterfaceWillBeGarbageCollectedV8Internal::funcMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts}, 110 }; 111 112 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate, V8TestInterfaceWillBeGarbageCollected::refObject, V8TestInterfaceWillBeGarbageCollected::derefObject, V8TestInterfaceWillBeGarbageCollected::createPersistentHandle, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledMethods, V8TestInterfaceWillBeGarbageCollected::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::WillBeGarbageCollectedObject }; 113 114 static void V8TestInterfaceWillBeGarbageCollectedConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 115 { 116 if (!info.IsConstructCall()) { 117 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterface"), info.GetIsolate()); 118 return; 119 } 120 121 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 122 v8SetReturnValue(info, info.Holder()); 123 return; 124 } 125 if (UNLIKELY(info.Length() < 1)) { 126 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()), info.GetIsolate()); 127 return; 128 } 129 V8StringResource<> str; 130 { 131 TOSTRING_VOID_INTERNAL(str, info[0]); 132 } 133 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::createForJSConstructor(str); 134 v8::Handle<v8::Object> wrapper = info.Holder(); 135 impl->associateWithWrapper(&V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo, wrapper, info.GetIsolate()); 136 v8SetReturnValue(info, wrapper); 137 } 138 139 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate(v8::Isolate* isolate) 140 { 141 static int domTemplateKey; // This address is used for a key to look up the dom template. 142 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 143 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey); 144 if (!result.IsEmpty()) 145 return result; 146 147 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "BuildDOMTemplate"); 148 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceWillBeGarbageCollectedConstructorCallback); 149 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); 150 instanceTemplate->SetInternalFieldCount(V8TestInterfaceWillBeGarbageCollected::internalFieldCount); 151 result->SetClassName(v8AtomicString(isolate, "TestInterfaceWillBeGarbageCollected")); 152 result->Inherit(V8TestInterfaceWillBeGarbageCollected::domTemplate(isolate)); 153 data->setDOMTemplate(&domTemplateKey, result); 154 return result; 155 } 156 157 void V8TestInterfaceWillBeGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 158 { 159 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor"); 160 if (!info.IsConstructCall()) { 161 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceWillBeGarbageCollected"), info.GetIsolate()); 162 return; 163 } 164 165 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 166 v8SetReturnValue(info, info.Holder()); 167 return; 168 } 169 170 TestInterfaceWillBeGarbageCollectedV8Internal::constructor(info); 171 } 172 173 static void installV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 174 { 175 functionTemplate->ReadOnlyPrototype(); 176 177 v8::Local<v8::Signature> defaultSignature; 178 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount, 179 V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes), 180 0, 0, 181 V8TestInterfaceWillBeGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedMethods), 182 isolate); 183 functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback); 184 functionTemplate->SetLength(1); 185 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 186 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 187 188 // Custom toString template 189 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 190 } 191 192 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollected::domTemplate(v8::Isolate* isolate) 193 { 194 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceWillBeGarbageCollectedTemplate); 195 } 196 197 bool V8TestInterfaceWillBeGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 198 { 199 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 200 } 201 202 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 203 { 204 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 205 } 206 207 TestInterfaceWillBeGarbageCollected* V8TestInterfaceWillBeGarbageCollected::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 208 { 209 return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<TestInterfaceWillBeGarbageCollected>() : 0; 210 } 211 212 EventTarget* V8TestInterfaceWillBeGarbageCollected::toEventTarget(v8::Handle<v8::Object> object) 213 { 214 return toImpl(object); 215 } 216 217 218 void V8TestInterfaceWillBeGarbageCollected::refObject(ScriptWrappableBase* internalPointer) 219 { 220 #if !ENABLE(OILPAN) 221 internalPointer->toImpl<TestInterfaceWillBeGarbageCollected>()->ref(); 222 #endif 223 } 224 225 void V8TestInterfaceWillBeGarbageCollected::derefObject(ScriptWrappableBase* internalPointer) 226 { 227 #if !ENABLE(OILPAN) 228 internalPointer->toImpl<TestInterfaceWillBeGarbageCollected>()->deref(); 229 #endif 230 } 231 232 WrapperPersistentNode* V8TestInterfaceWillBeGarbageCollected::createPersistentHandle(ScriptWrappableBase* internalPointer) 233 { 234 #if ENABLE(OILPAN) 235 return WrapperPersistent<TestInterfaceWillBeGarbageCollected>::create(internalPointer->toImpl<TestInterfaceWillBeGarbageCollected>()); 236 #else 237 ASSERT_NOT_REACHED(); 238 return 0; 239 #endif 240 } 241 242 template<> 243 v8::Handle<v8::Value> toV8NoInline(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 244 { 245 return toV8(impl, creationContext, isolate); 246 } 247 248 } // namespace blink 249