Ejemplo n.º 1
0
Archivo: main.go Proyecto: 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)
	}
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
Archivo: otto.go Proyecto: 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
}