当前位置: 首页>>代码示例>>Golang>>正文


Golang Otto.Run方法代码示例

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


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

示例1: testUndefined

func testUndefined(vm *otto.Otto, src string) error {
	v, err := vm.Run(src)
	if err == nil && !v.IsUndefined() {
		err = fmt.Errorf("expected undefined, got %v", v)
	}
	return err
}
开发者ID:hattya,项目名称:aster,代码行数:7,代码来源:otto_test.go

示例2: compileAndRun

func compileAndRun(vm *otto.Otto, filename string, src interface{}) (otto.Value, error) {
	script, err := vm.Compile(filename, src)
	if err != nil {
		return otto.Value{}, err
	}
	return vm.Run(script)
}
开发者ID:ssonneborn22,项目名称:go-ethereum,代码行数:7,代码来源:jsre.go

示例3: cleanupDocumentFromEnvironment

// now we be sure to cleanup the environment as best we can
func cleanupDocumentFromEnvironment(o *otto.Otto, doc Document) {
	for k, _ := range doc {
		_, err := o.Run(k + "=undefined")
		if err != nil {
			log.Printf("Error running otto cleanup: %v", err)
		}
	}
}
开发者ID:mschoch,项目名称:tuq,代码行数:9,代码来源:otto_util.go

示例4: run

func run(vm *otto.Otto, filename string, code string) (otto.Value, error) {
	// Compile before running so that stacktraces have filenames.
	script, err := vm.Compile(filename, code)
	if err != nil {
		return otto.Value{}, err
	}

	return vm.Run(script)
}
开发者ID:NetSys,项目名称:quilt,代码行数:9,代码来源:stitch.go

示例5: evaluateExpressionInEnvironment

func evaluateExpressionInEnvironment(o *otto.Otto, expr parser.Expression) otto.Value {
	result, err := o.Run(fmt.Sprintf("ignore = %v", expr))
	if err != nil {
		log.Printf("Error running otto eval %v, %v", expr, err)
	} else {
		return result
	}
	return otto.UndefinedValue()
}
开发者ID:mschoch,项目名称:tuq,代码行数:9,代码来源:otto_util.go

示例6: testString

func testString(vm *otto.Otto, src string) (string, error) {
	v, err := vm.Run(src)
	if err == nil {
		if !v.IsString() {
			err = fmt.Errorf("expected String, got %v", v)
		} else {
			return v.ToString()
		}
	}
	return "", err
}
开发者ID:hattya,项目名称:aster,代码行数:11,代码来源:otto_test.go

示例7: Execute

// Execute runs the EvalTask's otto.Script in the vm provided, pushing the
// resultant return value and error (or nil) into the associated channels.
// If the execution results in an error, it will return that error.
func (e EvalTask) Execute(vm *otto.Otto, l *loop.Loop) error {
	v, err := vm.Run(e.Script)
	e.Value <- v
	e.Error <- err

	if e.SoftError {
		return nil
	}

	return err
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:14,代码来源:tasks.go

示例8: testBoolean

func testBoolean(vm *otto.Otto, src string) (bool, error) {
	v, err := vm.Run(src)
	if err == nil {
		if !v.IsBoolean() {
			err = fmt.Errorf("expected Boolean, got %v", v)
		} else {
			return v.ToBoolean()
		}
	}
	return false, err
}
开发者ID:hattya,项目名称:aster,代码行数:11,代码来源:otto_test.go

示例9: reverseGremlinChainTo

func reverseGremlinChainTo(env *otto.Otto, prevObj *otto.Object, tag string) (*otto.Object, *otto.Object) {
	env.Run("var _base_object = {}")
	base, err := env.Object("_base_object")
	if err != nil {
		glog.Error(err)
		return otto.NullValue().Object(), otto.NullValue().Object()
	}
	if isVertexChain(prevObj) {
		base.Set("_gremlin_type", "vertex")
	} else {
		base.Set("_gremlin_type", "morphism")
	}
	return reverseGremlinChainHelper(env, prevObj, base, tag)
}
开发者ID:JIVS,项目名称:cayley,代码行数:14,代码来源:gremlin-traversals.go

示例10: evaluateExpressionInEnvironmentAsInteger

func evaluateExpressionInEnvironmentAsInteger(o *otto.Otto, expr parser.Expression) int64 {
	result, err := o.Run(fmt.Sprintf("%v", expr))
	if err != nil {
		log.Printf("Error running otto %v", err)
	} else {
		result, err := result.ToInteger()
		if err != nil {
			log.Printf("Error converting otto result to integer %v", err)
		} else {
			return result
		}
	}
	return -1
}
开发者ID:mschoch,项目名称:tuq,代码行数:14,代码来源:otto_util.go

示例11: putDocumentIntoEnvironment

// serialize all the top level elements of doc to JSON and
// put them in the environment
// FIXME there has to be a better way than this
func putDocumentIntoEnvironment(o *otto.Otto, doc Document) {
	for k, v := range doc {
		v_json, err := json.Marshal(v)
		if err != nil {
			log.Printf("JSON serialization failed: %v", err)
		} else {
			_, err := o.Run(k + "=" + string(v_json))
			if err != nil {
				log.Printf("Error running otto put: %v", err)
			}
		}
	}

}
开发者ID:mschoch,项目名称:tuq,代码行数:17,代码来源:otto_util.go

示例12: evaluateExpressionStringInEnvironmentAsBoolean

func evaluateExpressionStringInEnvironmentAsBoolean(o *otto.Otto, expression string) bool {
	result, err := o.Run(expression)
	if err != nil {
		log.Printf("Error running otto %v, %v", expression, err)
	} else {
		//log.Printf("result was %v", result)
		result, err := result.ToBoolean()
		if err != nil {
			log.Printf("Error converting otto result to boolean %v", err)
		} else if result {
			return true
		}
	}
	return false
}
开发者ID:mschoch,项目名称:tuq,代码行数:15,代码来源:otto_util.go

示例13: parseContext

func parseContext(vm *otto.Otto) (stc Stitch, err error) {
	vmCtx, err := vm.Run("deployment.toQuiltRepresentation()")
	if err != nil {
		return stc, err
	}

	// Export() always returns `nil` as the error (it's only present for
	// backwards compatibility), so we can safely ignore it.
	exp, _ := vmCtx.Export()
	ctxStr, err := json.Marshal(exp)
	if err != nil {
		return stc, err
	}
	err = json.Unmarshal(ctxStr, &stc)
	return stc, err
}
开发者ID:NetSys,项目名称:quilt,代码行数:16,代码来源:stitch.go

示例14: createContext

func createContext(vm *otto.Otto, event chan otto.Value) otto.Value {
	var cbfunc = func(invar ...interface{}) {
		var lovar otto.Value
		if len(invar) > 0 {
			lovar, _ = vm.ToValue(invar[0])
		} else {
			lovar = otto.NullValue()
		}
		event <- lovar
		close(event)
	}
	vm.Set("_iopipe_cb", cbfunc)
	vm.Run(`_iopipe_context = { "done": _iopipe_cb,
                                    "success": _iopipe_cb,
                                    "fail": _iopipe_cb }`)
	jscontext, _ := vm.Get("_iopipe_context")
	return jscontext
}
开发者ID:ewindisch,项目名称:iopipe,代码行数:18,代码来源:filter.go

示例15: reverseGremlinChainHelper

func reverseGremlinChainHelper(env *otto.Otto, chain *otto.Object, newBase *otto.Object, tag string) (*otto.Object, *otto.Object) {
	kindVal, _ := chain.Get("_gremlin_type")
	kind, _ := kindVal.ToString()

	if tag != "" {
		if kind == "tag" {
			tags := getStringArgs(chain)
			for _, t := range tags {
				if t == tag {
					return newBase, chain
				}
			}
		}
	}

	if kind == "morphism" || kind == "vertex" {
		return newBase, chain
	}
	var newKind string
	switch kind {
	case "in":
		newKind = "out"
	case "out":
		newKind = "in"
	default:
		newKind = kind
	}
	prev, _ := chain.Get("_gremlin_prev")
	env.Run("var out = {}")
	out, _ := env.Object("out")
	out.Set("_gremlin_type", newKind)
	values, _ := chain.Get("_gremlin_values")
	out.Set("_gremlin_values", values)
	back, _ := chain.Get("_gremlin_back_chain")
	out.Set("_gremlin_back_chain", back)
	out.Set("_gremlin_prev", newBase)
	strings, _ := chain.Get("string_args")
	out.Set("string_args", strings)
	return reverseGremlinChainHelper(env, prev.Object(), out, tag)
}
开发者ID:JIVS,项目名称:cayley,代码行数:40,代码来源:gremlin-traversals.go


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