WebCore/generated/JSEventSource.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2     This file is part of the WebKit open source project.
       
     3     This file has been generated by generate-bindings.pl. 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., 51 Franklin Street, Fifth Floor,
       
    18     Boston, MA 02110-1301, USA.
       
    19 */
       
    20 
       
    21 #include "config.h"
       
    22 
       
    23 #if ENABLE(EVENTSOURCE)
       
    24 
       
    25 #include "JSEventSource.h"
       
    26 
       
    27 #include "Event.h"
       
    28 #include "EventListener.h"
       
    29 #include "EventSource.h"
       
    30 #include "JSEvent.h"
       
    31 #include "JSEventListener.h"
       
    32 #include "KURL.h"
       
    33 #include "RegisteredEventListener.h"
       
    34 #include <runtime/Error.h>
       
    35 #include <runtime/JSNumberCell.h>
       
    36 #include <runtime/JSString.h>
       
    37 #include <wtf/GetPtr.h>
       
    38 
       
    39 using namespace JSC;
       
    40 
       
    41 namespace WebCore {
       
    42 
       
    43 ASSERT_CLASS_FITS_IN_CELL(JSEventSource);
       
    44 
       
    45 /* Hash table */
       
    46 #if ENABLE(JIT)
       
    47 #define THUNK_GENERATOR(generator) , generator
       
    48 #else
       
    49 #define THUNK_GENERATOR(generator)
       
    50 #endif
       
    51 
       
    52 static const HashTableValue JSEventSourceTableValues[7] =
       
    53 {
       
    54     { "URL", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceURL), (intptr_t)0 THUNK_GENERATOR(0) },
       
    55     { "readyState", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceReadyState), (intptr_t)0 THUNK_GENERATOR(0) },
       
    56     { "onopen", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnopen), (intptr_t)setJSEventSourceOnopen THUNK_GENERATOR(0) },
       
    57     { "onmessage", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnmessage), (intptr_t)setJSEventSourceOnmessage THUNK_GENERATOR(0) },
       
    58     { "onerror", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOnerror), (intptr_t)setJSEventSourceOnerror THUNK_GENERATOR(0) },
       
    59     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
       
    60     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    61 };
       
    62 
       
    63 #undef THUNK_GENERATOR
       
    64 static JSC_CONST_HASHTABLE HashTable JSEventSourceTable = { 17, 15, JSEventSourceTableValues, 0 };
       
    65 /* Hash table for constructor */
       
    66 #if ENABLE(JIT)
       
    67 #define THUNK_GENERATOR(generator) , generator
       
    68 #else
       
    69 #define THUNK_GENERATOR(generator)
       
    70 #endif
       
    71 
       
    72 static const HashTableValue JSEventSourceConstructorTableValues[4] =
       
    73 {
       
    74     { "CONNECTING", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceCONNECTING), (intptr_t)0 THUNK_GENERATOR(0) },
       
    75     { "OPEN", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOPEN), (intptr_t)0 THUNK_GENERATOR(0) },
       
    76     { "CLOSED", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceCLOSED), (intptr_t)0 THUNK_GENERATOR(0) },
       
    77     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    78 };
       
    79 
       
    80 #undef THUNK_GENERATOR
       
    81 static JSC_CONST_HASHTABLE HashTable JSEventSourceConstructorTable = { 8, 7, JSEventSourceConstructorTableValues, 0 };
       
    82 
       
    83 COMPILE_ASSERT(0 == EventSource::CONNECTING, EventSourceEnumCONNECTINGIsWrongUseDontCheckEnums);
       
    84 COMPILE_ASSERT(1 == EventSource::OPEN, EventSourceEnumOPENIsWrongUseDontCheckEnums);
       
    85 COMPILE_ASSERT(2 == EventSource::CLOSED, EventSourceEnumCLOSEDIsWrongUseDontCheckEnums);
       
    86 
       
    87 const ClassInfo JSEventSourceConstructor::s_info = { "EventSourceConstructor", 0, &JSEventSourceConstructorTable, 0 };
       
    88 
       
    89 JSEventSourceConstructor::JSEventSourceConstructor(ExecState* exec, JSDOMGlobalObject* globalObject)
       
    90     : DOMConstructorObject(JSEventSourceConstructor::createStructure(globalObject->objectPrototype()), globalObject)
       
    91 {
       
    92     putDirect(exec->propertyNames().prototype, JSEventSourcePrototype::self(exec, globalObject), DontDelete | ReadOnly);
       
    93     putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);
       
    94 }
       
    95 
       
    96 bool JSEventSourceConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
    97 {
       
    98     return getStaticValueSlot<JSEventSourceConstructor, DOMObject>(exec, &JSEventSourceConstructorTable, this, propertyName, slot);
       
    99 }
       
   100 
       
   101 bool JSEventSourceConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   102 {
       
   103     return getStaticValueDescriptor<JSEventSourceConstructor, DOMObject>(exec, &JSEventSourceConstructorTable, this, propertyName, descriptor);
       
   104 }
       
   105 
       
   106 ConstructType JSEventSourceConstructor::getConstructData(ConstructData& constructData)
       
   107 {
       
   108     constructData.native.function = constructJSEventSource;
       
   109     return ConstructTypeHost;
       
   110 }
       
   111 
       
   112 /* Hash table for prototype */
       
   113 #if ENABLE(JIT)
       
   114 #define THUNK_GENERATOR(generator) , generator
       
   115 #else
       
   116 #define THUNK_GENERATOR(generator)
       
   117 #endif
       
   118 
       
   119 static const HashTableValue JSEventSourcePrototypeTableValues[8] =
       
   120 {
       
   121     { "CONNECTING", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceCONNECTING), (intptr_t)0 THUNK_GENERATOR(0) },
       
   122     { "OPEN", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceOPEN), (intptr_t)0 THUNK_GENERATOR(0) },
       
   123     { "CLOSED", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsEventSourceCLOSED), (intptr_t)0 THUNK_GENERATOR(0) },
       
   124     { "close", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsEventSourcePrototypeFunctionClose), (intptr_t)0 THUNK_GENERATOR(0) },
       
   125     { "addEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsEventSourcePrototypeFunctionAddEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
       
   126     { "removeEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsEventSourcePrototypeFunctionRemoveEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
       
   127     { "dispatchEvent", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsEventSourcePrototypeFunctionDispatchEvent), (intptr_t)1 THUNK_GENERATOR(0) },
       
   128     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
   129 };
       
   130 
       
   131 #undef THUNK_GENERATOR
       
   132 static JSC_CONST_HASHTABLE HashTable JSEventSourcePrototypeTable = { 17, 15, JSEventSourcePrototypeTableValues, 0 };
       
   133 static const HashTable* getJSEventSourcePrototypeTable(ExecState* exec)
       
   134 {
       
   135     return getHashTableForGlobalData(exec->globalData(), &JSEventSourcePrototypeTable);
       
   136 }
       
   137 const ClassInfo JSEventSourcePrototype::s_info = { "EventSourcePrototype", 0, 0, getJSEventSourcePrototypeTable };
       
   138 
       
   139 JSObject* JSEventSourcePrototype::self(ExecState* exec, JSGlobalObject* globalObject)
       
   140 {
       
   141     return getDOMPrototype<JSEventSource>(exec, globalObject);
       
   142 }
       
   143 
       
   144 bool JSEventSourcePrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   145 {
       
   146     return getStaticPropertySlot<JSEventSourcePrototype, JSObject>(exec, getJSEventSourcePrototypeTable(exec), this, propertyName, slot);
       
   147 }
       
   148 
       
   149 bool JSEventSourcePrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   150 {
       
   151     return getStaticPropertyDescriptor<JSEventSourcePrototype, JSObject>(exec, getJSEventSourcePrototypeTable(exec), this, propertyName, descriptor);
       
   152 }
       
   153 
       
   154 static const HashTable* getJSEventSourceTable(ExecState* exec)
       
   155 {
       
   156     return getHashTableForGlobalData(exec->globalData(), &JSEventSourceTable);
       
   157 }
       
   158 const ClassInfo JSEventSource::s_info = { "EventSource", 0, 0, getJSEventSourceTable };
       
   159 
       
   160 JSEventSource::JSEventSource(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject* globalObject, PassRefPtr<EventSource> impl)
       
   161     : DOMObjectWithGlobalPointer(structure, globalObject)
       
   162     , m_impl(impl)
       
   163 {
       
   164 }
       
   165 
       
   166 JSEventSource::~JSEventSource()
       
   167 {
       
   168     impl()->invalidateJSEventListeners(this);
       
   169     forgetDOMObject(this, impl());
       
   170 }
       
   171 
       
   172 void JSEventSource::markChildren(MarkStack& markStack)
       
   173 {
       
   174     Base::markChildren(markStack);
       
   175     impl()->markJSEventListeners(markStack);
       
   176 }
       
   177 
       
   178 JSObject* JSEventSource::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
       
   179 {
       
   180     return new (exec) JSEventSourcePrototype(globalObject, JSEventSourcePrototype::createStructure(globalObject->objectPrototype()));
       
   181 }
       
   182 
       
   183 bool JSEventSource::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   184 {
       
   185     return getStaticValueSlot<JSEventSource, Base>(exec, getJSEventSourceTable(exec), this, propertyName, slot);
       
   186 }
       
   187 
       
   188 bool JSEventSource::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   189 {
       
   190     return getStaticValueDescriptor<JSEventSource, Base>(exec, getJSEventSourceTable(exec), this, propertyName, descriptor);
       
   191 }
       
   192 
       
   193 JSValue jsEventSourceURL(ExecState* exec, JSValue slotBase, const Identifier&)
       
   194 {
       
   195     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slotBase));
       
   196     UNUSED_PARAM(exec);
       
   197     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   198     JSValue result = jsString(exec, imp->url());
       
   199     return result;
       
   200 }
       
   201 
       
   202 JSValue jsEventSourceReadyState(ExecState* exec, JSValue slotBase, const Identifier&)
       
   203 {
       
   204     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slotBase));
       
   205     UNUSED_PARAM(exec);
       
   206     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   207     JSValue result = jsNumber(exec, imp->readyState());
       
   208     return result;
       
   209 }
       
   210 
       
   211 JSValue jsEventSourceOnopen(ExecState* exec, JSValue slotBase, const Identifier&)
       
   212 {
       
   213     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slotBase));
       
   214     UNUSED_PARAM(exec);
       
   215     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   216     if (EventListener* listener = imp->onopen()) {
       
   217         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
       
   218             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
       
   219                 return jsFunction;
       
   220         }
       
   221     }
       
   222     return jsNull();
       
   223 }
       
   224 
       
   225 JSValue jsEventSourceOnmessage(ExecState* exec, JSValue slotBase, const Identifier&)
       
   226 {
       
   227     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slotBase));
       
   228     UNUSED_PARAM(exec);
       
   229     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   230     if (EventListener* listener = imp->onmessage()) {
       
   231         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
       
   232             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
       
   233                 return jsFunction;
       
   234         }
       
   235     }
       
   236     return jsNull();
       
   237 }
       
   238 
       
   239 JSValue jsEventSourceOnerror(ExecState* exec, JSValue slotBase, const Identifier&)
       
   240 {
       
   241     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(slotBase));
       
   242     UNUSED_PARAM(exec);
       
   243     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   244     if (EventListener* listener = imp->onerror()) {
       
   245         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
       
   246             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
       
   247                 return jsFunction;
       
   248         }
       
   249     }
       
   250     return jsNull();
       
   251 }
       
   252 
       
   253 JSValue jsEventSourceConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
       
   254 {
       
   255     JSEventSource* domObject = static_cast<JSEventSource*>(asObject(slotBase));
       
   256     return JSEventSource::getConstructor(exec, domObject->globalObject());
       
   257 }
       
   258 void JSEventSource::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
       
   259 {
       
   260     lookupPut<JSEventSource, Base>(exec, propertyName, value, getJSEventSourceTable(exec), this, slot);
       
   261 }
       
   262 
       
   263 void setJSEventSourceOnopen(ExecState* exec, JSObject* thisObject, JSValue value)
       
   264 {
       
   265     UNUSED_PARAM(exec);
       
   266     EventSource* imp = static_cast<EventSource*>(static_cast<JSEventSource*>(thisObject)->impl());
       
   267     imp->setOnopen(createJSAttributeEventListener(exec, value, thisObject));
       
   268 }
       
   269 
       
   270 void setJSEventSourceOnmessage(ExecState* exec, JSObject* thisObject, JSValue value)
       
   271 {
       
   272     UNUSED_PARAM(exec);
       
   273     EventSource* imp = static_cast<EventSource*>(static_cast<JSEventSource*>(thisObject)->impl());
       
   274     imp->setOnmessage(createJSAttributeEventListener(exec, value, thisObject));
       
   275 }
       
   276 
       
   277 void setJSEventSourceOnerror(ExecState* exec, JSObject* thisObject, JSValue value)
       
   278 {
       
   279     UNUSED_PARAM(exec);
       
   280     EventSource* imp = static_cast<EventSource*>(static_cast<JSEventSource*>(thisObject)->impl());
       
   281     imp->setOnerror(createJSAttributeEventListener(exec, value, thisObject));
       
   282 }
       
   283 
       
   284 JSValue JSEventSource::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
       
   285 {
       
   286     return getDOMConstructor<JSEventSourceConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
       
   287 }
       
   288 
       
   289 EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionClose(ExecState* exec)
       
   290 {
       
   291     JSValue thisValue = exec->hostThisValue();
       
   292     if (!thisValue.inherits(&JSEventSource::s_info))
       
   293         return throwVMTypeError(exec);
       
   294     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(thisValue));
       
   295     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   296 
       
   297     imp->close();
       
   298     return JSValue::encode(jsUndefined());
       
   299 }
       
   300 
       
   301 EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionAddEventListener(ExecState* exec)
       
   302 {
       
   303     JSValue thisValue = exec->hostThisValue();
       
   304     if (!thisValue.inherits(&JSEventSource::s_info))
       
   305         return throwVMTypeError(exec);
       
   306     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(thisValue));
       
   307     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   308     JSValue listener = exec->argument(1);
       
   309     if (!listener.isObject())
       
   310         return JSValue::encode(jsUndefined());
       
   311     imp->addEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
       
   312     return JSValue::encode(jsUndefined());
       
   313 }
       
   314 
       
   315 EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionRemoveEventListener(ExecState* exec)
       
   316 {
       
   317     JSValue thisValue = exec->hostThisValue();
       
   318     if (!thisValue.inherits(&JSEventSource::s_info))
       
   319         return throwVMTypeError(exec);
       
   320     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(thisValue));
       
   321     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   322     JSValue listener = exec->argument(1);
       
   323     if (!listener.isObject())
       
   324         return JSValue::encode(jsUndefined());
       
   325     imp->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
       
   326     return JSValue::encode(jsUndefined());
       
   327 }
       
   328 
       
   329 EncodedJSValue JSC_HOST_CALL jsEventSourcePrototypeFunctionDispatchEvent(ExecState* exec)
       
   330 {
       
   331     JSValue thisValue = exec->hostThisValue();
       
   332     if (!thisValue.inherits(&JSEventSource::s_info))
       
   333         return throwVMTypeError(exec);
       
   334     JSEventSource* castedThis = static_cast<JSEventSource*>(asObject(thisValue));
       
   335     EventSource* imp = static_cast<EventSource*>(castedThis->impl());
       
   336     ExceptionCode ec = 0;
       
   337     Event* evt = toEvent(exec->argument(0));
       
   338 
       
   339 
       
   340     JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec));
       
   341     setDOMException(exec, ec);
       
   342     return JSValue::encode(result);
       
   343 }
       
   344 
       
   345 // Constant getters
       
   346 
       
   347 JSValue jsEventSourceCONNECTING(ExecState* exec, JSValue, const Identifier&)
       
   348 {
       
   349     return jsNumber(exec, static_cast<int>(0));
       
   350 }
       
   351 
       
   352 JSValue jsEventSourceOPEN(ExecState* exec, JSValue, const Identifier&)
       
   353 {
       
   354     return jsNumber(exec, static_cast<int>(1));
       
   355 }
       
   356 
       
   357 JSValue jsEventSourceCLOSED(ExecState* exec, JSValue, const Identifier&)
       
   358 {
       
   359     return jsNumber(exec, static_cast<int>(2));
       
   360 }
       
   361 
       
   362 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, EventSource* object)
       
   363 {
       
   364     return getDOMObjectWrapper<JSEventSource>(exec, globalObject, object);
       
   365 }
       
   366 EventSource* toEventSource(JSC::JSValue value)
       
   367 {
       
   368     return value.inherits(&JSEventSource::s_info) ? static_cast<JSEventSource*>(asObject(value))->impl() : 0;
       
   369 }
       
   370 
       
   371 }
       
   372 
       
   373 #endif // ENABLE(EVENTSOURCE)