當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Value.IsNull方法代碼示例

本文整理匯總了Golang中github.com/robertkrimen/otto.Value.IsNull方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.IsNull方法的具體用法?Golang Value.IsNull怎麽用?Golang Value.IsNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/robertkrimen/otto.Value的用法示例。


在下文中一共展示了Value.IsNull方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: formatOneLine

func formatOneLine(v otto.Value, limit int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		switch v.Class() {
		case "Array":
			return formatArrayOneLine(v, limit, seen)
		default:
			return formatObjectOneLine(v, limit, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
開發者ID:deoxxa,項目名稱:ottoext,代碼行數:30,代碼來源:print.go

示例2: inspect

func inspect(v otto.Value, width, indent int) string {
	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsString(), v.IsUndefined(), v.IsNaN():
		return fmt.Sprintf("%s%q", strings.Repeat("  ", indent), v.String())
	default:
		return ""
	}
}
開發者ID:deoxxa,項目名稱:ottoext,代碼行數:8,代碼來源:repl.go

示例3: ottoValueToStringArray

// Converts a JS string or array into a Go string array.
func ottoValueToStringArray(value otto.Value) []string {
	nativeValue, _ := value.Export()

	result := base.ValueToStringArray(nativeValue)

	if result == nil && !value.IsNull() && !value.IsUndefined() {
		base.Warn("SyncRunner: Non-string, non-array passed to JS callback: %s", value)
	}

	return result
}
開發者ID:paulharter,項目名稱:sync_gateway,代碼行數:12,代碼來源:sync_runner.go

示例4: GetOrCreateTransaction

//GetOrCreateTransaction gets transaction from otto value or creates new is otto value is null
func (env *Environment) GetOrCreateTransaction(value otto.Value) (transaction.Transaction, bool, error) {
	if !value.IsNull() {
		tx, err := GetTransaction(value)
		return tx, false, err
	}
	dataStore := env.DataStore
	tx, err := dataStore.Begin()
	if err != nil {
		return nil, false, fmt.Errorf("Error creating transaction: %v", err.Error())
	}
	return tx, true, nil
}
開發者ID:cloudwan,項目名稱:gohan,代碼行數:13,代碼來源:otto.go

示例5: ottoToGo

// Converts an Otto value to a Go value. Handles all JSON-compatible types.
func ottoToGo(value otto.Value) (interface{}, error) {
	if value.IsBoolean() {
		return value.ToBoolean()
	} else if value.IsNull() || value.IsUndefined() {
		return nil, nil
	} else if value.IsNumber() {
		return value.ToFloat()
	} else if value.IsString() {
		return value.ToString()
	} else {
		switch value.Class() {
		case "Array":
			return ottoToGoArray(value.Object())
		}
	}
	return nil, fmt.Errorf("Unsupported Otto value: %v", value)
}
開發者ID:steveyen,項目名稱:walrus,代碼行數:18,代碼來源:js_map_fn.go

示例6: buildIteratorFromValue

func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
	if val.IsNull() || val.IsUndefined() {
		return ts.GetNodesAllIterator()
	}
	if val.IsPrimitive() {
		thing, _ := val.Export()
		switch v := thing.(type) {
		case string:
			it := ts.MakeFixed()
			it.AddValue(ts.GetIdFor(v))
			return it
		default:
			glog.Errorln("Trying to build unknown primitive value.")
		}
	}
	switch val.Class() {
	case "Object":
		return buildIteratorTree(val.Object(), ts)
	case "Array":
		// Had better be an array of strings
		strings := makeListOfStringsFromArrayValue(val.Object())
		it := ts.MakeFixed()
		for _, x := range strings {
			it.AddValue(ts.GetIdFor(x))
		}
		return it
	case "Number":
		fallthrough
	case "Boolean":
		fallthrough
	case "Date":
		fallthrough
	case "String":
		it := ts.MakeFixed()
		str, _ := val.ToString()
		it.AddValue(ts.GetIdFor(str))
		return it
	default:
		glog.Errorln("Trying to handle unsupported Javascript value.")
		return graph.NewNullIterator()
	}
}
開發者ID:karanja-simon,項目名稱:cayley,代碼行數:42,代碼來源:build_iterator.go

示例7: buildIteratorFromValue

func buildIteratorFromValue(val otto.Value, qs graph.QuadStore) graph.Iterator {
	if val.IsNull() || val.IsUndefined() {
		return qs.NodesAllIterator()
	}
	if val.IsPrimitive() {
		thing, _ := val.Export()
		switch v := thing.(type) {
		case string:
			it := qs.FixedIterator()
			it.Add(qs.ValueOf(v))
			return it
		default:
			glog.Errorln("Trying to build unknown primitive value.")
		}
	}
	switch val.Class() {
	case "Object":
		return buildIteratorTree(val.Object(), qs)
	case "Array":
		// Had better be an array of strings
		strings := stringsFrom(val.Object())
		it := qs.FixedIterator()
		for _, x := range strings {
			it.Add(qs.ValueOf(x))
		}
		return it
	case "Number":
		fallthrough
	case "Boolean":
		fallthrough
	case "Date":
		fallthrough
	case "String":
		it := qs.FixedIterator()
		it.Add(qs.ValueOf(val.String()))
		return it
	default:
		glog.Errorln("Trying to handle unsupported Javascript value.")
		return iterator.NewNull()
	}
}
開發者ID:ericcapricorn,項目名稱:cayley,代碼行數:41,代碼來源:build_iterator.go

示例8: ottoValueToStringArray

// Converts a JS string or array into a Go string array.
func ottoValueToStringArray(value otto.Value) []string {
	nativeValue, _ := value.Export()
	switch nativeValue := nativeValue.(type) {
	case string:
		return []string{nativeValue}
	case []string:
		return nativeValue
	case []interface{}:
		result := make([]string, 0, len(nativeValue))
		for _, item := range nativeValue {
			if str, ok := item.(string); ok {
				result = append(result, str)
			}
		}
		return result
	default:
		if !value.IsNull() && !value.IsUndefined() {
			base.Warn("SyncRunner: Non-string, non-array passed to JS callback: %s", value)
		}
		return nil
	}
}
開發者ID:joscas,項目名稱:sync_gateway,代碼行數:23,代碼來源:sync_runner.go

示例9: buildPathFromValue

func buildPathFromValue(val otto.Value) (out []interface{}) {
	if val.IsNull() || val.IsUndefined() {
		return nil
	}
	if val.IsPrimitive() {
		thing, _ := val.Export()
		switch v := thing.(type) {
		case string:
			out = append(out, v)
			return
		default:
			clog.Errorf("Trying to build unknown primitive value.")
		}
	}
	switch val.Class() {
	case "Object":
		out = append(out, buildPathFromObject(val.Object()))
		return
	case "Array":
		// Had better be an array of strings
		for _, x := range stringsFrom(val.Object()) {
			out = append(out, x)
		}
		return
	case "Number":
		fallthrough
	case "Boolean":
		fallthrough
	case "Date":
		fallthrough
	case "String":
		out = append(out, val.String())
		return
	default:
		clog.Errorf("Trying to handle unsupported Javascript value.")
		return nil
	}
}
開發者ID:RamboWANG,項目名稱:cayley,代碼行數:38,代碼來源:build_iterator.go

示例10: printValue

func (ctx ppctx) printValue(v otto.Value, level int, inArray bool) {
	switch {
	case v.IsObject():
		ctx.printObject(v.Object(), level, inArray)
	case v.IsNull():
		specialColor.Print("null")
	case v.IsUndefined():
		specialColor.Print("undefined")
	case v.IsString():
		s, _ := v.ToString()
		stringColor.Printf("%q", s)
	case v.IsBoolean():
		b, _ := v.ToBoolean()
		specialColor.Printf("%t", b)
	case v.IsNaN():
		numberColor.Printf("NaN")
	case v.IsNumber():
		s, _ := v.ToString()
		numberColor.Printf("%s", s)
	default:
		fmt.Printf("<unprintable>")
	}
}
開發者ID:Xiaoyang-Zhu,項目名稱:go-ethereum,代碼行數:23,代碼來源:pretty.go

示例11: formatIndent

func formatIndent(v otto.Value, width, indent, limit, level, additional int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		if d, err := formatOneLine(v, limit, seen); err != nil {
			return "", err
		} else if level*indent+additional+len(d) <= width {
			return d, nil
		}

		switch v.Class() {
		case "Array":
			return formatArray(v, width, indent, limit, level, seen)
		default:
			return formatObject(v, width, indent, limit, level, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
開發者ID:deoxxa,項目名稱:ottoext,代碼行數:36,代碼來源:print.go


注:本文中的github.com/robertkrimen/otto.Value.IsNull方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。