JSHistoryCustom.cpp [plain text]
#include "config.h"
#include "JSHistory.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "JSDOMConvertNullable.h"
#include "JSDOMConvertStrings.h"
#include "SerializedScriptValue.h"
#include <runtime/JSFunction.h>
using namespace JSC;
namespace WebCore {
JSValue JSHistory::state(ExecState& state) const
{
History& history = wrapped();
JSValue cachedValue = m_state.get();
if (!cachedValue.isEmpty() && !history.stateChanged())
return cachedValue;
RefPtr<SerializedScriptValue> serialized = history.state();
JSValue result = serialized ? serialized->deserialize(state, globalObject()) : jsNull();
m_state.set(state.vm(), this, result);
return result;
}
JSValue JSHistory::pushState(ExecState& state)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto argCount = state.argumentCount();
if (UNLIKELY(argCount < 2))
return throwException(&state, scope, createNotEnoughArgumentsError(&state));
auto historyState = SerializedScriptValue::create(state, state.uncheckedArgument(0));
RETURN_IF_EXCEPTION(scope, JSValue());
String title = convert<IDLNullable<IDLDOMString>>(state, state.uncheckedArgument(1));
RETURN_IF_EXCEPTION(scope, JSValue());
String url;
if (argCount > 2) {
url = convert<IDLNullable<IDLUSVString>>(state, state.uncheckedArgument(2));
RETURN_IF_EXCEPTION(scope, JSValue());
}
propagateException(state, scope, wrapped().stateObjectAdded(WTFMove(historyState), title, url, History::StateObjectType::Push));
m_state.clear();
return jsUndefined();
}
JSValue JSHistory::replaceState(ExecState& state)
{
VM& vm = state.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
auto argCount = state.argumentCount();
if (UNLIKELY(argCount < 2))
return throwException(&state, scope, createNotEnoughArgumentsError(&state));
auto historyState = SerializedScriptValue::create(state, state.uncheckedArgument(0));
RETURN_IF_EXCEPTION(scope, JSValue());
String title = convert<IDLNullable<IDLDOMString>>(state, state.uncheckedArgument(1));
RETURN_IF_EXCEPTION(scope, JSValue());
String url;
if (argCount > 2) {
url = convert<IDLNullable<IDLUSVString>>(state, state.uncheckedArgument(2));
RETURN_IF_EXCEPTION(scope, JSValue());
}
propagateException(state, scope, wrapped().stateObjectAdded(WTFMove(historyState), title, url, History::StateObjectType::Replace));
m_state.clear();
return jsUndefined();
}
}