Home | History | Annotate | Download | only in results
      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 #include "V8TestEventConstructor.h"
     23 
     24 #include "RuntimeEnabledFeatures.h"
     25 #include "bindings/v8/Dictionary.h"
     26 #include "bindings/v8/ScriptController.h"
     27 #include "bindings/v8/V8Binding.h"
     28 #include "bindings/v8/V8DOMConfiguration.h"
     29 #include "bindings/v8/V8DOMWrapper.h"
     30 #include "bindings/v8/V8ObjectConstructor.h"
     31 #include "core/dom/ContextFeatures.h"
     32 #include "core/dom/Document.h"
     33 #include "core/page/Frame.h"
     34 #include "core/platform/chromium/TraceEvent.h"
     35 #include "wtf/UnusedParam.h"
     36 
     37 namespace WebCore {
     38 
     39 static void initializeScriptWrappableForInterface(TestEventConstructor* object)
     40 {
     41     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
     42         ScriptWrappable::setTypeInfoInObject(object, &V8TestEventConstructor::info);
     43     else
     44         ASSERT_NOT_REACHED();
     45 }
     46 
     47 } // namespace WebCore
     48 
     49 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
     50 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
     51 // in the global namespace.
     52 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
     53 void webCoreInitializeScriptWrappableForInterface(WebCore::TestEventConstructor* object)
     54 {
     55     WebCore::initializeScriptWrappableForInterface(object);
     56 }
     57 
     58 namespace WebCore {
     59 WrapperTypeInfo V8TestEventConstructor::info = { V8TestEventConstructor::GetTemplate, V8TestEventConstructor::derefObject, 0, 0, 0, V8TestEventConstructor::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
     60 
     61 namespace TestEventConstructorV8Internal {
     62 
     63 template <typename T> void V8_USE(T) { }
     64 
     65 static void attr1AttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     66 {
     67     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
     68     v8SetReturnValueString(info, imp->attr1(), info.GetIsolate());
     69     return;
     70 }
     71 
     72 static void attr1AttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     73 {
     74     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
     75     TestEventConstructorV8Internal::attr1AttrGetter(name, info);
     76     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
     77 }
     78 
     79 static void attr2AttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     80 {
     81     TestEventConstructor* imp = V8TestEventConstructor::toNative(info.Holder());
     82     v8SetReturnValueString(info, imp->attr2(), info.GetIsolate());
     83     return;
     84 }
     85 
     86 static void attr2AttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     87 {
     88     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
     89     TestEventConstructorV8Internal::attr2AttrGetter(name, info);
     90     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
     91 }
     92 
     93 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& args)
     94 {
     95     if (args.Length() < 1) {
     96         throwNotEnoughArgumentsError(args.GetIsolate());
     97         return;
     98     }
     99 
    100     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]);
    101     TestEventConstructorInit eventInit;
    102     if (args.Length() >= 2) {
    103         V8TRYCATCH_VOID(Dictionary, options, Dictionary(args[1], args.GetIsolate()));
    104         if (!fillTestEventConstructorInit(eventInit, options))
    105             return;
    106     }
    107 
    108     RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, eventInit);
    109     v8::Handle<v8::Object> wrapper = args.Holder();
    110     V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(event.release(), &V8TestEventConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    111     v8SetReturnValue(args, wrapper);
    112 }
    113 } // namespace TestEventConstructorV8Internal
    114 
    115 static const V8DOMConfiguration::BatchedAttribute V8TestEventConstructorAttrs[] = {
    116     // Attribute 'attr1'
    117     {"attr1", TestEventConstructorV8Internal::attr1AttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
    118     // Attribute 'attr2'
    119     {"attr2", TestEventConstructorV8Internal::attr2AttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
    120 };
    121 
    122 bool fillTestEventConstructorInit(TestEventConstructorInit& eventInit, const Dictionary& options)
    123 {
    124     options.get("attr2", eventInit.attr2);
    125     return true;
    126 }
    127 
    128 void V8TestEventConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
    129 {
    130     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
    131     if (!args.IsConstructCall()) {
    132         throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
    133         return;
    134     }
    135 
    136     if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
    137         args.GetReturnValue().Set(args.Holder());
    138         return;
    139     }
    140 
    141     TestEventConstructorV8Internal::constructor(args);
    142 }
    143 
    144 static v8::Handle<v8::FunctionTemplate> ConfigureV8TestEventConstructorTemplate(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    145 {
    146     desc->ReadOnlyPrototype();
    147 
    148     v8::Local<v8::Signature> defaultSignature;
    149     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestEventConstructor", v8::Local<v8::FunctionTemplate>(), V8TestEventConstructor::internalFieldCount,
    150         V8TestEventConstructorAttrs, WTF_ARRAY_LENGTH(V8TestEventConstructorAttrs),
    151         0, 0, isolate, currentWorldType);
    152     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
    153     desc->SetCallHandler(V8TestEventConstructor::constructorCallback);
    154     desc->SetLength(1);
    155 
    156     // Custom toString template
    157     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
    158     return desc;
    159 }
    160 
    161 v8::Handle<v8::FunctionTemplate> V8TestEventConstructor::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
    162 {
    163     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    164     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info);
    165     if (result != data->templateMap(currentWorldType).end())
    166         return result->value.newLocal(isolate);
    167 
    168     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
    169     v8::HandleScope handleScope(isolate);
    170     v8::Handle<v8::FunctionTemplate> templ =
    171         ConfigureV8TestEventConstructorTemplate(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType);
    172     data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
    173     return handleScope.Close(templ);
    174 }
    175 
    176 bool V8TestEventConstructor::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    177 {
    178     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType);
    179 }
    180 
    181 bool V8TestEventConstructor::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate)
    182 {
    183     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
    184         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld)
    185         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld);
    186 }
    187 
    188 
    189 v8::Handle<v8::Object> V8TestEventConstructor::createWrapper(PassRefPtr<TestEventConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    190 {
    191     ASSERT(impl.get());
    192     ASSERT(DOMDataStore::getWrapper<V8TestEventConstructor>(impl.get(), isolate).IsEmpty());
    193     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
    194         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
    195         // Might be a XXXConstructor::info instead of an XXX::info. These will both have
    196         // the same object de-ref functions, though, so use that as the basis of the check.
    197         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction);
    198     }
    199 
    200 
    201     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate);
    202     if (UNLIKELY(wrapper.IsEmpty()))
    203         return wrapper;
    204     installPerContextProperties(wrapper, impl.get(), isolate);
    205     V8DOMWrapper::associateObjectWithWrapper<V8TestEventConstructor>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent);
    206     return wrapper;
    207 }
    208 void V8TestEventConstructor::derefObject(void* object)
    209 {
    210     fromInternalPointer(object)->deref();
    211 }
    212 
    213 } // namespace WebCore
    214