Bug 136297 - Web Replay: code generator should be able to encode/decode ViewState::Flags
Summary: Web Replay: code generator should be able to encode/decode ViewState::Flags
Status: RESOLVED LATER
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 136312
Blocks: 129694
  Show dependency treegraph
 
Reported: 2014-08-27 11:04 PDT by Brian Burg
Modified: 2017-07-10 13:59 PDT (History)
2 users (show)

See Also:


Attachments
WIP (30.05 KB, patch)
2014-09-24 16:36 PDT, Brian Burg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Burg 2014-08-27 11:04:54 PDT
ViewState::(enum) is an anonymous enum inside of a struct (ViewState). ViewState::Flags is a typedef for uint32_t, and the enum values are used to bitwise-construct and query a uint32_t containing several flags.

For replay we still want to serialize ViewState with string names, since ViewState::Flags could change in the future and we don't want reordering the flags to break serialization.
But, since the enum is un-named and ViewState::Flags is a uint32_t, the existing code will try to define new EncodingTraits specializations for uint32_t, which isn't allowed.

To sidestep this, I'll generate a wrapper class for each framework, so multiple specializations can exist for the same underlying type. Cases like ViewState will use a new flag in the inputs file to opt-in to this code generation behavior.


Sketch:

enum class JSEnum { FooBar, BarBaz };

template <JSEnum EnumName, typename StorageType>
class UncheckedJSEnum {
public:
    UncheckedJSEnum(StorageType value) : m_value(value) { }
    StorageType m_value;
};
    
template<> struct EncodingTraits<UncheckedJSEnum<JSEnum::FooBar,uint32_t>> {
  ...  
};
Comment 1 Brian Burg 2014-08-27 11:59:58 PDT
Even simpler:

enum class WebEnums { FooBar, BarBaz };
struct ViewState {
    typedef uint32_t Flags;
};
template <typename EnumType, EnumType tag>
class Phantom { };
template<> struct EncodingTraits<Phantom<JSEnums,JSEnums::FooBar>> {
    typedef ViewState::Flags DecodedType;
    static EncodedValue encodeValue(const DecodedType&);
    static bool decodeValue(EncodedValue&, const DecodedType&);
};
Comment 2 Brian Burg 2014-09-24 16:36:44 PDT
Created attachment 238625 [details]
WIP
Comment 3 BJ Burg 2017-07-10 13:59:36 PDT
Closing web replay-related bugs until we resume working on the feature again.