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 "V8TestInterfaceEventTarget.h" 9 10 #include "bindings/v8/ExceptionState.h" 11 #include "bindings/v8/V8DOMConfiguration.h" 12 #include "bindings/v8/V8HiddenValue.h" 13 #include "bindings/v8/V8ObjectConstructor.h" 14 #include "core/dom/ContextFeatures.h" 15 #include "core/dom/Document.h" 16 #include "core/frame/LocalDOMWindow.h" 17 #include "platform/RuntimeEnabledFeatures.h" 18 #include "platform/TraceEvent.h" 19 #include "wtf/GetPtr.h" 20 #include "wtf/RefPtr.h" 21 22 namespace WebCore { 23 24 static void initializeScriptWrappableForInterface(TestInterfaceEventTarget* object) 25 { 26 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 27 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceEventTarget::wrapperTypeInfo); 28 else 29 ASSERT_NOT_REACHED(); 30 } 31 32 } // namespace WebCore 33 34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceEventTarget* object) 35 { 36 WebCore::initializeScriptWrappableForInterface(object); 37 } 38 39 namespace WebCore { 40 const WrapperTypeInfo V8TestInterfaceEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTarget::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject }; 41 42 namespace TestInterfaceEventTargetV8Internal { 43 44 template <typename T> void V8_USE(T) { } 45 46 } // namespace TestInterfaceEventTargetV8Internal 47 48 const WrapperTypeInfo V8TestInterfaceEventTargetConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTargetConstructor::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, WillBeGarbageCollectedObject }; 49 50 static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 51 { 52 v8::Isolate* isolate = info.GetIsolate(); 53 if (!info.IsConstructCall()) { 54 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Name"), isolate); 55 return; 56 } 57 58 if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) { 59 v8SetReturnValue(info, info.Holder()); 60 return; 61 } 62 63 Document* documentPtr = currentDOMWindow(isolate)->document(); 64 ASSERT(documentPtr); 65 Document& document = *documentPtr; 66 67 // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceEventTarget instance 68 // may end up being the only node in the map and get garbage-collected prematurely. 69 toV8(documentPtr, info.Holder(), isolate); 70 71 RefPtrWillBeRawPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(document); 72 73 v8::Handle<v8::Object> wrapper = info.Holder(); 74 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl.release(), &V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 75 v8SetReturnValue(info, wrapper); 76 } 77 78 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTargetConstructor::domTemplate(v8::Isolate* isolate) 79 { 80 static int domTemplateKey; // This address is used for a key to look up the dom template. 81 V8PerIsolateData* data = V8PerIsolateData::from(isolate); 82 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey); 83 if (!result.IsEmpty()) 84 return result; 85 86 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate"); 87 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceEventTargetConstructorCallback); 88 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate(); 89 instanceTemplate->SetInternalFieldCount(V8TestInterfaceEventTarget::internalFieldCount); 90 result->SetClassName(v8AtomicString(isolate, "TestInterfaceEventTarget")); 91 result->Inherit(V8TestInterfaceEventTarget::domTemplate(isolate)); 92 data->setDOMTemplate(&domTemplateKey, result); 93 return result; 94 } 95 96 static void configureV8TestInterfaceEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 97 { 98 functionTemplate->ReadOnlyPrototype(); 99 100 v8::Local<v8::Signature> defaultSignature; 101 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceEventTarget", V8EventTarget::domTemplate(isolate), V8TestInterfaceEventTarget::internalFieldCount, 102 0, 0, 103 0, 0, 104 0, 0, 105 isolate); 106 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 107 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 108 109 // Custom toString template 110 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 111 } 112 113 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTarget::domTemplate(v8::Isolate* isolate) 114 { 115 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), configureV8TestInterfaceEventTargetTemplate); 116 } 117 118 bool V8TestInterfaceEventTarget::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 119 { 120 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 121 } 122 123 v8::Handle<v8::Object> V8TestInterfaceEventTarget::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 124 { 125 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 126 } 127 128 TestInterfaceEventTarget* V8TestInterfaceEventTarget::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 129 { 130 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0; 131 } 132 133 EventTarget* V8TestInterfaceEventTarget::toEventTarget(v8::Handle<v8::Object> object) 134 { 135 return toNative(object); 136 } 137 138 v8::Handle<v8::Object> wrap(TestInterfaceEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 139 { 140 ASSERT(impl); 141 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceEventTarget>(impl, isolate)); 142 return V8TestInterfaceEventTarget::createWrapper(impl, creationContext, isolate); 143 } 144 145 v8::Handle<v8::Object> V8TestInterfaceEventTarget::createWrapper(PassRefPtrWillBeRawPtr<TestInterfaceEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 146 { 147 ASSERT(impl); 148 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceEventTarget>(impl.get(), isolate)); 149 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) { 150 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo(); 151 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have 152 // the same object de-ref functions, though, so use that as the basis of the check. 153 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction); 154 } 155 156 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate); 157 if (UNLIKELY(wrapper.IsEmpty())) 158 return wrapper; 159 160 installPerContextEnabledProperties(wrapper, impl.get(), isolate); 161 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent); 162 return wrapper; 163 } 164 165 void V8TestInterfaceEventTarget::derefObject(void* object) 166 { 167 #if !ENABLE(OILPAN) 168 fromInternalPointer(object)->deref(); 169 #endif // !ENABLE(OILPAN) 170 } 171 172 template<> 173 v8::Handle<v8::Value> toV8NoInline(TestInterfaceEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 174 { 175 return toV8(impl, creationContext, isolate); 176 } 177 178 } // namespace WebCore 179