Skip to content

Commit

Permalink
Update serialization for types including RunJavaScriptParameters
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262662
rdar://116490225

Reviewed by Alex Christensen.

* Source/WebCore/PAL/pal/SessionID.h:
(PAL::SessionID::encode const): Deleted.
(PAL::SessionID::decode): Deleted.
* Source/WebCore/bindings/js/RunJavaScriptParameters.h:
(WebCore::RunJavaScriptParameters::RunJavaScriptParameters):
(WebCore::RunJavaScriptParameters::encode const): Deleted.
(WebCore::RunJavaScriptParameters::decode): Deleted.
* Source/WebCore/platform/graphics/PlatformColorSpace.h:
(WebCore::PlatformColorSpace::encode const): Deleted.
(WebCore::PlatformColorSpace::decode): Deleted.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/268915@main
  • Loading branch information
sheeparegreat authored and achristensen07 committed Oct 5, 2023
1 parent 71a0ded commit ca78091
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 84 deletions.
23 changes: 1 addition & 22 deletions Source/WebCore/PAL/pal/SessionID.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,15 @@ class SessionID {
friend bool operator==(SessionID, SessionID) = default;
bool isAlwaysOnLoggingAllowed() const { return !isEphemeral(); }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<SessionID> decode(Decoder&);

SessionID isolatedCopy() const { return *this; }

explicit operator bool() const { return m_identifier; }

private:
static bool isValidSessionIDValue(uint64_t sessionID) { return sessionID != HashTableEmptyValueID && sessionID != HashTableDeletedValueID; }

private:
uint64_t m_identifier;
};

template<class Encoder>
void SessionID::encode(Encoder& encoder) const
{
ASSERT(isValid());
encoder << m_identifier;
}

template<class Decoder>
std::optional<SessionID> SessionID::decode(Decoder& decoder)
{
std::optional<uint64_t> sessionID;
decoder >> sessionID;
if (!sessionID || !isValidSessionIDValue(*sessionID))
return std::nullopt;
return SessionID { *sessionID };
}

} // namespace PAL

namespace WTF {
Expand Down
48 changes: 4 additions & 44 deletions Source/WebCore/bindings/js/RunJavaScriptParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ using ArgumentWireBytesMap = HashMap<String, Vector<uint8_t>>;
struct RunJavaScriptParameters {
RunJavaScriptParameters(String&& source, JSC::SourceTaintedOrigin taintedness, URL&& sourceURL, RunAsAsyncFunction runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, ForceUserGesture forceUserGesture, RemoveTransientActivation removeTransientActivation)
: source(WTFMove(source))
, sourceURL(WTFMove(sourceURL))
, taintedness(taintedness)
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture)
Expand All @@ -54,8 +54,8 @@ struct RunJavaScriptParameters {

RunJavaScriptParameters(const String& source, JSC::SourceTaintedOrigin taintedness, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture, RemoveTransientActivation removeTransientActivation)
: source(source)
, sourceURL(WTFMove(sourceURL))
, taintedness(taintedness)
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction ? RunAsAsyncFunction::Yes : RunAsAsyncFunction::No)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture ? ForceUserGesture::Yes : ForceUserGesture::No)
Expand All @@ -65,8 +65,8 @@ struct RunJavaScriptParameters {

RunJavaScriptParameters(String&& source, JSC::SourceTaintedOrigin taintedness, URL&& sourceURL, bool runAsAsyncFunction, std::optional<ArgumentWireBytesMap>&& arguments, bool forceUserGesture, RemoveTransientActivation removeTransientActivation)
: source(WTFMove(source))
, sourceURL(WTFMove(sourceURL))
, taintedness(taintedness)
, sourceURL(WTFMove(sourceURL))
, runAsAsyncFunction(runAsAsyncFunction ? RunAsAsyncFunction::Yes : RunAsAsyncFunction::No)
, arguments(WTFMove(arguments))
, forceUserGesture(forceUserGesture ? ForceUserGesture::Yes : ForceUserGesture::No)
Expand All @@ -75,52 +75,12 @@ struct RunJavaScriptParameters {
}

String source;
URL sourceURL;
JSC::SourceTaintedOrigin taintedness;
URL sourceURL;
RunAsAsyncFunction runAsAsyncFunction;
std::optional<ArgumentWireBytesMap> arguments;
ForceUserGesture forceUserGesture;
RemoveTransientActivation removeTransientActivation;

template<typename Encoder>
void encode(Encoder& encoder) const
{
encoder << source << sourceURL << taintedness << runAsAsyncFunction << arguments << forceUserGesture << removeTransientActivation;
}

template<typename Decoder>
static std::optional<RunJavaScriptParameters> decode(Decoder& decoder)
{
String source;
if (!decoder.decode(source))
return std::nullopt;

URL sourceURL;
if (!decoder.decode(sourceURL))
return std::nullopt;

JSC::SourceTaintedOrigin taintedness;
if (!decoder.decode(taintedness))
return std::nullopt;

RunAsAsyncFunction runAsAsyncFunction;
if (!decoder.decode(runAsAsyncFunction))
return std::nullopt;

std::optional<ArgumentWireBytesMap> arguments;
if (!decoder.decode(arguments))
return std::nullopt;

ForceUserGesture forceUserGesture;
if (!decoder.decode(forceUserGesture))
return std::nullopt;

RemoveTransientActivation removeTransientActivation;
if (!decoder.decode(removeTransientActivation))
return std::nullopt;

return { RunJavaScriptParameters { WTFMove(source), taintedness, WTFMove(sourceURL), runAsAsyncFunction, WTFMove(arguments), forceUserGesture, removeTransientActivation } };
}
};

} // namespace WebCore
18 changes: 0 additions & 18 deletions Source/WebCore/platform/graphics/PlatformColorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,12 @@ class PlatformColorSpace {

Name get() const { return m_name; }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static std::optional<PlatformColorSpace> decode(Decoder&);

private:
Name m_name;

};
using PlatformColorSpaceValue = PlatformColorSpace::Name;

template<class Encoder> void PlatformColorSpace::encode(Encoder& encoder) const
{
encoder << m_name;
}

template<class Decoder> std::optional<PlatformColorSpace> PlatformColorSpace::decode(Decoder& decoder)
{
std::optional<PlatformColorSpace::Name> name;
decoder >> name;
if (!name)
return std::nullopt;

return { { *name } };
}

#endif

}
19 changes: 19 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -3468,6 +3468,25 @@ struct WebCore::ListStyleType {
AtomString identifier;
};

header: <pal/SessionID.h>
[CustomHeader] class PAL::SessionID {
[Validator='PAL::SessionID::isValidSessionIDValue(*toUInt64)'] uint64_t toUInt64();
}

enum class WebCore::RunAsAsyncFunction : bool;
enum class WebCore::ForceUserGesture : bool;
enum class WebCore::RemoveTransientActivation : bool;

struct WebCore::RunJavaScriptParameters {
String source;
JSC::SourceTaintedOrigin taintedness;
URL sourceURL;
WebCore::RunAsAsyncFunction runAsAsyncFunction;
std::optional<WebCore::ArgumentWireBytesMap> arguments;
WebCore::ForceUserGesture forceUserGesture;
WebCore::RemoveTransientActivation removeTransientActivation;
}

header: <WebCore/FontAttributes.h>
[CustomHeader] struct WebCore::TextList {
WebCore::ListStyleType styleType;
Expand Down

0 comments on commit ca78091

Please sign in to comment.