JSWebAnimationCustom.cpp [plain text]
#include "config.h"
#include "JSWebAnimation.h"
#include "Document.h"
#include "JSAnimationEffect.h"
#include "JSAnimationTimeline.h"
#include "JSCSSAnimation.h"
#include "JSCSSTransition.h"
#include "JSDOMConstructor.h"
#include "JSDOMConvert.h"
namespace WebCore {
using namespace JSC;
JSValue toJSNewlyCreated(JSGlobalObject*, JSDOMGlobalObject* globalObject, Ref<WebAnimation>&& value)
{
if (value->isCSSAnimation())
return createWrapper<CSSAnimation>(globalObject, WTFMove(value));
if (value->isCSSTransition())
return createWrapper<CSSTransition>(globalObject, WTFMove(value));
return createWrapper<WebAnimation>(globalObject, WTFMove(value));
}
JSValue toJS(JSGlobalObject* lexicalGlobalObject, JSDOMGlobalObject* globalObject, WebAnimation& value)
{
return wrap(lexicalGlobalObject, globalObject, value);
}
EncodedJSValue constructJSWebAnimation(JSGlobalObject* lexicalGlobalObject, CallFrame& callFrame)
{
VM& vm = lexicalGlobalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
UNUSED_PARAM(throwScope);
auto* jsConstructor = jsCast<JSDOMConstructorBase*>(callFrame.jsCallee());
ASSERT(jsConstructor);
auto* context = jsConstructor->scriptExecutionContext();
if (UNLIKELY(!context))
return throwConstructorScriptExecutionContextUnavailableError(*lexicalGlobalObject, throwScope, "Animation");
auto& document = downcast<Document>(*context);
auto effect = convert<IDLNullable<IDLInterface<AnimationEffect>>>(*lexicalGlobalObject, callFrame.argument(0), [](JSGlobalObject& lexicalGlobalObject, ThrowScope& scope) {
throwArgumentTypeError(lexicalGlobalObject, scope, 0, "effect", "Animation", nullptr, "AnimationEffect");
});
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (callFrame.argument(1).isUndefined()) {
auto object = WebAnimation::create(document, WTFMove(effect));
return JSValue::encode(toJSNewlyCreated<IDLInterface<WebAnimation>>(*lexicalGlobalObject, *jsConstructor->globalObject(), WTFMove(object)));
}
auto timeline = convert<IDLNullable<IDLInterface<AnimationTimeline>>>(*lexicalGlobalObject, callFrame.uncheckedArgument(1), [](JSGlobalObject& lexicalGlobalObject, ThrowScope& scope) {
throwArgumentTypeError(lexicalGlobalObject, scope, 1, "timeline", "Animation", nullptr, "AnimationTimeline");
});
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
auto object = WebAnimation::create(document, WTFMove(effect), WTFMove(timeline));
return JSValue::encode(toJSNewlyCreated<IDLInterface<WebAnimation>>(*lexicalGlobalObject, *jsConstructor->globalObject(), WTFMove(object)));
}
}