NullSetterFunction.cpp [plain text]
#include "config.h"
#include "NullSetterFunction.h"
#include "CodeBlock.h"
#include "Error.h"
#include "JSCInlines.h"
#include "JSCJSValueInlines.h"
#include "StackVisitor.h"
namespace JSC {
const ClassInfo NullSetterFunction::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NullSetterFunction) };
class GetCallerStrictnessFunctor {
public:
GetCallerStrictnessFunctor()
: m_iterations(0)
, m_callerIsStrict(false)
{
}
StackVisitor::Status operator()(StackVisitor& visitor) const
{
++m_iterations;
if (m_iterations < 2)
return StackVisitor::Continue;
CodeBlock* codeBlock = visitor->codeBlock();
m_callerIsStrict = codeBlock && codeBlock->isStrictMode();
return StackVisitor::Done;
}
bool callerIsStrict() const { return m_callerIsStrict; }
private:
mutable int m_iterations;
mutable bool m_callerIsStrict;
};
static bool callerIsStrict(VM& vm, CallFrame* callFrame)
{
GetCallerStrictnessFunctor iter;
callFrame->iterate(vm, iter);
return iter.callerIsStrict();
}
namespace NullSetterFunctionInternal {
static EncodedJSValue JSC_HOST_CALL callReturnUndefined(JSGlobalObject* globalObject, CallFrame* callFrame)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
if (callerIsStrict(vm, callFrame))
return JSValue::encode(throwTypeError(globalObject, scope, "Setting a property that has only a getter"_s));
return JSValue::encode(jsUndefined());
}
}
NullSetterFunction::NullSetterFunction(VM& vm, Structure* structure)
: Base(vm, structure, NullSetterFunctionInternal::callReturnUndefined, nullptr)
{
}
}