Changeset 229392 in webkit
- Timestamp:
- Mar 7, 2018 7:31:01 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r229390 r229392 1 2018-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 1 25 2018-03-07 Youenn Fablet <youenn@apple.com> 2 26 -
trunk/Source/WebCore/bindings/js/JSHistoryCustom.cpp
r228218 r229392 1 1 /* 2 * Copyright (C) 2008 , 2016Apple Inc. All rights reserved.2 * Copyright (C) 2008-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #include "JSHistory.h" 31 31 32 #include "Frame.h"33 #include "JSDOMConvertNullable.h"34 #include "JSDOMConvertStrings.h"35 32 #include "SerializedScriptValue.h" 36 #include <JavaScriptCore/JSFunction.h>37 33 38 34 namespace WebCore { 35 39 36 using namespace JSC; 40 37 41 38 JSValue JSHistory::state(ExecState& state) const 42 39 { 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 }); 53 44 } 54 45 55 JSValue JSHistory::pushState(ExecState& state)46 void JSHistory::visitAdditionalChildren(SlotVisitor& visitor) 56 47 { 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); 111 49 } 112 50 -
trunk/Source/WebCore/page/History.cpp
r229375 r229392 1 1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2007-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 105 105 } 106 106 107 JSValueInWrappedObject& History::cachedState() 108 { 109 if (m_cachedState && stateChanged()) 110 m_cachedState = { }; 111 return m_cachedState; 112 } 113 107 114 bool History::isSameAsCurrentState(SerializedScriptValue* state) const 108 115 { … … 164 171 ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data, const String& title, const String& urlString, StateObjectType stateObjectType) 165 172 { 173 m_cachedState = { }; 174 166 175 // Each unique main-frame document is only allowed to send 64MB of state object payload to the UI client/process. 167 176 static uint32_t totalStateObjectPayloadLimit = 0x4000000; -
trunk/Source/WebCore/page/History.h
r228942 r229392 1 1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2007-2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #include "DOMWindowProperty.h" 29 29 #include "ExceptionOr.h" 30 #include "JSValueInWrappedObject.h" 30 31 #include "ScriptWrappable.h" 31 32 #include "SerializedScriptValue.h" … … 53 54 54 55 SerializedScriptValue* state(); 56 JSValueInWrappedObject& cachedState(); 57 55 58 void back(); 56 59 void forward(); … … 61 64 void go(Document&, int); 62 65 63 bool stateChanged() const;64 66 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 71 private: 72 explicit History(Frame&); 65 73 66 74 enum class StateObjectType { Push, Replace }; 67 75 ExceptionOr<void> stateObjectAdded(RefPtr<SerializedScriptValue>&&, const String& title, const String& url, StateObjectType); 68 69 private: 70 explicit History(Frame&); 76 bool stateChanged() const; 71 77 72 78 URL urlForState(const String& url); … … 75 81 76 82 RefPtr<SerializedScriptValue> m_lastStateObjectRequested; 83 JSValueInWrappedObject m_cachedState; 77 84 78 85 unsigned m_currentStateObjectTimeSpanObjectsAdded { 0 }; … … 86 93 }; 87 94 95 inline 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 100 inline 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 88 105 } // namespace WebCore -
trunk/Source/WebCore/page/History.idl
r222454 r229392 26 26 [ 27 27 GenerateIsReachable=ImplFrame, 28 JSCustomMarkFunction, 28 29 ] interface History { 29 30 readonly attribute unsigned long length; 30 31 attribute ScrollRestoration scrollRestoration; 31 [C achedAttribute, Custom] readonly attribute SerializedScriptValuestate;32 [Custom] readonly attribute any state; 32 33 33 34 [CallWith=Document, ForwardDeclareInHeader] void back(); 34 35 [CallWith=Document, ForwardDeclareInHeader] void forward(); 35 [CallWith=Document, ForwardDeclareInHeader] void go(optional long d istance= 0);36 [CallWith=Document, ForwardDeclareInHeader] void go(optional long delta = 0); 36 37 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); 39 41 }; 40 42
Note: See TracChangeset
for help on using the changeset viewer.