class Playwright::JavaScript::ValueParser
def initialize(hash)
def initialize(hash) @hash = hash @refs = {} end
def parse
-
(Hash)-
def parse if @hash.nil? nil else parse_hash(@hash) end end
def parse_hash(hash)
ref: https://github.com/microsoft/playwright/blob/b45905ae3f1a066a8ecb358035ce745ddd21cf3a/src/protocol/serializers.ts#L42
def parse_hash(hash) b).each do |key| rn hash[key] if hash.key?(key) h.key?('ref') rn @refs[hash['ref']] h.key?('v') rn case hash['v'] when 'undefined' nil when 'null' nil when 'NaN' Float::NAN when 'Infinity' Float::INFINITY when '-Infinity' -Float::INFINITY when '-0' -0 end h.key?('d') rn DateTime.parse(hash['d']) h.key?('u') rn URI(hash['u']) h.key?('bi') rn hash['bi'].to_i h.key?('m') rn parse_hash(hash['m']).to_h h.key?('se') rn Set.new(parse_hash(hash['se'])) h.key?('r') ee https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp ee https://docs.ruby-lang.org/ja/latest/class/Regexp.html egex_flag = hash['r']['f'] s = [] s << Regexp::IGNORECASE if js_regex_flag.include?('i') s << Regexp::MULTILINE if js_regex_flag.include?('m') || js_regex_flag.include?('s') rn Regexp.compile(hash['r']['p'], flags.inject(:|)) h.key?('a') lt = [] ash['id'] efs[hash['id']] = result ['a'].each { |value| result << parse_hash(value) } rn result h.key?('o') lt = {} ash['id'] efs[hash['id']] = result ['o'].each { |obj| result[obj['k']] = parse_hash(obj['v']) } rn result h.key?('h') rn @handles[hash['h']] ArgumentError.new("Unexpected value: #{hash}")