Exemple #1
0
void JSHistory::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
{
    JSHistory* thisObject = jsCast<JSHistory*>(object);
    // Only allow the history object to enumerated by frames in the same origin.
    if (!shouldAllowAccessToFrame(exec, thisObject->impl()->frame()))
        return;
    Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
}
bool JSHistory::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
{
    JSHistory* thisObject = jsCast<JSHistory*>(cell);
    // Only allow deleting by frames in the same origin.
    if (!allowAccessToFrame(exec, thisObject->impl()->frame()))
        return false;
    return Base::deleteProperty(thisObject, exec, propertyName);
}
Exemple #3
0
bool JSHistory::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName)
{
    JSHistory* thisObject = jsCast<JSHistory*>(cell);
    // Only allow deleting by frames in the same origin.
    if (!shouldAllowAccessToFrame(exec, thisObject->impl()->frame()))
        return false;
    return Base::deletePropertyByIndex(thisObject, exec, propertyName);
}
JSValue JSPopStateEvent::state(ExecState* exec) const
{
    JSValue cachedValue = m_state.get();
    if (!cachedValue.isEmpty()) {
        // We cannot use a cached object if we are in a different world than the one it was created in.
        if (!cachedValue.isObject() || &worldForDOMObject(cachedValue.getObject()) == &currentWorld(exec))
            return cachedValue;
        ASSERT_NOT_REACHED();
    }

    PopStateEvent& event = impl();

    if (!event.state().hasNoValue()) {
        // We need to make sure a PopStateEvent does not leak objects in its state property across isolated DOM worlds.
        // Ideally, we would check that the worlds have different privileges but that's not possible yet.
        JSValue state = event.state().jsValue();
        if (state.isObject() && &worldForDOMObject(state.getObject()) != &currentWorld(exec)) {
            if (RefPtr<SerializedScriptValue> serializedValue = event.trySerializeState(exec))
                state = serializedValue->deserialize(exec, globalObject(), nullptr);
            else
                state = jsNull();
        }

        return cacheState(exec, const_cast<JSPopStateEvent*>(this), state);
    }

    History* history = event.history();
    if (!history || !event.serializedState())
        return cacheState(exec, const_cast<JSPopStateEvent*>(this), jsNull());

    // There's no cached value from a previous invocation, nor a state value was provided by the
    // event, but there is a history object, so first we need to see if the state object has been
    // deserialized through the history object already.
    // The current history state object might've changed in the meantime, so we need to take care
    // of using the correct one, and always share the same deserialization with history.state.

    bool isSameState = history->isSameAsCurrentState(event.serializedState().get());
    JSValue result;

    if (isSameState) {
        JSHistory* jsHistory = jsCast<JSHistory*>(toJS(exec, globalObject(), history).asCell());
        result = jsHistory->state(exec);
    } else
        result = event.serializedState()->deserialize(exec, globalObject(), 0);

    return cacheState(exec, const_cast<JSPopStateEvent*>(this), result);
}