ScriptArguments.cpp [plain text]
#include "config.h"
#include "ScriptArguments.h"
#include "ScriptValue.h"
namespace WebCore {
PassRefPtr<ScriptArguments> ScriptArguments::create(ScriptState* scriptState, Vector<ScriptValue>& arguments)
{
return adoptRef(new ScriptArguments(scriptState, arguments));
}
ScriptArguments::ScriptArguments(ScriptState* scriptState, Vector<ScriptValue>& arguments)
: m_globalObject(scriptState->vm(), scriptState->lexicalGlobalObject())
{
m_arguments.swap(arguments);
}
ScriptArguments::~ScriptArguments()
{
}
const ScriptValue &ScriptArguments::argumentAt(size_t index) const
{
ASSERT(m_arguments.size() > index);
return m_arguments[index];
}
ScriptState* ScriptArguments::globalState() const
{
if (m_globalObject)
return const_cast<JSC::JSGlobalObject*>(m_globalObject.get())->globalExec();
return 0;
}
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined)
{
if (!argumentCount())
return false;
const ScriptValue& value = argumentAt(0);
if (checkForNullOrUndefined && (value.isNull() || value.isUndefined()))
return false;
if (!globalState()) {
ASSERT_NOT_REACHED();
return false;
}
result = value.toString(globalState());
return true;
}
bool ScriptArguments::isEqual(ScriptArguments* other) const
{
if (!other)
return false;
if (m_arguments.size() != other->m_arguments.size())
return false;
if (!globalState() && m_arguments.size())
return false;
for (size_t i = 0; i < m_arguments.size(); ++i) {
if (!m_arguments[i].isEqual(other->globalState(), other->m_arguments[i]))
return false;
}
return true;
}
}