JSHistoryCustom.cpp [plain text]
#include "config.h"
#include "JSHistoryCustom.h"
#include "Frame.h"
#include "History.h"
#include <runtime/JSFunction.h>
#include <runtime/PrototypeFunction.h>
using namespace JSC;
namespace WebCore {
static JSValue nonCachingStaticBackFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&)
{
return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, jsHistoryPrototypeFunctionBack);
}
static JSValue nonCachingStaticForwardFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&)
{
return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, jsHistoryPrototypeFunctionForward);
}
static JSValue nonCachingStaticGoFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&)
{
return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject()->prototypeFunctionStructure(), 1, propertyName, jsHistoryPrototypeFunctionGo);
}
bool JSHistory::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
String message;
if (allowsAccessFromFrame(exec, impl()->frame(), message))
return false;
const HashEntry* entry = JSHistoryPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry) {
if (entry->attributes() & Function) {
if (entry->function() == jsHistoryPrototypeFunctionBack) {
slot.setCustom(this, nonCachingStaticBackFunctionGetter);
return true;
} else if (entry->function() == jsHistoryPrototypeFunctionForward) {
slot.setCustom(this, nonCachingStaticForwardFunctionGetter);
return true;
} else if (entry->function() == jsHistoryPrototypeFunctionGo) {
slot.setCustom(this, nonCachingStaticGoFunctionGetter);
return true;
}
}
} else {
if (propertyName == exec->propertyNames().toString) {
slot.setCustom(this, objectToStringFunctionGetter);
return true;
}
}
printErrorMessageForFrame(impl()->frame(), message);
slot.setUndefined();
return true;
}
bool JSHistory::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
{
if (!impl()->frame()) {
descriptor.setUndefined();
return true;
}
if (!allowsAccessFromFrame(exec, impl()->frame()))
return true;
const HashEntry* entry = JSHistoryPrototype::s_info.propHashTable(exec)->entry(exec, propertyName);
if (entry) {
PropertySlot slot;
if (entry->attributes() & Function) {
if (entry->function() == jsHistoryPrototypeFunctionBack) {
slot.setCustom(this, nonCachingStaticBackFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
} else if (entry->function() == jsHistoryPrototypeFunctionForward) {
slot.setCustom(this, nonCachingStaticForwardFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
} else if (entry->function() == jsHistoryPrototypeFunctionGo) {
slot.setCustom(this, nonCachingStaticGoFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
}
}
} else {
if (propertyName == exec->propertyNames().toString) {
PropertySlot slot;
slot.setCustom(this, objectToStringFunctionGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
return true;
}
}
descriptor.setUndefined();
return true;
}
bool JSHistory::putDelegate(ExecState* exec, const Identifier&, JSValue, PutPropertySlot&)
{
if (!allowsAccessFromFrame(exec, impl()->frame()))
return true;
return false;
}
bool JSHistory::deleteProperty(ExecState* exec, const Identifier& propertyName)
{
if (!allowsAccessFromFrame(exec, impl()->frame()))
return false;
return Base::deleteProperty(exec, propertyName);
}
void JSHistory::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
if (!allowsAccessFromFrame(exec, impl()->frame()))
return;
Base::getOwnPropertyNames(exec, propertyNames, mode);
}
JSValue JSHistory::pushState(ExecState* exec, const ArgList& args)
{
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, args.at(0));
if (exec->hadException())
return jsUndefined();
String title = valueToStringWithUndefinedOrNullCheck(exec, args.at(1));
if (exec->hadException())
return jsUndefined();
String url;
if (args.size() > 2) {
url = valueToStringWithUndefinedOrNullCheck(exec, args.at(2));
if (exec->hadException())
return jsUndefined();
}
ExceptionCode ec = 0;
impl()->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec);
setDOMException(exec, ec);
return jsUndefined();
}
JSValue JSHistory::replaceState(ExecState* exec, const ArgList& args)
{
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, args.at(0));
if (exec->hadException())
return jsUndefined();
String title = valueToStringWithUndefinedOrNullCheck(exec, args.at(1));
if (exec->hadException())
return jsUndefined();
String url;
if (args.size() > 2) {
url = valueToStringWithUndefinedOrNullCheck(exec, args.at(2));
if (exec->hadException())
return jsUndefined();
}
ExceptionCode ec = 0;
impl()->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec);
setDOMException(exec, ec);
return jsUndefined();
}
}