JSAudioContextCustom.cpp [plain text]
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "AudioContext.h"
#include "AudioBuffer.h"
#include "JSArrayBuffer.h"
#include "JSAudioBuffer.h"
#include "JSAudioContext.h"
#include <runtime/Error.h>
#include <wtf/ArrayBuffer.h>
using namespace JSC;
namespace WebCore {
void JSAudioContext::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
JSAudioContext* thisObject = jsCast<JSAudioContext*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
Base::visitChildren(thisObject, visitor);
thisObject->m_impl->visitJSEventListeners(visitor);
}
EncodedJSValue JSC_HOST_CALL JSAudioContextConstructor::constructJSAudioContext(ExecState* exec)
{
JSAudioContextConstructor* jsConstructor = jsCast<JSAudioContextConstructor*>(exec->callee());
if (!jsConstructor)
return throwVMError(exec, createReferenceError(exec, "AudioContext constructor callee is unavailable"));
ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext();
if (!scriptExecutionContext)
return throwVMError(exec, createReferenceError(exec, "AudioContext constructor script execution context is unavailable"));
if (!scriptExecutionContext->isDocument())
return throwVMError(exec, createReferenceError(exec, "AudioContext constructor called in a script execution context which is not a document"));
Document* document = static_cast<Document*>(scriptExecutionContext);
RefPtr<AudioContext> audioContext;
if (!exec->argumentCount()) {
ExceptionCode ec = 0;
audioContext = AudioContext::create(document, ec);
if (ec) {
setDOMException(exec, ec);
return JSValue::encode(JSValue());
}
if (!audioContext.get())
return throwVMError(exec, createSyntaxError(exec, "audio resources unavailable for AudioContext construction"));
} else {
if (exec->argumentCount() < 3)
return throwVMError(exec, createNotEnoughArgumentsError(exec));
int32_t numberOfChannels = exec->argument(0).toInt32(exec);
int32_t numberOfFrames = exec->argument(1).toInt32(exec);
float sampleRate = exec->argument(2).toFloat(exec);
if (numberOfChannels <= 0 || numberOfChannels > 10)
return throwVMError(exec, createSyntaxError(exec, "Invalid number of channels"));
if (numberOfFrames <= 0)
return throwVMError(exec, createSyntaxError(exec, "Invalid number of frames"));
if (sampleRate <= 0)
return throwVMError(exec, createSyntaxError(exec, "Invalid sample rate"));
ExceptionCode ec = 0;
audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec);
if (ec) {
setDOMException(exec, ec);
return throwVMError(exec, createSyntaxError(exec, "Error creating OfflineAudioContext"));
}
}
if (!audioContext.get())
return throwVMError(exec, createReferenceError(exec, "Error creating AudioContext"));
return JSValue::encode(CREATE_DOM_WRAPPER(exec, jsConstructor->globalObject(), AudioContext, audioContext.get()));
}
}
#endif // ENABLE(WEB_AUDIO)