JSHistoryCustom.cpp [plain text]
#include "config.h"
#include "JSHistoryCustom.h"
#include "Frame.h"
#include "History.h"
#include "SerializedScriptValue.h"
#include <runtime/JSFunction.h>
using namespace JSC;
namespace WebCore {
static JSValue nonCachingStaticBackFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 0, propertyName, jsHistoryPrototypeFunctionBack);
}
static JSValue nonCachingStaticForwardFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 0, propertyName, jsHistoryPrototypeFunctionForward);
}
static JSValue nonCachingStaticGoFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName)
{
return JSFunction::create(exec, exec->lexicalGlobalObject(), 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() & JSC::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() & JSC::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(JSCell* cell, ExecState* exec, const Identifier& propertyName)
{
JSHistory* thisObject = jsCast<JSHistory*>(cell);
if (!allowsAccessFromFrame(exec, thisObject->impl()->frame()))
return false;
return Base::deleteProperty(thisObject, exec, propertyName);
}
void JSHistory::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
JSHistory* thisObject = jsCast<JSHistory*>(object);
if (!allowsAccessFromFrame(exec, thisObject->impl()->frame()))
return;
Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
JSValue JSHistory::pushState(ExecState* exec)
{
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0));
if (exec->hadException())
return jsUndefined();
String title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(1));
if (exec->hadException())
return jsUndefined();
String url;
if (exec->argumentCount() > 2) {
url = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(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)
{
RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0));
if (exec->hadException())
return jsUndefined();
String title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(1));
if (exec->hadException())
return jsUndefined();
String url;
if (exec->argumentCount() > 2) {
url = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2));
if (exec->hadException())
return jsUndefined();
}
ExceptionCode ec = 0;
impl()->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec);
setDOMException(exec, ec);
return jsUndefined();
}
}