github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/dom/frame_id.go (about)

     1  package dom
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/mafredri/cdp/protocol/page"
     7  	"github.com/wI2L/jettison"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/core"
    10  	"github.com/MontFerret/ferret/pkg/runtime/values"
    11  )
    12  
    13  var FrameIDType = core.NewType("ferret.drivers.cdp.dom.FrameID")
    14  
    15  type FrameID page.FrameID
    16  
    17  func NewFrameID(id page.FrameID) FrameID {
    18  	return FrameID(id)
    19  }
    20  
    21  func (f FrameID) MarshalJSON() ([]byte, error) {
    22  	return jettison.MarshalOpts(string(f), jettison.NoHTMLEscaping())
    23  }
    24  
    25  func (f FrameID) Type() core.Type {
    26  	return FrameIDType
    27  }
    28  
    29  func (f FrameID) String() string {
    30  	return string(f)
    31  }
    32  
    33  func (f FrameID) Compare(other core.Value) int64 {
    34  	var s1 string
    35  	var s2 string
    36  
    37  	s1 = string(f)
    38  
    39  	switch v := other.(type) {
    40  	case FrameID:
    41  		s2 = string(v)
    42  	case *HTMLDocument:
    43  		s2 = string(v.Frame().Frame.ID)
    44  	case values.String:
    45  		s2 = v.String()
    46  	default:
    47  		return -1
    48  	}
    49  
    50  	return int64(strings.Compare(s1, s2))
    51  }
    52  
    53  func (f FrameID) Unwrap() interface{} {
    54  	return page.FrameID(f)
    55  }
    56  
    57  func (f FrameID) Hash() uint64 {
    58  	return values.Hash(FrameIDType, []byte(f))
    59  }
    60  
    61  func (f FrameID) Copy() core.Value {
    62  	return f
    63  }