本文整理匯總了Golang中github.com/robertkrimen/otto.Object.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Object.Get方法的具體用法?Golang Object.Get怎麽用?Golang Object.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robertkrimen/otto.Object
的用法示例。
在下文中一共展示了Object.Get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getString
func getString(obj *otto.Object, name string) (string, error) {
v, err := obj.Get(name)
if err != nil {
return "", err
}
return v.ToString()
}
示例2: getInt
func getInt(obj *otto.Object, name string) (int64, error) {
v, err := obj.Get(name)
if err != nil {
return -1, err
}
return v.ToInteger()
}
示例3: getViaData
func getViaData(obj *otto.Object) (predicates []interface{}, tags []string, ok bool) {
argList, _ := obj.Get("_gremlin_values")
if argList.Class() != "GoArray" {
clog.Errorf("How is arglist not an array? Return nothing. %v", argList.Class())
return nil, nil, false
}
argArray := argList.Object()
lengthVal, _ := argArray.Get("length")
length, _ := lengthVal.ToInteger()
if length == 0 {
predicates = []interface{}{}
} else {
zero, _ := argArray.Get("0")
predicates = buildPathFromValue(zero)
}
if length >= 2 {
one, _ := argArray.Get("1")
if one.IsString() {
tags = append(tags, one.String())
} else if one.Class() == "Array" {
tags = stringsFrom(one.Object())
}
}
ok = true
return
}
示例4: fields
func (ctx ppctx) fields(obj *otto.Object) []string {
var (
vals, methods []string
seen = make(map[string]bool)
)
add := func(k string) {
if seen[k] || boringKeys[k] {
return
}
seen[k] = true
if v, _ := obj.Get(k); v.IsFunction() {
methods = append(methods, k)
} else {
vals = append(vals, k)
}
}
// add own properties
ctx.doOwnProperties(obj.Value(), add)
// add properties of the constructor
if cp := constructorPrototype(obj); cp != nil {
ctx.doOwnProperties(cp.Value(), add)
}
sort.Strings(vals)
sort.Strings(methods)
return append(vals, methods...)
}
示例5: propertiesOf
func propertiesOf(obj *otto.Object, name string) []string {
val, _ := obj.Get(name)
if val.IsUndefined() {
return nil
}
export, _ := val.Export()
return export.([]string)
}
示例6: getFirstArgAsMorphismChain
func getFirstArgAsMorphismChain(obj *otto.Object) *otto.Object {
arg, _ := obj.Get("_gremlin_values")
firstArg, _ := arg.Object().Get("0")
if isVertexChain(firstArg.Object()) {
return nil
}
return firstArg.Object()
}
示例7: constructorPrototype
func constructorPrototype(obj *otto.Object) *otto.Object {
if v, _ := obj.Get("constructor"); v.Object() != nil {
if v, _ = v.Object().Get("prototype"); v.Object() != nil {
return v.Object()
}
}
return nil
}
示例8: debugChain
func debugChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
glog.V(2).Infoln(val)
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return debugChain(val.Object())
}
return false
}
示例9: debugChain
func debugChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
if clog.V(2) {
clog.Infof("%v", val)
}
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return debugChain(val.Object())
}
return false
}
示例10: isVertexChain
func isVertexChain(obj *otto.Object) bool {
val, _ := obj.Get("_gremlin_type")
if val.String() == "vertex" {
return true
}
val, _ = obj.Get("_gremlin_prev")
if val.IsObject() {
return isVertexChain(val.Object())
}
return false
}
示例11: getStrings
func getStrings(obj *otto.Object, field string) []string {
strings := make([]string, 0)
val, _ := obj.Get(field)
if !val.IsUndefined() {
export, _ := val.Export()
array := export.([]interface{})
for _, arg := range array {
strings = append(strings, arg.(string))
}
}
return strings
}
示例12: setHeader
func setHeader(o *otto.Object, h *http.Header) {
header, _ := o.Get("header")
headerIface, _ := header.Export()
headerMap, ok := headerIface.(map[string]interface{})
if ok {
for k, v := range headerMap {
strV, ok := v.(string)
if ok {
h.Set(k, strV)
}
}
}
}
示例13: getFirstArgAsInt64
func getFirstArgAsInt64(obj *otto.Object) (int64, bool) {
arg, err := obj.Get("_gremlin_values")
if err != nil {
return 0, false
}
firstArg, err := arg.Object().Get("0")
if err != nil {
return 0, false
}
if !firstArg.IsNumber() {
return 0, false
}
v, err := firstArg.ToInteger()
return v, err == nil
}
示例14: stringsFrom
func stringsFrom(obj *otto.Object) []string {
var output []string
lengthValue, _ := obj.Get("length")
length, _ := lengthValue.ToInteger()
ulength := uint32(length)
for i := uint32(0); i < ulength; i++ {
name := strconv.FormatInt(int64(i), 10)
value, err := obj.Get(name)
if err != nil || !value.IsString() {
continue
}
output = append(output, value.String())
}
return output
}
示例15: isBigNumber
func (ctx ppctx) isBigNumber(v *otto.Object) bool {
// Handle numbers with custom constructor.
if v, _ := v.Get("constructor"); v.Object() != nil {
if strings.HasPrefix(toString(v.Object()), "function BigNumber") {
return true
}
}
// Handle default constructor.
BigNumber, _ := ctx.vm.Object("BigNumber.prototype")
if BigNumber == nil {
return false
}
bv, _ := BigNumber.Call("isPrototypeOf", v)
b, _ := bv.ToBoolean()
return b
}