JSMessagePortCustom.cpp [plain text]
#include "config.h"
#include "JSMessagePort.h"
#include "AtomicString.h"
#include "Event.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "JSDOMGlobalObject.h"
#include "JSEvent.h"
#include "JSEventListener.h"
#include "JSMessagePortCustom.h"
#include "MessagePort.h"
#include <runtime/Error.h>
using namespace JSC;
namespace WebCore {
void JSMessagePort::markChildren(MarkStack& markStack)
{
Base::markChildren(markStack);
if (MessagePort* entangledPort = m_impl->locallyEntangledPort())
markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), entangledPort);
m_impl->markJSEventListeners(markStack);
}
JSValue JSMessagePort::addEventListener(ExecState* exec, const ArgList& args)
{
JSValue listener = args.at(1);
if (!listener.isObject())
return jsUndefined();
impl()->addEventListener(args.at(0).toString(exec), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
return jsUndefined();
}
JSValue JSMessagePort::removeEventListener(ExecState* exec, const ArgList& args)
{
JSValue listener = args.at(1);
if (!listener.isObject())
return jsUndefined();
impl()->removeEventListener(args.at(0).toString(exec), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), args.at(2).toBoolean(exec));
return jsUndefined();
}
JSC::JSValue JSMessagePort::postMessage(JSC::ExecState* exec, const JSC::ArgList& args)
{
return handlePostMessage(exec, args, impl());
}
void fillMessagePortArray(JSC::ExecState* exec, JSC::JSValue value, MessagePortArray& portArray)
{
if (value.isUndefinedOrNull()) {
portArray.resize(0);
return;
}
unsigned length;
JSObject* object = toJSSequence(exec, value, length);
if (exec->hadException())
return;
portArray.resize(length);
for (unsigned i = 0 ; i < length; ++i) {
JSValue value = object->get(exec, i);
if (exec->hadException())
return;
if (value.isUndefinedOrNull()) {
setDOMException(exec, INVALID_STATE_ERR);
return;
}
RefPtr<MessagePort> port = toMessagePort(value);
if (!port) {
throwError(exec, TypeError);
return;
}
portArray[i] = port.release();
}
}
}