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 "V8TestInterfaceGarbageCollected.h" 9 10 #include "bindings/tests/v8/V8TestInterfaceGarbageCollected.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(TestInterfaceGarbageCollected* object) 26 { 27 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 28 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceGarbageCollected::wrapperTypeInfo); 29 else 30 ASSERT_NOT_REACHED(); 31 } 32 33 } // namespace WebCore 34 35 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceGarbageCollected* object) 36 { 37 WebCore::initializeScriptWrappableForInterface(object); 38 } 39 40 namespace WebCore { 41 const WrapperTypeInfo V8TestInterfaceGarbageCollected::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceGarbageCollected::domTemplate, V8TestInterfaceGarbageCollected::derefObject, 0, V8TestInterfaceGarbageCollected::toEventTarget, 0, V8TestInterfaceGarbageCollected::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, GarbageCollectedObject }; 42 43 namespace TestInterfaceGarbageCollectedV8Internal { 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 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::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 TestInterfaceGarbageCollectedV8Internal::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 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(holder); 65 TONATIVE_VOID(TestInterfaceGarbageCollected*, cppValue, V8TestInterfaceGarbageCollected::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 TestInterfaceGarbageCollectedV8Internal::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", "TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate()); 80 return; 81 } 82 TestInterfaceGarbageCollected* impl = V8TestInterfaceGarbageCollected::toNative(info.Holder()); 83 TestInterfaceGarbageCollected* arg; 84 { 85 v8::TryCatch block; 86 V8RethrowTryCatchScope rethrow(block); 87 TONATIVE_VOID_INTERNAL(arg, V8TestInterfaceGarbageCollected::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 TestInterfaceGarbageCollectedV8Internal::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("TestInterfaceGarbageCollected", 1, info.Length(), info.GetIsolate()); 104 return; 105 } 106 V8StringResource<> str; 107 { 108 TOSTRING_VOID_INTERNAL(str, info[0]); 109 } 110 RawPtr<TestInterfaceGarbageCollected> impl = TestInterfaceGarbageCollected::create(str); 111 112 v8::Handle<v8::Object> wrapper = info.Holder(); 113 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl.release(), &V8TestInterfaceGarbageCollected::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 114 v8SetReturnValue(info, wrapper); 115 } 116 117 } // namespace TestInterfaceGarbageCollectedV8Internal 118 119 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceGarbageCollectedAttributes[] = { 120 {"attr1", TestInterfaceGarbageCollectedV8Internal::attr1AttributeGetterCallback, TestInterfaceGarbageCollectedV8Internal::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 V8TestInterfaceGarbageCollectedMethods[] = { 124 {"func", TestInterfaceGarbageCollectedV8Internal::funcMethodCallback, 0, 1}, 125 }; 126 127 void V8TestInterfaceGarbageCollected::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 128 { 129 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor"); 130 if (!info.IsConstructCall()) { 131 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceGarbageCollected"), info.GetIsolate()); 132 return; 133 } 134 135 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 136 v8SetReturnValue(info, info.Holder()); 137 return; 138 } 139 140 TestInterfaceGarbageCollectedV8Internal::constructor(info); 141 } 142 143 static void configureV8TestInterfaceGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 144 { 145 functionTemplate->ReadOnlyPrototype(); 146 147 v8::Local<v8::Signature> defaultSignature; 148 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceGarbageCollected::internalFieldCount, 149 V8TestInterfaceGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedAttributes), 150 0, 0, 151 V8TestInterfaceGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedMethods), 152 isolate); 153 functionTemplate->SetCallHandler(V8TestInterfaceGarbageCollected::constructorCallback); 154 functionTemplate->SetLength(1); 155 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 156 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 157 158 // Custom toString template 159 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 160 } 161 162 v8::Handle<v8::FunctionTemplate> V8TestInterfaceGarbageCollected::domTemplate(v8::Isolate* isolate) 163 { 164 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceGarbageCollectedTemplate); 165 } 166 167 bool V8TestInterfaceGarbageCollected::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 168 { 169 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 170 } 171 172 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 173 { 174 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 175 } 176 177 TestInterfaceGarbageCollected* V8TestInterfaceGarbageCollected::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 178 { 179 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0; 180 } 181 182 EventTarget* V8TestInterfaceGarbageCollected::toEventTarget(v8::Handle<v8::Object> object) 183 { 184 return toNative(object); 185 } 186 187 v8::Handle<v8::Object> wrap(TestInterfaceGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 188 { 189 ASSERT(impl); 190 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceGarbageCollected>(impl, isolate)); 191 return V8TestInterfaceGarbageCollected::createWrapper(impl, creationContext, isolate); 192 } 193 194 v8::Handle<v8::Object> V8TestInterfaceGarbageCollected::createWrapper(RawPtr<TestInterfaceGarbageCollected> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 195 { 196 ASSERT(impl); 197 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceGarbageCollected>(impl.get(), isolate)); 198 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 199 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo(); 200 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have 201 // the same object de-ref functions, though, so use that as the basis of the check. 202 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction); 203 } 204 205 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate); 206 if (UNLIKELY(wrapper.IsEmpty())) 207 return wrapper; 208 209 installPerContextEnabledProperties(wrapper, impl.get(), isolate); 210 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceGarbageCollected>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 211 return wrapper; 212 } 213 214 void V8TestInterfaceGarbageCollected::derefObject(void* object) 215 { 216 } 217 218 template<> 219 v8::Handle<v8::Value> toV8NoInline(TestInterfaceGarbageCollected* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 220 { 221 return toV8(impl, creationContext, isolate); 222 } 223 224 } // namespace WebCore 225