JSMessagePortCustom.cpp [plain text]
#include "config.h"
#include "JSMessagePort.h"
#include "Event.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "JSArrayBuffer.h"
#include "JSDOMGlobalObject.h"
#include "JSEvent.h"
#include "JSEventListener.h"
#include "JSMessagePortCustom.h"
#include "MessagePort.h"
#include <runtime/Error.h>
#include <wtf/text/AtomicString.h>
using namespace JSC;
namespace WebCore {
void JSMessagePort::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
JSMessagePort* thisObject = jsCast<JSMessagePort*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
Base::visitChildren(thisObject, visitor);
if (MessagePort* port = thisObject->m_impl->locallyEntangledPort())
visitor.addOpaqueRoot(port);
thisObject->m_impl->visitJSEventListeners(visitor);
}
JSC::JSValue JSMessagePort::postMessage(JSC::ExecState* exec)
{
return handlePostMessage(exec, impl());
}
void fillMessagePortArray(JSC::ExecState* exec, JSC::JSValue value, MessagePortArray& portArray, ArrayBufferArray& arrayBuffers)
{
if (value.isUndefinedOrNull()) {
portArray.resize(0);
arrayBuffers.resize(0);
return;
}
unsigned length = 0;
JSObject* object = toJSSequence(exec, value, length);
if (exec->hadException())
return;
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) {
if (portArray.contains(port)) {
setDOMException(exec, INVALID_STATE_ERR);
return;
}
portArray.append(port.release());
} else {
RefPtr<ArrayBuffer> arrayBuffer = toArrayBuffer(value);
if (arrayBuffer)
arrayBuffers.append(arrayBuffer);
else {
throwTypeError(exec);
return;
}
}
}
}
}