JSLocationCustom.cpp [plain text]
#include "config.h"
#include "JSLocation.h"
#include "JSDOMBinding.h"
#include "RuntimeApplicationChecks.h"
#include <runtime/JSFunction.h>
using namespace JSC;
namespace WebCore {
bool JSLocation::getOwnPropertySlotDelegate(ExecState* state, PropertyName propertyName, PropertySlot& slot)
{
VM& vm = state->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Frame* frame = wrapped().frame();
if (!frame) {
slot.setUndefined();
return true;
}
String message;
if (BindingSecurity::shouldAllowAccessToFrame(*state, *frame, message))
return false;
if (propertyName == state->propertyNames().toStringTagSymbol || propertyName == state->propertyNames().hasInstanceSymbol || propertyName == state->propertyNames().isConcatSpreadableSymbol) {
slot.setUndefined();
return true;
}
if (propertyName == state->propertyNames().replace) {
slot.setCustom(this, ReadOnly | DontEnum, nonCachingStaticFunctionGetter<jsLocationInstanceFunctionReplace, 1>);
return true;
}
if (slot.internalMethodType() == PropertySlot::InternalMethodType::GetOwnProperty && propertyName == state->propertyNames().href) {
auto* entry = JSLocation::info()->staticPropHashTable->entry(propertyName);
CustomGetterSetter* customGetterSetter = CustomGetterSetter::create(vm, nullptr, entry->propertyPutter());
slot.setCustomGetterSetter(this, DontEnum | CustomAccessor, customGetterSetter);
return true;
}
throwSecurityError(*state, scope, message);
slot.setUndefined();
return true;
}
bool JSLocation::putDelegate(ExecState* state, PropertyName propertyName, JSValue, PutPropertySlot&, bool& putResult)
{
putResult = false;
Frame* frame = wrapped().frame();
if (!frame)
return true;
if (propertyName == state->propertyNames().toString || propertyName == state->propertyNames().valueOf)
return true;
if (propertyName == state->propertyNames().href)
return false;
if (!BindingSecurity::shouldAllowAccessToFrame(state, frame, ThrowSecurityError))
return true;
return false;
}
bool JSLocation::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
JSLocation* thisObject = jsCast<JSLocation*>(cell);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), ThrowSecurityError))
return false;
return Base::deleteProperty(thisObject, exec, propertyName);
}
bool JSLocation::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
{
JSLocation* thisObject = jsCast<JSLocation*>(cell);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), ThrowSecurityError))
return false;
return Base::deletePropertyByIndex(thisObject, exec, propertyName);
}
static void addCrossOriginLocationPropertyNames(ExecState& state, PropertyNameArray& propertyNames)
{
static const Identifier* const properties[] = { &state.propertyNames().href, &state.propertyNames().replace };
for (auto* property : properties)
propertyNames.add(*property);
}
void JSLocation::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
JSLocation* thisObject = jsCast<JSLocation*>(object);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), DoNotReportSecurityError)) {
if (mode.includeDontEnumProperties())
addCrossOriginLocationPropertyNames(*exec, propertyNames);
return;
}
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
bool JSLocation::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool throwException)
{
JSLocation* thisObject = jsCast<JSLocation*>(object);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), ThrowSecurityError))
return false;
if (descriptor.isAccessorDescriptor() && (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf))
return false;
return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
bool JSLocation::setPrototype(JSObject*, ExecState* exec, JSValue, bool shouldThrowIfCantSet)
{
auto scope = DECLARE_THROW_SCOPE(exec->vm());
if (shouldThrowIfCantSet)
throwTypeError(exec, scope, ASCIILiteral("Cannot set prototype of this object"));
return false;
}
JSValue JSLocation::getPrototype(JSObject* object, ExecState* exec)
{
JSLocation* thisObject = jsCast<JSLocation*>(object);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), DoNotReportSecurityError))
return jsNull();
return Base::getPrototype(object, exec);
}
bool JSLocation::preventExtensions(JSObject* object, ExecState* exec)
{
JSLocation* thisObject = jsCast<JSLocation*>(object);
if (!BindingSecurity::shouldAllowAccessToFrame(exec, thisObject->wrapped().frame(), ThrowSecurityError))
return false;
return Base::preventExtensions(object, exec);
}
bool JSLocationPrototype::putDelegate(ExecState* exec, PropertyName propertyName, JSValue, PutPropertySlot&, bool& putResult)
{
putResult = false;
return (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf);
}
bool JSLocationPrototype::defineOwnProperty(JSObject* object, ExecState* exec, PropertyName propertyName, const PropertyDescriptor& descriptor, bool throwException)
{
if (descriptor.isAccessorDescriptor() && (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf))
return false;
return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
}
}