JSRTCRtpSFrameTransformCustom.cpp [plain text]
#include "config.h"
#include "JSRTCRtpSFrameTransform.h"
#if ENABLE(WEB_RTC)
#include "JSCryptoKey.h"
#include "JSDOMPromiseDeferred.h"
#include <JavaScriptCore/JSBigInt.h>
namespace WebCore {
using namespace JSC;
JSValue JSRTCRtpSFrameTransform::setEncryptionKey(JSGlobalObject& lexicalGlobalObject, CallFrame& callFrame, Ref<DeferredPromise>&& promise)
{
auto& vm = getVM(&lexicalGlobalObject);
auto throwScope = DECLARE_THROW_SCOPE(vm);
if (UNLIKELY(callFrame.argumentCount() < 1)) {
throwVMError(&lexicalGlobalObject, throwScope, createNotEnoughArgumentsError(&lexicalGlobalObject));
return jsUndefined();
}
EnsureStillAliveScope argument0 = callFrame.uncheckedArgument(0);
auto key = convert<IDLInterface<CryptoKey>>(lexicalGlobalObject, argument0.value(), [](auto& lexicalGlobalObject, auto& scope) {
throwArgumentTypeError(lexicalGlobalObject, scope, 0, "key", "SFrameTransform", "setEncryptionKey", "CryptoKey");
});
RETURN_IF_EXCEPTION(throwScope, jsUndefined());
EnsureStillAliveScope argument1 = callFrame.argument(1);
Optional<uint64_t> keyID;
if (!argument1.value().isUndefined()) {
if (argument1.value().isBigInt()) {
if (argument1.value().asHeapBigInt()->length() > 1) {
throwException(&lexicalGlobalObject, throwScope, createDOMException(&lexicalGlobalObject, RangeError, "Not a 64 bits integer"_s));
return jsUndefined();
}
keyID = JSBigInt::toBigUInt64(argument1.value());
} else
keyID = Optional<Converter<IDLUnsignedLongLong>::ReturnType>(convert<IDLUnsignedLongLong>(lexicalGlobalObject, argument1.value()));
}
RETURN_IF_EXCEPTION(throwScope, jsUndefined());
throwScope.release();
wrapped().setEncryptionKey(*key, keyID, WTFMove(promise));
return jsUndefined();
}
}
#endif