示例#1
0
文件: main.go 项目: timorl/otto
func main() {
	flag.Parse()

	if !*flag_underscore {
		underscore.Disable()
	}

	err := func() error {
		src, err := readSource(flag.Arg(0))
		if err != nil {
			return err
		}

		vm := otto.New()
		_, err = vm.Run(src)
		return err
	}()
	if err != nil {
		switch err := err.(type) {
		case *otto.Error:
			fmt.Print(err.String())
		default:
			fmt.Println(err)
		}
		os.Exit(64)
	}
}
示例#2
0
//NewEnvironment create new gohan extension environment based on context
func NewEnvironment(dataStore db.DB, identity middleware.IdentityService, timelimit time.Duration) *Environment {
	vm := otto.New()
	vm.Interrupt = make(chan func(), 1)
	env := &Environment{
		VM:        vm,
		DataStore: dataStore,
		Identity:  identity,
		timelimit: timelimit,
	}
	env.SetUp()
	return env
}
示例#3
0
文件: tester.go 项目: timorl/otto
func test(filename string) error {
	script, err := ioutil.ReadFile(filename)
	if err != nil {
		return err
	}

	if !*flag_report {
		fmt.Fprintln(os.Stdout, filename, len(script))
	}

	parse := false
	option := target[filename]

	if option != "parse" {
		vm := otto.New()
		_, err = vm.Run(string(script))
		if err != nil {
			value := err.Error()
			switch {
			case match_ReferenceError_not_defined.MatchString(value):
			case match_TypeError_undefined.MatchString(value):
			case match_lookahead.MatchString(value):
			case match_backreference.MatchString(value):
			default:
				return err
			}
			parse = true
		}
	}

	if parse {
		_, err = parser.ParseFile(nil, filename, string(script), parser.IgnoreRegExpErrors)
		if err != nil {
			return err
		}
		target[filename] = "parse"
	}

	return nil
}
示例#4
0
文件: otto.go 项目: nati/gohan
//NewEnvironment create new gohan extension environment based on context
func NewEnvironment(dataStore db.DB, identity middleware.IdentityService) *Environment {
	vm := otto.New()
	env := &Environment{VM: vm, DataStore: dataStore, Identity: identity}
	env.SetUp()
	return env
}