JSRTCPeerConnectionCustom.cpp [plain text]
#include "config.h"
#if ENABLE(MEDIA_STREAM)
#include "JSRTCPeerConnection.h"
#include "ExceptionCode.h"
#include "JSDOMBinding.h"
using namespace JSC;
namespace WebCore {
EncodedJSValue JSC_HOST_CALL constructJSRTCPeerConnection(ExecState* exec)
{
if (exec->argumentCount() < 1)
return throwVMError(exec, createNotEnoughArgumentsError(exec));
ExceptionCode ec = 0;
Dictionary rtcConfiguration(exec, exec->argument(0));
if (exec->hadException())
return JSValue::encode(jsUndefined());
if (!rtcConfiguration.isObject())
return throwVMError(exec, createTypeError(exec, "RTCPeerConnection argument must be a valid Dictionary"));
DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext();
if (!scriptExecutionContext)
return throwVMError(exec, createReferenceError(exec, "RTCPeerConnection constructor associated document is unavailable"));
RefPtr<RTCPeerConnection> peerConnection = RTCPeerConnection::create(*scriptExecutionContext, rtcConfiguration, ec);
if (ec == TYPE_MISMATCH_ERR) {
setDOMException(exec, ec);
return throwVMError(exec, createTypeError(exec, "Invalid RTCPeerConnection constructor arguments"));
}
if (ec) {
setDOMException(exec, ec);
return throwVMError(exec, createTypeError(exec, "Error creating RTCPeerConnection"));
}
return JSValue::encode(CREATE_DOM_WRAPPER(jsConstructor->globalObject(), RTCPeerConnection, peerConnection.get()));
}
}
#endif // ENABLE(MEDIA_STREAM)