JSLocationCustom.cpp [plain text]
#include "config.h"
#include "JSLocation.h"
#include "JSDOMBinding.h"
#include <runtime/JSFunction.h>
using namespace JSC;
namespace WebCore {
bool JSLocation::getOwnPropertySlotDelegate(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
Frame* frame = impl().frame();
if (!frame) {
slot.setUndefined();
return true;
}
String message;
if (shouldAllowAccessToFrame(exec, frame, message))
return false;
if (propertyName == exec->propertyNames().replace) {
slot.setCustom(this, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsLocationPrototypeFunctionReplace, 1>);
return true;
}
if (propertyName == exec->propertyNames().reload) {
slot.setCustom(this, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsLocationPrototypeFunctionReload, 0>);
return true;
}
if (propertyName == exec->propertyNames().assign) {
slot.setCustom(this, ReadOnly | DontDelete | DontEnum, nonCachingStaticFunctionGetter<jsLocationPrototypeFunctionAssign, 1>);
return true;
}
printErrorMessageForFrame(frame, message);
slot.setUndefined();
return true;
}
bool JSLocation::putDelegate(ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
{
Frame* frame = impl().frame();
if (!frame)
return true;
if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf)
return true;
bool sameDomainAccess = shouldAllowAccessToFrame(exec, frame);
const HashTableValue* entry = JSLocation::info()->propHashTable(exec)->entry(exec, propertyName);
if (!entry) {
if (sameDomainAccess)
JSObject::put(this, exec, propertyName, value, slot);
return true;
}
if (propertyName != exec->propertyNames().href && !sameDomainAccess)
return true;
return false;
}
bool JSLocation::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
JSLocation* thisObject = jsCast<JSLocation*>(cell);
if (!shouldAllowAccessToFrame(exec, thisObject->impl().frame()))
return false;
return Base::deleteProperty(thisObject, exec, propertyName);
}
bool JSLocation::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
{
JSLocation* thisObject = jsCast<JSLocation*>(cell);
if (!shouldAllowAccessToFrame(exec, thisObject->impl().frame()))
return false;
return Base::deletePropertyByIndex(thisObject, exec, propertyName);
}
void JSLocation::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
JSLocation* thisObject = jsCast<JSLocation*>(object);
if (!shouldAllowAccessToFrame(exec, thisObject->impl().frame()))
return;
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
bool JSLocation::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);
}
void JSLocation::setHref(ExecState* exec, JSValue value)
{
String href = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setHref(href, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setProtocol(ExecState* exec, JSValue value)
{
String protocol = value.toString(exec)->value(exec);
if (exec->hadException())
return;
ExceptionCode ec = 0;
impl().setProtocol(protocol, activeDOMWindow(exec), firstDOMWindow(exec), ec);
setDOMException(exec, ec);
}
void JSLocation::setHost(ExecState* exec, JSValue value)
{
String host = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setHost(host, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setHostname(ExecState* exec, JSValue value)
{
String hostname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setHostname(hostname, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setPort(ExecState* exec, JSValue value)
{
String port = value.toWTFString(exec);
if (exec->hadException())
return;
impl().setPort(port, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setPathname(ExecState* exec, JSValue value)
{
String pathname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setPathname(pathname, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setSearch(ExecState* exec, JSValue value)
{
String pathname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setSearch(pathname, activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setHash(ExecState* exec, JSValue value)
{
String hash = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl().setHash(hash, activeDOMWindow(exec), firstDOMWindow(exec));
}
JSValue JSLocation::replace(ExecState* exec)
{
String urlString = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return jsUndefined();
impl().replace(urlString, activeDOMWindow(exec), firstDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::reload(ExecState* exec)
{
impl().reload(activeDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::assign(ExecState* exec)
{
String urlString = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return jsUndefined();
impl().assign(urlString, activeDOMWindow(exec), firstDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::toStringFunction(ExecState* exec)
{
Frame* frame = impl().frame();
if (!frame || !shouldAllowAccessToFrame(exec, frame))
return jsUndefined();
return jsStringWithCache(exec, impl().toString());
}
bool JSLocationPrototype::putDelegate(ExecState* exec, PropertyName propertyName, JSValue, PutPropertySlot&)
{
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);
}
}