Changeset 229392 in webkit


Ignore:
Timestamp:
Mar 7, 2018 7:31:01 PM (6 years ago)
Author:
Chris Dumez
Message:

Get rid of custom bindings for History's replaceState() / pushState()
https://bugs.webkit.org/show_bug.cgi?id=183372

Reviewed by Youenn Fablet.

Get rid of custom bindings for History's replaceState() / pushState() by
moving the cached state from the wrapper to the History implementation
object.

No new tests, no web-facing behavior change.

  • bindings/js/JSHistoryCustom.cpp:

(WebCore::JSHistory::state const):
(WebCore::JSHistory::visitAdditionalChildren):

  • page/History.cpp:

(WebCore::History::cachedState):
(WebCore::History::stateObjectAdded):

  • page/History.h:

(WebCore::History::pushState):
(WebCore::History::replaceState):

  • page/History.idl:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r229390 r229392  
     12018-03-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Get rid of custom bindings for History's replaceState() / pushState()
     4        https://bugs.webkit.org/show_bug.cgi?id=183372
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Get rid of custom bindings for History's replaceState() / pushState() by
     9        moving the cached state from the wrapper to the History implementation
     10        object.
     11
     12        No new tests, no web-facing behavior change.
     13
     14        * bindings/js/JSHistoryCustom.cpp:
     15        (WebCore::JSHistory::state const):
     16        (WebCore::JSHistory::visitAdditionalChildren):
     17        * page/History.cpp:
     18        (WebCore::History::cachedState):
     19        (WebCore::History::stateObjectAdded):
     20        * page/History.h:
     21        (WebCore::History::pushState):
     22        (WebCore::History::replaceState):
     23        * page/History.idl:
     24
    1252018-03-07  Youenn Fablet  <youenn@apple.com>
    226
  • trunk/Source/WebCore/bindings/js/JSHistoryCustom.cpp

    r228218 r229392  
    11/*
    2  * Copyright (C) 2008, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "JSHistory.h"
    3131
    32 #include "Frame.h"
    33 #include "JSDOMConvertNullable.h"
    34 #include "JSDOMConvertStrings.h"
    3532#include "SerializedScriptValue.h"
    36 #include <JavaScriptCore/JSFunction.h>
    3733
    3834namespace WebCore {
     35
    3936using namespace JSC;
    4037
    4138JSValue JSHistory::state(ExecState& state) const
    4239{
    43     History& history = wrapped();
    44 
    45     JSValue cachedValue = m_state.get();
    46     if (!cachedValue.isEmpty() && !history.stateChanged())
    47         return cachedValue;
    48 
    49     RefPtr<SerializedScriptValue> serialized = history.state();
    50     JSValue result = serialized ? serialized->deserialize(state, globalObject()) : jsNull();
    51     m_state.set(state.vm(), this, result);
    52     return result;
     40    return cachedPropertyValue(state, *this, wrapped().cachedState(), [this, &state] {
     41        auto* serialized = wrapped().state();
     42        return serialized ? serialized->deserialize(state, globalObject()) : jsNull();
     43    });
    5344}
    5445
    55 JSValue JSHistory::pushState(ExecState& state)
     46void JSHistory::visitAdditionalChildren(SlotVisitor& visitor)
    5647{
    57     VM& vm = state.vm();
    58     auto scope = DECLARE_THROW_SCOPE(vm);
    59 
    60     auto argCount = state.argumentCount();
    61     if (UNLIKELY(argCount < 2))
    62         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
    63 
    64     auto historyState = SerializedScriptValue::create(state, state.uncheckedArgument(0));
    65     RETURN_IF_EXCEPTION(scope, JSValue());
    66 
    67     // FIXME: title should not be nullable.
    68     String title = convert<IDLNullable<IDLDOMString>>(state, state.uncheckedArgument(1));
    69     RETURN_IF_EXCEPTION(scope, JSValue());
    70 
    71     String url;
    72     if (argCount > 2) {
    73         url = convert<IDLNullable<IDLUSVString>>(state, state.uncheckedArgument(2));
    74         RETURN_IF_EXCEPTION(scope, JSValue());
    75     }
    76 
    77     propagateException(state, scope, wrapped().stateObjectAdded(WTFMove(historyState), title, url, History::StateObjectType::Push));
    78 
    79     m_state.clear();
    80 
    81     return jsUndefined();
    82 }
    83 
    84 JSValue JSHistory::replaceState(ExecState& state)
    85 {
    86     VM& vm = state.vm();
    87     auto scope = DECLARE_THROW_SCOPE(vm);
    88 
    89     auto argCount = state.argumentCount();
    90     if (UNLIKELY(argCount < 2))
    91         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
    92 
    93     auto historyState = SerializedScriptValue::create(state, state.uncheckedArgument(0));
    94     RETURN_IF_EXCEPTION(scope, JSValue());
    95 
    96     // FIXME: title should not be nullable.
    97     String title = convert<IDLNullable<IDLDOMString>>(state, state.uncheckedArgument(1));
    98     RETURN_IF_EXCEPTION(scope, JSValue());
    99 
    100     String url;
    101     if (argCount > 2) {
    102         url = convert<IDLNullable<IDLUSVString>>(state, state.uncheckedArgument(2));
    103         RETURN_IF_EXCEPTION(scope, JSValue());
    104     }
    105 
    106     propagateException(state, scope, wrapped().stateObjectAdded(WTFMove(historyState), title, url, History::StateObjectType::Replace));
    107 
    108     m_state.clear();
    109 
    110     return jsUndefined();
     48    wrapped().cachedState().visit(visitor);
    11149}
    11250
  • trunk/Source/WebCore/page/History.cpp

    r229375 r229392  
    11/*
    2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2007-2018 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    105105}
    106106
     107JSValueInWrappedObject& History::cachedState()
     108{
     109    if (m_cachedState && stateChanged())
     110        m_cachedState = { };
     111    return m_cachedState;
     112}
     113
    107114bool History::isSameAsCurrentState(SerializedScriptValue* state) const
    108115{
     
    164171ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString, StateObjectType stateObjectType)
    165172{
     173    m_cachedState = { };
     174
    166175    // Each unique main-frame document is only allowed to send 64MB of state object payload to the UI client/process.
    167176    static uint32_t totalStateObjectPayloadLimit = 0x4000000;
  • trunk/Source/WebCore/page/History.h

    r228942 r229392  
    11/*
    2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2007-2018 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#include "DOMWindowProperty.h"
    2929#include "ExceptionOr.h"
     30#include "JSValueInWrappedObject.h"
    3031#include "ScriptWrappable.h"
    3132#include "SerializedScriptValue.h"
     
    5354
    5455    SerializedScriptValue* state();
     56    JSValueInWrappedObject& cachedState();
     57
    5558    void back();
    5659    void forward();
     
    6164    void go(Document&, int);
    6265
    63     bool stateChanged() const;
    6466    bool isSameAsCurrentState(SerializedScriptValue*) const;
     67
     68    ExceptionOr<void> pushState(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString);
     69    ExceptionOr<void> replaceState(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString);
     70
     71private:
     72    explicit History(Frame&);
    6573
    6674    enum class StateObjectType { Push, Replace };
    6775    ExceptionOr<void> stateObjectAdded(RefPtr<SerializedScriptValue>&&, const String& title, const String& url, StateObjectType);
    68 
    69 private:
    70     explicit History(Frame&);
     76    bool stateChanged() const;
    7177
    7278    URL urlForState(const String& url);
     
    7581
    7682    RefPtr<SerializedScriptValue> m_lastStateObjectRequested;
     83    JSValueInWrappedObject m_cachedState;
    7784
    7885    unsigned m_currentStateObjectTimeSpanObjectsAdded { 0 };
     
    8693};
    8794
     95inline ExceptionOr<void> History::pushState(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString)
     96{
     97    return stateObjectAdded(WTFMove(data), title, urlString, StateObjectType::Push);
     98}
     99
     100inline ExceptionOr<void> History::replaceState(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString)
     101{
     102    return stateObjectAdded(WTFMove(data), title, urlString, StateObjectType::Replace);
     103}
     104
    88105} // namespace WebCore
  • trunk/Source/WebCore/page/History.idl

    r222454 r229392  
    2626[
    2727    GenerateIsReachable=ImplFrame,
     28    JSCustomMarkFunction,
    2829] interface History {
    2930    readonly attribute unsigned long length;
    3031    attribute ScrollRestoration scrollRestoration;
    31     [CachedAttribute, Custom] readonly attribute SerializedScriptValue state;
     32    [Custom] readonly attribute any state;
    3233
    3334    [CallWith=Document, ForwardDeclareInHeader] void back();
    3435    [CallWith=Document, ForwardDeclareInHeader] void forward();
    35     [CallWith=Document, ForwardDeclareInHeader] void go(optional long distance = 0);
     36    [CallWith=Document, ForwardDeclareInHeader] void go(optional long delta = 0);
    3637
    37     [Custom, MayThrowException] void pushState(any data, DOMString title, optional USVString? url = null);
    38     [Custom, MayThrowException] void replaceState(any data, DOMString title, optional USVString? url = null);
     38    // FIXME: title should not be nullable as per the HTML specification.
     39    [MayThrowException] void pushState(SerializedScriptValue data, DOMString? title, optional USVString? url = null);
     40    [MayThrowException] void replaceState(SerializedScriptValue data, DOMString? title, optional USVString? url = null);
    3941};
    4042
Note: See TracChangeset for help on using the changeset viewer.