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 "V8TestInterfaceEventTarget.h"
10 #include "RuntimeEnabledFeatures.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/DOMWindow.h"
18 #include "platform/TraceEvent.h"
19 #include "wtf/GetPtr.h"
20 #include "wtf/RefPtr.h"
24 static void initializeScriptWrappableForInterface(TestInterfaceEventTarget* object)
26 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27 ScriptWrappable::fromObject(object)->setTypeInfo(&V8TestInterfaceEventTarget::wrapperTypeInfo);
32 } // namespace WebCore
34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceEventTarget* object)
36 WebCore::initializeScriptWrappableForInterface(object);
40 const WrapperTypeInfo V8TestInterfaceEventTarget::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTarget::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, &V8EventTarget::wrapperTypeInfo, WrapperTypeObjectPrototype, RefCountedObject };
42 namespace TestInterfaceEventTargetV8Internal {
44 template <typename T> void V8_USE(T) { }
46 } // namespace TestInterfaceEventTargetV8Internal
48 const WrapperTypeInfo V8TestInterfaceEventTargetConstructor::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceEventTargetConstructor::domTemplate, V8TestInterfaceEventTarget::derefObject, 0, V8TestInterfaceEventTarget::toEventTarget, 0, V8TestInterfaceEventTarget::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, RefCountedObject };
50 static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
52 v8::Isolate* isolate = info.GetIsolate();
53 if (!info.IsConstructCall()) {
54 throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Name"), isolate);
58 if (ConstructorMode::current(isolate) == ConstructorMode::WrapExistingObject) {
59 v8SetReturnValue(info, info.Holder());
63 Document* document = currentDOMWindow(isolate)->document();
66 // Make sure the document is added to the DOM Node map. Otherwise, the TestInterfaceEventTarget instance
67 // may end up being the only node in the map and get garbage-collected prematurely.
68 toV8(document, info.Holder(), isolate);
70 RefPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(*document);
72 v8::Handle<v8::Object> wrapper = info.Holder();
73 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl.release(), &V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
74 v8SetReturnValue(info, wrapper);
77 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTargetConstructor::domTemplate(v8::Isolate* isolate)
79 static int domTemplateKey; // This address is used for a key to look up the dom template.
80 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
81 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(&domTemplateKey);
82 if (!result.IsEmpty())
85 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
86 result = v8::FunctionTemplate::New(isolate, V8TestInterfaceEventTargetConstructorCallback);
87 v8::Local<v8::ObjectTemplate> instanceTemplate = result->InstanceTemplate();
88 instanceTemplate->SetInternalFieldCount(V8TestInterfaceEventTarget::internalFieldCount);
89 result->SetClassName(v8AtomicString(isolate, "TestInterfaceEventTarget"));
90 result->Inherit(V8TestInterfaceEventTarget::domTemplate(isolate));
91 data->setDOMTemplate(&domTemplateKey, result);
95 static void configureV8TestInterfaceEventTargetTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
97 functionTemplate->ReadOnlyPrototype();
99 v8::Local<v8::Signature> defaultSignature;
100 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceEventTarget", V8EventTarget::domTemplate(isolate), V8TestInterfaceEventTarget::internalFieldCount,
105 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate();
106 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate();
108 // Custom toString template
109 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
112 v8::Handle<v8::FunctionTemplate> V8TestInterfaceEventTarget::domTemplate(v8::Isolate* isolate)
114 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
115 v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
116 if (!result.IsEmpty())
119 TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
120 result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
121 configureV8TestInterfaceEventTargetTemplate(result, isolate);
122 data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
126 bool V8TestInterfaceEventTarget::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
128 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
131 v8::Handle<v8::Object> V8TestInterfaceEventTarget::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
133 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
136 TestInterfaceEventTarget* V8TestInterfaceEventTarget::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
138 return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
141 EventTarget* V8TestInterfaceEventTarget::toEventTarget(v8::Handle<v8::Object> object)
143 return toNative(object);
146 v8::Handle<v8::Object> V8TestInterfaceEventTarget::createWrapper(PassRefPtr<TestInterfaceEventTarget> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
149 ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceEventTarget>(impl.get(), isolate));
150 if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
151 const WrapperTypeInfo* actualInfo = ScriptWrappable::fromObject(impl.get())->typeInfo();
152 // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
153 // the same object de-ref functions, though, so use that as the basis of the check.
154 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
157 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
158 if (UNLIKELY(wrapper.IsEmpty()))
161 installPerContextEnabledProperties(wrapper, impl.get(), isolate);
162 V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceEventTarget>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
166 void V8TestInterfaceEventTarget::derefObject(void* object)
168 fromInternalPointer(object)->deref();
172 v8::Handle<v8::Value> toV8NoInline(TestInterfaceEventTarget* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
174 return toV8(impl, creationContext, isolate);
177 } // namespace WebCore