JSLocationCustom.cpp [plain text]
#include "config.h"
#include "JSLocationCustom.h"
#include "Location.h"
#include <runtime/JSFunction.h>
using namespace JSC;
namespace WebCore {
static JSValue nonCachingStaticReplaceFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 1, propertyName, jsLocationPrototypeFunctionReplace);
}
static JSValue nonCachingStaticReloadFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 0, propertyName, jsLocationPrototypeFunctionReload);
}
static JSValue nonCachingStaticAssignFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 1, propertyName, jsLocationPrototypeFunctionAssign);
}
bool JSLocation::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
Frame* frame = impl()->frame();
if (!frame) {
slot.setUndefined();
return true;
}
String message;
if (shouldAllowAccessToFrame(exec, frame, message))
return false;
const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry && (entry->attributes() & JSC::Function)) {
if (entry->function() == jsLocationPrototypeFunctionReplace) {
slot.setCustom(this, nonCachingStaticReplaceFunctionGetter);
return true;
} else if (entry->function() == jsLocationPrototypeFunctionReload) {
slot.setCustom(this, nonCachingStaticReloadFunctionGetter);
return true;
} else if (entry->function() == jsLocationPrototypeFunctionAssign) {
slot.setCustom(this, nonCachingStaticAssignFunctionGetter);
return true;
}
}
printErrorMessageForFrame(frame, message);
slot.setUndefined();
return true;
}
bool JSLocation::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
Frame* frame = impl()->frame();
if (!frame) {
descriptor.setUndefined();
return true;
}
if (!shouldAllowAccessToFrame(exec, frame))
return true;
const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
PropertySlot slot;
if (entry && (entry->attributes() & JSC::Function)) {
if (entry->function() == jsLocationPrototypeFunctionReplace) {
slot.setCustom(this, nonCachingStaticReplaceFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
} else if (entry->function() == jsLocationPrototypeFunctionReload) {
slot.setCustom(this, nonCachingStaticReloadFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
} else if (entry->function() == jsLocationPrototypeFunctionAssign) {
slot.setCustom(this, nonCachingStaticAssignFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
}
}
descriptor.setUndefined();
return true;
}
bool JSLocation::putDelegate(ExecState* exec, const Identifier& 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 HashEntry* entry = JSLocation::s_info.propHashTable(exec)->entry(exec, propertyName);
if (!entry) {
if (sameDomainAccess)
JSObject::put(this, exec, propertyName, value, slot);
return true;
}
if (entry->propertyPutter() != setJSLocationHref && !sameDomainAccess)
return true;
return false;
}
bool JSLocation::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
{
JSLocation* thisObject = jsCast<JSLocation*>(cell);
if (!shouldAllowAccessToFrame(exec, thisObject->impl()->frame()))
return false;
return Base::deleteProperty(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, const Identifier& propertyName, 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)
{
UString href = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setHref(ustringToString(href), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setProtocol(ExecState* exec, JSValue value)
{
UString protocol = value.toString(exec)->value(exec);
if (exec->hadException())
return;
ExceptionCode ec = 0;
impl()->setProtocol(ustringToString(protocol), activeDOMWindow(exec), firstDOMWindow(exec), ec);
setDOMException(exec, ec);
}
void JSLocation::setHost(ExecState* exec, JSValue value)
{
UString host = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setHost(ustringToString(host), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setHostname(ExecState* exec, JSValue value)
{
UString hostname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setHostname(ustringToString(hostname), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setPort(ExecState* exec, JSValue value)
{
UString port = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setPort(ustringToString(port), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setPathname(ExecState* exec, JSValue value)
{
UString pathname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setPathname(ustringToString(pathname), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setSearch(ExecState* exec, JSValue value)
{
UString pathname = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setSearch(ustringToString(pathname), activeDOMWindow(exec), firstDOMWindow(exec));
}
void JSLocation::setHash(ExecState* exec, JSValue value)
{
UString hash = value.toString(exec)->value(exec);
if (exec->hadException())
return;
impl()->setHash(ustringToString(hash), activeDOMWindow(exec), firstDOMWindow(exec));
}
JSValue JSLocation::replace(ExecState* exec)
{
UString urlString = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return jsUndefined();
impl()->replace(ustringToString(urlString), activeDOMWindow(exec), firstDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::reload(ExecState* exec)
{
impl()->reload(activeDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::assign(ExecState* exec)
{
UString urlString = exec->argument(0).toString(exec)->value(exec);
if (exec->hadException())
return jsUndefined();
impl()->assign(ustringToString(urlString), activeDOMWindow(exec), firstDOMWindow(exec));
return jsUndefined();
}
JSValue JSLocation::toStringFunction(ExecState* exec)
{
Frame* frame = impl()->frame();
if (!frame || !shouldAllowAccessToFrame(exec, frame))
return jsUndefined();
return jsString(exec, impl()->toString());
}
bool JSLocationPrototype::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue, PutPropertySlot&)
{
return (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf);
}
bool JSLocationPrototype::defineOwnProperty(JSObject* object, ExecState* exec, const Identifier& propertyName, 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);
}
}