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/tests/v8/V8TestInterfaceWillBeGarbageCollected.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/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 WebCore { 24 25 static void initializeScriptWrappableForInterface(TestInterfaceWillBeGarbageCollected* object) 26 { 27 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 28 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo); 29 else 30 ASSERT_NOT_REACHED(); 31 } 32 33 } // namespace WebCore 34 35 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceWillBeGarbageCollected* object) 36 { 37 WebCore::initializeScriptWrappableForInterface(object); 38 } 39 40 namespace WebCore { 41 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollected::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject }; 42 43 namespace TestInterfaceWillBeGarbageCollectedV8Internal { 44 45 template <typename T> void V8_USE(T) { } 46 47 static void attr1AttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 48 { 49 v8::Handle<v8::Object> holder = info.Holder(); 50 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(holder); 51 v8SetReturnValueFast(info, WTF::getPtr(impl->attr1()), impl); 52 } 53 54 static void attr1AttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 55 { 56 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter"); 57 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetter(info); 58 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 59 } 60 61 static void attr1AttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 62 { 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)); 67 } 68 69 static void attr1AttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 70 { 71 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter"); 72 TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetter(v8Value, info); 73 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 74 } 75 76 static void funcMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 77 { 78 if (UNLIKELY(info.Length() < 1)) { 79 throwMinimumArityTypeErrorForMethod("func", "TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()); 80 return; 81 } 82 TestInterfaceWillBeGarbageCollected* impl = V8TestInterfaceWillBeGarbageCollected::toNative(info.Holder()); 83 TestInterfaceWillBeGarbageCollected* arg; 84 { 85 v8::TryCatch block; 86 V8RethrowTryCatchScope rethrow(block); 87 TONATIVE_VOID_INTERNAL(arg, V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(info.GetIsolate(), info[0])); 88 } 89 impl->func(arg); 90 } 91 92 static void funcMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 93 { 94 TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod"); 95 TestInterfaceWillBeGarbageCollectedV8Internal::funcMethod(info); 96 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); 97 } 98 99 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 100 { 101 v8::Isolate* isolate = info.GetIsolate(); 102 if (UNLIKELY(info.Length() < 1)) { 103 throwMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()); 104 return; 105 } 106 V8StringResource<> str; 107 { 108 TOSTRING_VOID_INTERNAL(str, info[0]); 109 } 110 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::create(str); 111 112 v8::Handle<v8::Object> wrapper = info.Holder(); 113 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollected::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 114 v8SetReturnValue(info, wrapper); 115 } 116 117 } // namespace TestInterfaceWillBeGarbageCollectedV8Internal 118 119 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceWillBeGarbageCollectedAttributes[] = { 120 {"attr1", TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceWillBeGarbageCollectedV8Internal::attr1AttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 121 }; 122 123 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceWillBeGarbageCollectedMethods[] = { 124 {"func", TestInterfaceWillBeGarbageCollectedV8Internal::funcMethodCallback, 0, 1}, 125 }; 126 127 const WrapperTypeInfo V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate, V8TestInterfaceWillBeGarbageCollected::derefObject, 0, V8TestInterfaceWillBeGarbageCollected::toEventTarget, 0, V8TestInterfaceWillBeGarbageCollected::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject }; 128 129 static void V8TestInterfaceWillBeGarbageCollectedConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 130 { 131 v8::Isolate* isolate = info.GetIsolate(); 132 if (!info.IsConstructCall()) { 133 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterface"), isolate); 134 return; 135 } 136 137 if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) { 138 v8SetReturnValue(info, info.Holder()); 139 return; 140 } 141 142 Document* documentPtr = currentDOMWindow(isolate)->document(); 143 ASSERT(documentPtr); 144 Document& document = *documentPtr; 145 146 // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceWillBeGarbageCollected instance 147 // may end up being the only node in the map and get garbage-collected prematurely. 148 toV8(documentPtr, info.Holder(), isolate); 149 150 if (UNLIKELY(info.Length() < 1)) { 151 throwMinimumArityTypeErrorForConstructor("TestInterfaceWillBeGarbageCollected", 1, info.Length(), info.GetIsolate()); 152 return; 153 } 154 V8StringResource<> str; 155 { 156 TOSTRING_VOID_INTERNAL(str, info[0]); 157 } 158 RefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl = TestInterfaceWillBeGarbageCollected::createForJSConstructor(str); 159 160 v8::Handle<v8::Object> wrapper = info.Holder(); 161 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.release(), &V8TestInterfaceWillBeGarbageCollectedConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 162 v8SetReturnValue(info, wrapper); 163 } 164 165 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollectedConstructor::domTemplate(v8::Isolate* isolate) 166 { 167 static int domTemplateKey; // This address is used for a key to look up the dom template. 168 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 169 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey); 170 if (!result.IsEmpty()) 171 return result; 172 173 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate"); 174 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceWillBeGarbageCollectedConstructorCallback); 175 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); 176 instanceTemplate->SetInternalFieldCount(V8TestInterfaceWillBeGarbageCollected::internalFieldCount); 177 result->SetClassName(v8AtomicString(isolate, "TestInterfaceWillBeGarbageCollected")); 178 result->Inherit(V8TestInterfaceWillBeGarbageCollected::domTemplate(isolate)); 179 data->setDOMTemplate(&domTemplateKey, result); 180 return result; 181 } 182 183 void V8TestInterfaceWillBeGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 184 { 185 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor"); 186 if (!info.IsConstructCall()) { 187 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceWillBeGarbageCollected"), info.GetIsolate()); 188 return; 189 } 190 191 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 192 v8SetReturnValue(info, info.Holder()); 193 return; 194 } 195 196 TestInterfaceWillBeGarbageCollectedV8Internal::constructor(info); 197 } 198 199 static void configureV8TestInterfaceWillBeGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 200 { 201 functionTemplate->ReadOnlyPrototype(); 202 203 v8::Local<v8::Signature> defaultSignature; 204 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceWillBeGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceWillBeGarbageCollected::internalFieldCount, 205 V8TestInterfaceWillBeGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedAttributes), 206 0, 0, 207 V8TestInterfaceWillBeGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceWillBeGarbageCollectedMethods), 208 isolate); 209 functionTemplate->SetCallHandler(V8TestInterfaceWillBeGarbageCollected::constructorCallback); 210 functionTemplate->SetLength(1); 211 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 212 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 213 214 // Custom toString template 215 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 216 } 217 218 v8::Handle<v8::FunctionTemplate> V8TestInterfaceWillBeGarbageCollected::domTemplate(v8::Isolate* isolate) 219 { 220 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceWillBeGarbageCollectedTemplate); 221 } 222 223 bool V8TestInterfaceWillBeGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 224 { 225 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 226 } 227 228 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 229 { 230 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 231 } 232 233 TestInterfaceWillBeGarbageCollected* V8TestInterfaceWillBeGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 234 { 235 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0; 236 } 237 238 EventTarget* V8TestInterfaceWillBeGarbageCollected::toEventTarget(v8::Handle<v8::Object> object) 239 { 240 return toNative(object); 241 } 242 243 v8::Handle<v8::Object> wrap(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 244 { 245 ASSERT(impl); 246 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, isolate)); 247 return V8TestInterfaceWillBeGarbageCollected::createWrapper(impl, creationContext, isolate); 248 } 249 250 v8::Handle<v8::Object> V8TestInterfaceWillBeGarbageCollected::createWrapper(PassRefPtrWillBeRawPtr<TestInterfaceWillBeGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 251 { 252 ASSERT(impl); 253 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceWillBeGarbageCollected>(impl.get(), isolate)); 254 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 255 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo(); 256 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have 257 // the same object de-ref functions, though, so use that as the basis of the check. 258 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction); 259 } 260 261 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate); 262 if (UNLIKELY(wrapper.IsEmpty())) 263 return wrapper; 264 265 installPerContextEnabledProperties(wrapper, impl.get(), isolate); 266 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceWillBeGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 267 return wrapper; 268 } 269 270 void V8TestInterfaceWillBeGarbageCollected::derefObject(void* object) 271 { 272 #if !ENABLE(OILPAN) 273 fromInternalPointer(object)->deref(); 274 #endif // !ENABLE(OILPAN) 275 } 276 277 template<> 278 v8::Handle<v8::Value> toV8NoInline(TestInterfaceWillBeGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 279 { 280 return toV8(impl, creationContext, isolate); 281 } 282 283 } // namespace WebCore 284