• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang otto.Object类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/robertkrimen/otto.Object的典型用法代码示例。如果您正苦于以下问题:Golang Object类的具体用法?Golang Object怎么用?Golang Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Object类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setFunc

// pipelines in javascript are chainable, you take in a pipeline, and you return a pipeline
// we just generalize some of that logic here
func (js *JavascriptBuilder) setFunc(obj *otto.Object, token string, fn func(string, Node, otto.FunctionCall) (Node, error)) error {
	return obj.Set(token, func(call otto.FunctionCall) otto.Value {
		this, _ := call.This.Export()

		node, err := CreateNode(this)
		if err != nil {
			js.err = err
			return otto.NullValue()
		}

		node, err = fn(token, node, call)
		if err != nil {
			js.err = err
			return otto.NullValue()
		}

		o, err := node.Object()
		if err != nil {
			js.err = err
			return otto.NullValue()
		}

		js.setFunc(o, "transform", js.transform)
		js.setFunc(o, "save", js.save)

		return o.Value()
	})
}
开发者ID:Garyguo110,项目名称:transporter,代码行数:30,代码来源:javascript_builder.go


示例2: getString

func getString(obj *otto.Object, name string) (string, error) {
	v, err := obj.Get(name)
	if err != nil {
		return "", err
	}
	return v.ToString()
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:7,代码来源:plugins.go


示例3: 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...)
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:26,代码来源:pretty.go


示例4: gremlinFollowR

func (wk *worker) gremlinFollowR(kind string, prev *otto.Object, env *otto.Otto) func(otto.FunctionCall) otto.Value {
	return func(call otto.FunctionCall) otto.Value {
		call.Otto.Run("var out = {}")
		out, _ := call.Otto.Object("out")
		out.Set("_gremlin_type", kind)
		out.Set("_gremlin_values", call.ArgumentList)
		args := argsOf(call)
		if len(args) > 0 {
			out.Set("string_args", args)
		}
		if len(call.ArgumentList) == 0 {
			return prev.Value()
		}
		arg := call.Argument(0)
		if isVertexChain(arg.Object()) {
			return prev.Value()
		}
		newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
		out.Set("_gremlin_prev", prev)
		out.Set("_gremlin_followr", newChain)
		wk.embedTraversals(env, out)
		if isVertexChain(call.This.Object()) {
			wk.embedFinals(env, out)
		}
		return out.Value()
	}
}
开发者ID:lytics,项目名称:cayley,代码行数:27,代码来源:traversals.go


示例5: 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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:26,代码来源:build_iterator.go


示例6: gremlinFollowR

func gremlinFollowR(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
	return func(call otto.FunctionCall) otto.Value {
		call.Otto.Run("var out = {}")
		out, _ := call.Otto.Object("out")
		out.Set("_gremlin_type", kind)
		out.Set("_gremlin_values", call.ArgumentList)
		outStrings := concatStringArgs(call)
		if len(*outStrings) > 0 {
			out.Set("string_args", *outStrings)
		}
		if len(call.ArgumentList) == 0 {
			return prevObj.Value()
		}
		arg := call.Argument(0)
		if isVertexChain(arg.Object()) {
			return prevObj.Value()
		}
		newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
		out.Set("_gremlin_prev", prevObj)
		out.Set("_gremlin_followr", newChain)
		embedTraversals(env, ses, out)
		if isVertexChain(call.This.Object()) {
			embedFinals(env, ses, out)
		}
		return out.Value()

	}
}
开发者ID:JIVS,项目名称:cayley,代码行数:28,代码来源:gremlin-traversals.go


示例7: getInt

func getInt(obj *otto.Object, name string) (int64, error) {
	v, err := obj.Get(name)
	if err != nil {
		return -1, err
	}
	return v.ToInteger()
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:7,代码来源:plugins.go


示例8: propertiesOf

func propertiesOf(obj *otto.Object, name string) []string {
	val, _ := obj.Get(name)
	if val.IsUndefined() {
		return nil
	}
	export, _ := val.Export()
	return export.([]string)
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:8,代码来源:build_iterator.go


示例9: 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()
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:8,代码来源:build_iterator.go


示例10: 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
}
开发者ID:Xiaoyang-Zhu,项目名称:go-ethereum,代码行数:8,代码来源:pretty.go


示例11: 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
}
开发者ID:dwdm,项目名称:clair,代码行数:9,代码来源:traversals.go


示例12: 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
}
开发者ID:lytics,项目名称:cayley,代码行数:11,代码来源:environ.go


示例13: 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
}
开发者ID:kortschak,项目名称:cayley,代码行数:11,代码来源:traversals.go


示例14: 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
}
开发者ID:karanja-simon,项目名称:cayley,代码行数:12,代码来源:build_iterator.go


示例15: ResponseWriterToJso

func ResponseWriterToJso(o *otto.Object, w http.ResponseWriter) {
	o.Set("write", func(c otto.FunctionCall) otto.Value {
		text, _ := c.Argument(0).ToString()
		w.Write([]byte(text))
		return otto.TrueValue()
	})
	o.Set("writeHeader", func(c otto.FunctionCall) otto.Value {
		statusCode, _ := c.Argument(0).ToInteger()
		w.WriteHeader(int(statusCode))
		return otto.TrueValue()
	})
}
开发者ID:BlackEspresso,项目名称:ServeJS,代码行数:12,代码来源:http.go


示例16: 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)
			}
		}
	}
}
开发者ID:BlackEspresso,项目名称:ServeJS,代码行数:14,代码来源:http.go


示例17: 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
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:15,代码来源:build_iterator.go


示例18: 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
}
开发者ID:kortschak,项目名称:cayley,代码行数:15,代码来源:build_iterator.go


示例19: JsoToResponseWriter

func JsoToResponseWriter(respObj *otto.Object, w http.ResponseWriter) {
	contentTypeV, err := respObj.Get("contentType")
	if err == nil {
		contentType, _ := contentTypeV.ToString()
		w.Header().Set("Content-Type", contentType)
	}

	wHeader := w.Header()
	setHeader(respObj, &wHeader)

	codeV, err := respObj.Get("statusCode")
	if err == nil && codeV.IsDefined() {
		code, _ := codeV.ToInteger()
		w.WriteHeader(int(code))
	}
}
开发者ID:BlackEspresso,项目名称:ServeJS,代码行数:16,代码来源:http.go


示例20: iterOwnKeys

func iterOwnKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
	Object, _ := vm.Object("Object")
	rv, _ := Object.Call("getOwnPropertyNames", obj.Value())
	gv, _ := rv.Export()
	switch gv := gv.(type) {
	case []interface{}:
		for _, v := range gv {
			f(v.(string))
		}
	case []string:
		for _, v := range gv {
			f(v)
		}
	default:
		panic(fmt.Errorf("Object.getOwnPropertyNames returned unexpected type %T", gv))
	}
}
开发者ID:Xiaoyang-Zhu,项目名称:go-ethereum,代码行数:17,代码来源:pretty.go



注:本文中的github.com/robertkrimen/otto.Object类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang otto.Otto类代码示例发布时间:2022-05-28
下一篇:
Golang otto.FunctionCall类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap