ReadableStreamController.cpp [plain text]
#include "config.h"
#include "ReadableStreamController.h"
#if ENABLE(STREAMS_API)
#include "JSReadableStream.h"
#include "JSReadableStreamSource.h"
#include "WebCoreJSClientData.h"
namespace WebCore {
static inline JSC::JSValue callFunction(JSC::ExecState& state, JSC::JSValue jsFunction, JSC::JSValue thisValue, const JSC::ArgList& arguments)
{
JSC::CallData callData;
auto callType = JSC::getCallData(jsFunction, callData);
return call(&state, jsFunction, callType, callData, thisValue, arguments);
}
JSC::JSValue ReadableStreamController::invoke(JSC::ExecState& state, JSC::JSObject& object, const char* propertyName, JSC::JSValue parameter)
{
JSC::JSLockHolder lock(&state);
auto function = object.get(&state, JSC::Identifier::fromString(&state, propertyName));
if (state.hadException())
return JSC::jsUndefined();
if (!function.isFunction()) {
if (!function.isUndefined())
throwTypeError(&state, ASCIILiteral("ReadableStream trying to call a property that is not callable"));
return JSC::jsUndefined();
}
JSC::MarkedArgumentBuffer arguments;
arguments.append(parameter);
return callFunction(state, function, &object, arguments);
}
bool ReadableStreamController::isControlledReadableStreamLocked() const
{
auto& state = *globalObject()->globalExec();
JSC::JSLockHolder lock(&state);
auto& clientData = *static_cast<JSVMClientData*>(state.vm().clientData);
auto readableStream = m_jsController->get(&state, clientData.builtinNames().controlledReadableStreamPrivateName());
ASSERT(!state.hadException());
auto isLocked = globalObject()->builtinInternalFunctions().readableStreamInternals().m_isReadableStreamLockedFunction.get();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
auto result = callFunction(state, isLocked, JSC::jsUndefined(), arguments);
ASSERT(!state.hadException());
return result.isTrue();
}
JSC::JSValue createReadableStream(JSC::ExecState& state, JSDOMGlobalObject* globalObject, ReadableStreamSource* source)
{
JSC::JSLockHolder lock(&state);
auto jsSource = source ? toJS(&state, globalObject, *source) : JSC::jsUndefined();
JSC::Strong<JSC::Unknown> protect(state.vm(), jsSource);
JSC::MarkedArgumentBuffer arguments;
arguments.append(jsSource);
auto constructor = JSReadableStream::getConstructor(state.vm(), globalObject);
JSC::ConstructData constructData;
auto constructType = JSC::getConstructData(constructor, constructData);
ASSERT(constructType != JSC::ConstructType::None);
return construct(&state, constructor, constructType, constructData, arguments);
}
JSC::JSValue getReadableStreamReader(JSC::ExecState& state, JSC::JSValue readableStream)
{
ASSERT(readableStream.isObject());
auto getReader = readableStream.getObject()->get(&state, JSC::Identifier::fromString(&state, "getReader"));
ASSERT(!state.hadException());
auto reader = callFunction(state, getReader, readableStream, JSC::MarkedArgumentBuffer());
ASSERT(!state.hadException());
return reader;
}
}
#endif // ENABLE(STREAMS_API)