WebCore/generated/JSMessagePort.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 #include "JSMessagePort.h"
       
    23 
       
    24 #include "Event.h"
       
    25 #include "EventListener.h"
       
    26 #include "JSEvent.h"
       
    27 #include "JSEventListener.h"
       
    28 #include "MessagePort.h"
       
    29 #include "PlatformString.h"
       
    30 #include "RegisteredEventListener.h"
       
    31 #include <runtime/Error.h>
       
    32 #include <wtf/GetPtr.h>
       
    33 
       
    34 using namespace JSC;
       
    35 
       
    36 namespace WebCore {
       
    37 
       
    38 ASSERT_CLASS_FITS_IN_CELL(JSMessagePort);
       
    39 
       
    40 /* Hash table */
       
    41 #if ENABLE(JIT)
       
    42 #define THUNK_GENERATOR(generator) , generator
       
    43 #else
       
    44 #define THUNK_GENERATOR(generator)
       
    45 #endif
       
    46 
       
    47 static const HashTableValue JSMessagePortTableValues[3] =
       
    48 {
       
    49     { "onmessage", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessagePortOnmessage), (intptr_t)setJSMessagePortOnmessage THUNK_GENERATOR(0) },
       
    50     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMessagePortConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
       
    51     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    52 };
       
    53 
       
    54 #undef THUNK_GENERATOR
       
    55 static JSC_CONST_HASHTABLE HashTable JSMessagePortTable = { 4, 3, JSMessagePortTableValues, 0 };
       
    56 /* Hash table for constructor */
       
    57 #if ENABLE(JIT)
       
    58 #define THUNK_GENERATOR(generator) , generator
       
    59 #else
       
    60 #define THUNK_GENERATOR(generator)
       
    61 #endif
       
    62 
       
    63 static const HashTableValue JSMessagePortConstructorTableValues[1] =
       
    64 {
       
    65     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
    66 };
       
    67 
       
    68 #undef THUNK_GENERATOR
       
    69 static JSC_CONST_HASHTABLE HashTable JSMessagePortConstructorTable = { 1, 0, JSMessagePortConstructorTableValues, 0 };
       
    70 class JSMessagePortConstructor : public DOMConstructorObject {
       
    71 public:
       
    72     JSMessagePortConstructor(JSC::ExecState*, JSDOMGlobalObject*);
       
    73 
       
    74     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
       
    75     virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
       
    76     virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
       
    77     static const JSC::ClassInfo s_info;
       
    78     static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype)
       
    79     {
       
    80         return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount);
       
    81     }
       
    82 protected:
       
    83     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;
       
    84 };
       
    85 
       
    86 const ClassInfo JSMessagePortConstructor::s_info = { "MessagePortConstructor", 0, &JSMessagePortConstructorTable, 0 };
       
    87 
       
    88 JSMessagePortConstructor::JSMessagePortConstructor(ExecState* exec, JSDOMGlobalObject* globalObject)
       
    89     : DOMConstructorObject(JSMessagePortConstructor::createStructure(globalObject->objectPrototype()), globalObject)
       
    90 {
       
    91     putDirect(exec->propertyNames().prototype, JSMessagePortPrototype::self(exec, globalObject), DontDelete | ReadOnly);
       
    92 }
       
    93 
       
    94 bool JSMessagePortConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
    95 {
       
    96     return getStaticValueSlot<JSMessagePortConstructor, DOMObject>(exec, &JSMessagePortConstructorTable, this, propertyName, slot);
       
    97 }
       
    98 
       
    99 bool JSMessagePortConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   100 {
       
   101     return getStaticValueDescriptor<JSMessagePortConstructor, DOMObject>(exec, &JSMessagePortConstructorTable, this, propertyName, descriptor);
       
   102 }
       
   103 
       
   104 /* Hash table for prototype */
       
   105 #if ENABLE(JIT)
       
   106 #define THUNK_GENERATOR(generator) , generator
       
   107 #else
       
   108 #define THUNK_GENERATOR(generator)
       
   109 #endif
       
   110 
       
   111 static const HashTableValue JSMessagePortPrototypeTableValues[7] =
       
   112 {
       
   113     { "postMessage", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionPostMessage), (intptr_t)2 THUNK_GENERATOR(0) },
       
   114     { "start", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionStart), (intptr_t)0 THUNK_GENERATOR(0) },
       
   115     { "close", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionClose), (intptr_t)0 THUNK_GENERATOR(0) },
       
   116     { "addEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionAddEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
       
   117     { "removeEventListener", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionRemoveEventListener), (intptr_t)3 THUNK_GENERATOR(0) },
       
   118     { "dispatchEvent", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsMessagePortPrototypeFunctionDispatchEvent), (intptr_t)1 THUNK_GENERATOR(0) },
       
   119     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
       
   120 };
       
   121 
       
   122 #undef THUNK_GENERATOR
       
   123 static JSC_CONST_HASHTABLE HashTable JSMessagePortPrototypeTable = { 17, 15, JSMessagePortPrototypeTableValues, 0 };
       
   124 static const HashTable* getJSMessagePortPrototypeTable(ExecState* exec)
       
   125 {
       
   126     return getHashTableForGlobalData(exec->globalData(), &JSMessagePortPrototypeTable);
       
   127 }
       
   128 const ClassInfo JSMessagePortPrototype::s_info = { "MessagePortPrototype", 0, 0, getJSMessagePortPrototypeTable };
       
   129 
       
   130 JSObject* JSMessagePortPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
       
   131 {
       
   132     return getDOMPrototype<JSMessagePort>(exec, globalObject);
       
   133 }
       
   134 
       
   135 bool JSMessagePortPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   136 {
       
   137     return getStaticFunctionSlot<JSObject>(exec, getJSMessagePortPrototypeTable(exec), this, propertyName, slot);
       
   138 }
       
   139 
       
   140 bool JSMessagePortPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   141 {
       
   142     return getStaticFunctionDescriptor<JSObject>(exec, getJSMessagePortPrototypeTable(exec), this, propertyName, descriptor);
       
   143 }
       
   144 
       
   145 static const HashTable* getJSMessagePortTable(ExecState* exec)
       
   146 {
       
   147     return getHashTableForGlobalData(exec->globalData(), &JSMessagePortTable);
       
   148 }
       
   149 const ClassInfo JSMessagePort::s_info = { "MessagePort", 0, 0, getJSMessagePortTable };
       
   150 
       
   151 JSMessagePort::JSMessagePort(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject* globalObject, PassRefPtr<MessagePort> impl)
       
   152     : DOMObjectWithGlobalPointer(structure, globalObject)
       
   153     , m_impl(impl)
       
   154 {
       
   155 }
       
   156 
       
   157 JSMessagePort::~JSMessagePort()
       
   158 {
       
   159     impl()->invalidateJSEventListeners(this);
       
   160     forgetDOMObject(this, impl());
       
   161 }
       
   162 
       
   163 JSObject* JSMessagePort::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
       
   164 {
       
   165     return new (exec) JSMessagePortPrototype(globalObject, JSMessagePortPrototype::createStructure(globalObject->objectPrototype()));
       
   166 }
       
   167 
       
   168 bool JSMessagePort::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   169 {
       
   170     return getStaticValueSlot<JSMessagePort, Base>(exec, getJSMessagePortTable(exec), this, propertyName, slot);
       
   171 }
       
   172 
       
   173 bool JSMessagePort::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
       
   174 {
       
   175     return getStaticValueDescriptor<JSMessagePort, Base>(exec, getJSMessagePortTable(exec), this, propertyName, descriptor);
       
   176 }
       
   177 
       
   178 JSValue jsMessagePortOnmessage(ExecState* exec, JSValue slotBase, const Identifier&)
       
   179 {
       
   180     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(slotBase));
       
   181     UNUSED_PARAM(exec);
       
   182     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   183     if (EventListener* listener = imp->onmessage()) {
       
   184         if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {
       
   185             if (JSObject* jsFunction = jsListener->jsFunction(imp->scriptExecutionContext()))
       
   186                 return jsFunction;
       
   187         }
       
   188     }
       
   189     return jsNull();
       
   190 }
       
   191 
       
   192 JSValue jsMessagePortConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
       
   193 {
       
   194     JSMessagePort* domObject = static_cast<JSMessagePort*>(asObject(slotBase));
       
   195     return JSMessagePort::getConstructor(exec, domObject->globalObject());
       
   196 }
       
   197 void JSMessagePort::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
       
   198 {
       
   199     lookupPut<JSMessagePort, Base>(exec, propertyName, value, getJSMessagePortTable(exec), this, slot);
       
   200 }
       
   201 
       
   202 void setJSMessagePortOnmessage(ExecState* exec, JSObject* thisObject, JSValue value)
       
   203 {
       
   204     UNUSED_PARAM(exec);
       
   205     MessagePort* imp = static_cast<MessagePort*>(static_cast<JSMessagePort*>(thisObject)->impl());
       
   206     imp->setOnmessage(createJSAttributeEventListener(exec, value, thisObject));
       
   207 }
       
   208 
       
   209 JSValue JSMessagePort::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
       
   210 {
       
   211     return getDOMConstructor<JSMessagePortConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
       
   212 }
       
   213 
       
   214 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionPostMessage(ExecState* exec)
       
   215 {
       
   216     JSValue thisValue = exec->hostThisValue();
       
   217     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   218         return throwVMTypeError(exec);
       
   219     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   220     return JSValue::encode(castedThis->postMessage(exec));
       
   221 }
       
   222 
       
   223 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionStart(ExecState* exec)
       
   224 {
       
   225     JSValue thisValue = exec->hostThisValue();
       
   226     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   227         return throwVMTypeError(exec);
       
   228     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   229     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   230 
       
   231     imp->start();
       
   232     return JSValue::encode(jsUndefined());
       
   233 }
       
   234 
       
   235 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionClose(ExecState* exec)
       
   236 {
       
   237     JSValue thisValue = exec->hostThisValue();
       
   238     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   239         return throwVMTypeError(exec);
       
   240     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   241     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   242 
       
   243     imp->close();
       
   244     return JSValue::encode(jsUndefined());
       
   245 }
       
   246 
       
   247 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionAddEventListener(ExecState* exec)
       
   248 {
       
   249     JSValue thisValue = exec->hostThisValue();
       
   250     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   251         return throwVMTypeError(exec);
       
   252     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   253     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   254     JSValue listener = exec->argument(1);
       
   255     if (!listener.isObject())
       
   256         return JSValue::encode(jsUndefined());
       
   257     imp->addEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
       
   258     return JSValue::encode(jsUndefined());
       
   259 }
       
   260 
       
   261 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionRemoveEventListener(ExecState* exec)
       
   262 {
       
   263     JSValue thisValue = exec->hostThisValue();
       
   264     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   265         return throwVMTypeError(exec);
       
   266     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   267     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   268     JSValue listener = exec->argument(1);
       
   269     if (!listener.isObject())
       
   270         return JSValue::encode(jsUndefined());
       
   271     imp->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
       
   272     return JSValue::encode(jsUndefined());
       
   273 }
       
   274 
       
   275 EncodedJSValue JSC_HOST_CALL jsMessagePortPrototypeFunctionDispatchEvent(ExecState* exec)
       
   276 {
       
   277     JSValue thisValue = exec->hostThisValue();
       
   278     if (!thisValue.inherits(&JSMessagePort::s_info))
       
   279         return throwVMTypeError(exec);
       
   280     JSMessagePort* castedThis = static_cast<JSMessagePort*>(asObject(thisValue));
       
   281     MessagePort* imp = static_cast<MessagePort*>(castedThis->impl());
       
   282     ExceptionCode ec = 0;
       
   283     Event* evt = toEvent(exec->argument(0));
       
   284 
       
   285 
       
   286     JSC::JSValue result = jsBoolean(imp->dispatchEvent(evt, ec));
       
   287     setDOMException(exec, ec);
       
   288     return JSValue::encode(result);
       
   289 }
       
   290 
       
   291 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, MessagePort* object)
       
   292 {
       
   293     return getDOMObjectWrapper<JSMessagePort>(exec, globalObject, object);
       
   294 }
       
   295 MessagePort* toMessagePort(JSC::JSValue value)
       
   296 {
       
   297     return value.inherits(&JSMessagePort::s_info) ? static_cast<JSMessagePort*>(asObject(value))->impl() : 0;
       
   298 }
       
   299 
       
   300 }