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