Home | History | Annotate | Download | only in templates
      1 /*
      2     This file is part of the Blink open source project.
      3     This file has been auto-generated by CodeGeneratorV8.pm. DO NOT MODIFY!
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Library General Public
      7     License as published by the Free Software Foundation; either
      8     version 2 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Library General Public License for more details.
     14 
     15     You should have received a copy of the GNU Library General Public License
     16     along with this library; see the file COPYING.LIB.  If not, write to
     17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     18     Boston, MA 02111-1307, USA.
     19 */
     20 
     21 #include "config.h"
     22 {% if conditional_string %}
     23 #if {{conditional_string}}
     24 {% endif %}
     25 #include "{{v8_class_name}}.h"
     26 
     27 {% for filename in cpp_includes %}
     28 #include "{{ filename }}"
     29 {% endfor %}
     30 
     31 namespace WebCore {
     32 
     33 static void initializeScriptWrappableForInterface({{cpp_class_name}}* object)
     34 {
     35     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
     36         ScriptWrappable::setTypeInfoInObject(object, &{{v8_class_name}}::info);
     37     else
     38         ASSERT_NOT_REACHED();
     39 }
     40 
     41 } // namespace WebCore
     42 
     43 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
     44 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
     45 // in the global namespace.
     46 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
     47 void webCoreInitializeScriptWrappableForInterface(WebCore::{{cpp_class_name}}* object)
     48 {
     49     WebCore::initializeScriptWrappableForInterface(object);
     50 }
     51 
     52 namespace WebCore {
     53 WrapperTypeInfo {{v8_class_name}}::info = { {{v8_class_name}}::GetTemplate, {{v8_class_name}}::derefObject, 0, 0, 0, {{v8_class_name}}::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
     54 
     55 namespace {{cpp_class_name}}V8Internal {
     56 
     57 template <typename T> void V8_USE(T) { }
     58 
     59 {% for attribute in attributes %}
     60 static void {{attribute.name}}AttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     61 {
     62     {{cpp_class_name}}* imp = {{v8_class_name}}::toNative(info.Holder());
     63     {{attribute.cpp_type}} result = imp->{{attribute.cpp_method_name}}();
     64     v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper<{{attribute.v8_type}}>(result.get(), info.GetIsolate())) : v8Undefined();
     65     if (wrapper.IsEmpty()) {
     66         wrapper = toV8(result.get(), info.Holder(), info.GetIsolate());
     67         if (!wrapper.IsEmpty())
     68             V8HiddenPropertyName::setNamedHiddenReference(info.Holder(), "{{attribute.name}}", wrapper);
     69     }
     70     v8SetReturnValue(info, wrapper);
     71 }
     72 
     73 static void {{attribute.name}}AttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     74 {
     75     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
     76     {{cpp_class_name}}V8Internal::{{attribute.name}}AttrGetter(name, info);
     77     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
     78 }
     79 
     80 {% endfor %}
     81 
     82 } // namespace {{cpp_class_name}}V8Internal
     83 
     84 {% if attributes %}
     85 static const V8DOMConfiguration::BatchedAttribute {{v8_class_name}}Attributes[] = {
     86 {% for attribute in attributes %}
     87     {"{{attribute.name}}", {{cpp_class_name}}V8Internal::{{attribute.name}}AttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
     88 {% endfor %}
     89 };
     90 
     91 {% endif %}
     92 
     93 
     94 static v8::Handle<v8::FunctionTemplate> Configure{{v8_class_name}}Template(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType)
     95 {
     96     desc->ReadOnlyPrototype();
     97 
     98     v8::Local<v8::Signature> defaultSignature;
     99     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "{{interface_name}}", v8::Local<v8::FunctionTemplate>(), {{v8_class_name}}::internalFieldCount,
    100         {{attribute_templates}}, {{number_of_attributes}},
    101         0, 0, isolate, currentWorldType);
    102     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
    103 
    104     // Custom toString template
    105     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
    106     return desc;
    107 }
    108 
    109 v8::Handle<v8::FunctionTemplate> {{v8_class_name}}::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
    110 {
    111     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    112     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info);
    113     if (result != data->templateMap(currentWorldType).end())
    114         return result->value.newLocal(isolate);
    115 
    116     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
    117     v8::HandleScope handleScope(isolate);
    118     v8::Handle<v8::FunctionTemplate> templ =
    119         Configure{{v8_class_name}}Template(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType);
    120     data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
    121     return handleScope.Close(templ);
    122 }
    123 
    124 bool {{v8_class_name}}::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    125 {
    126     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType);
    127 }
    128 
    129 bool {{v8_class_name}}::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate)
    130 {
    131     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
    132         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld)
    133         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld);
    134 }
    135 
    136 v8::Handle<v8::Object> {{v8_class_name}}::createWrapper(PassRefPtr<{{cpp_class_name}}> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    137 {
    138     ASSERT(impl.get());
    139     ASSERT(DOMDataStore::getWrapper<{{v8_class_name}}>(impl.get(), isolate).IsEmpty());
    140     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
    141         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
    142         // Might be a XXXConstructor::info instead of an XXX::info. These will both have
    143         // the same object de-ref functions, though, so use that as the basis of the check.
    144         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction);
    145     }
    146 
    147     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate);
    148     if (UNLIKELY(wrapper.IsEmpty()))
    149         return wrapper;
    150 
    151     installPerContextProperties(wrapper, impl.get(), isolate);
    152     V8DOMWrapper::associateObjectWithWrapper<{{v8_class_name}}>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent);
    153     return wrapper;
    154 }
    155 
    156 void {{v8_class_name}}::derefObject(void* object)
    157 {
    158     fromInternalPointer(object)->deref();
    159 }
    160 
    161 } // namespace WebCore
    162 
    163 {% if conditional_string %}
    164 #endif // {{conditional_string}}
    165 {% endif %}
    166 
    167