aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/robertkrimen/otto/type_go_struct.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-10-29 01:05:01 +0800
committerFelix Lange <fjl@twurst.com>2016-10-29 01:05:01 +0800
commit289b30715d097edafd5562f66cb3567a70b2d330 (patch)
tree7eaaa6da97c84727469303b986e364606ece57ce /vendor/github.com/robertkrimen/otto/type_go_struct.go
parent77703045765343c489ded2f43e3ed0f332c5f148 (diff)
downloaddexon-289b30715d097edafd5562f66cb3567a70b2d330.tar
dexon-289b30715d097edafd5562f66cb3567a70b2d330.tar.gz
dexon-289b30715d097edafd5562f66cb3567a70b2d330.tar.bz2
dexon-289b30715d097edafd5562f66cb3567a70b2d330.tar.lz
dexon-289b30715d097edafd5562f66cb3567a70b2d330.tar.xz
dexon-289b30715d097edafd5562f66cb3567a70b2d330.tar.zst
dexon-289b30715d097edafd5562f66cb3567a70b2d330.zip
Godeps, vendor: convert dependency management to trash (#3198)
This commit converts the dependency management from Godeps to the vendor folder, also switching the tool from godep to trash. Since the upstream tool lacks a few features proposed via a few PRs, until those PRs are merged in (if), use github.com/karalabe/trash. You can update dependencies via trash --update. All dependencies have been updated to their latest version. Parts of the build system are reworked to drop old notions of Godeps and invocation of the go vet command so that it doesn't run against the vendor folder, as that will just blow up during vetting. The conversion drops OpenCL (and hence GPU mining support) from ethash and our codebase. The short reasoning is that there's noone to maintain and having opencl libs in our deps messes up builds as go install ./... tries to build them, failing with unsatisfied link errors for the C OpenCL deps. golang.org/x/net/context is not vendored in. We expect it to be fetched by the user (i.e. using go get). To keep ci.go builds reproducible the package is "vendored" in build/_vendor.
Diffstat (limited to 'vendor/github.com/robertkrimen/otto/type_go_struct.go')
-rw-r--r--vendor/github.com/robertkrimen/otto/type_go_struct.go146
1 files changed, 146 insertions, 0 deletions
diff --git a/vendor/github.com/robertkrimen/otto/type_go_struct.go b/vendor/github.com/robertkrimen/otto/type_go_struct.go
new file mode 100644
index 000000000..608ac6660
--- /dev/null
+++ b/vendor/github.com/robertkrimen/otto/type_go_struct.go
@@ -0,0 +1,146 @@
+package otto
+
+import (
+ "encoding/json"
+ "reflect"
+)
+
+// FIXME Make a note about not being able to modify a struct unless it was
+// passed as a pointer-to: &struct{ ... }
+// This seems to be a limitation of the reflect package.
+// This goes for the other Go constructs too.
+// I guess we could get around it by either:
+// 1. Creating a new struct every time
+// 2. Creating an addressable? struct in the constructor
+
+func (runtime *_runtime) newGoStructObject(value reflect.Value) *_object {
+ self := runtime.newObject()
+ self.class = "Object" // TODO Should this be something else?
+ self.objectClass = _classGoStruct
+ self.value = _newGoStructObject(value)
+ return self
+}
+
+type _goStructObject struct {
+ value reflect.Value
+}
+
+func _newGoStructObject(value reflect.Value) *_goStructObject {
+ if reflect.Indirect(value).Kind() != reflect.Struct {
+ dbgf("%/panic//%@: %v != reflect.Struct", value.Kind())
+ }
+ self := &_goStructObject{
+ value: value,
+ }
+ return self
+}
+
+func (self _goStructObject) getValue(name string) reflect.Value {
+ if validGoStructName(name) {
+ // Do not reveal hidden or unexported fields
+ if field := reflect.Indirect(self.value).FieldByName(name); (field != reflect.Value{}) {
+ return field
+ }
+
+ if method := self.value.MethodByName(name); (method != reflect.Value{}) {
+ return method
+ }
+ }
+
+ return reflect.Value{}
+}
+
+func (self _goStructObject) field(name string) (reflect.StructField, bool) {
+ return reflect.Indirect(self.value).Type().FieldByName(name)
+}
+
+func (self _goStructObject) method(name string) (reflect.Method, bool) {
+ return reflect.Indirect(self.value).Type().MethodByName(name)
+}
+
+func (self _goStructObject) setValue(name string, value Value) bool {
+ field, exists := self.field(name)
+ if !exists {
+ return false
+ }
+ fieldValue := self.getValue(name)
+ reflectValue, err := value.toReflectValue(field.Type.Kind())
+ if err != nil {
+ panic(err)
+ }
+ fieldValue.Set(reflectValue)
+
+ return true
+}
+
+func goStructGetOwnProperty(self *_object, name string) *_property {
+ object := self.value.(*_goStructObject)
+ value := object.getValue(name)
+ if value.IsValid() {
+ return &_property{self.runtime.toValue(value.Interface()), 0110}
+ }
+
+ return objectGetOwnProperty(self, name)
+}
+
+func validGoStructName(name string) bool {
+ if name == "" {
+ return false
+ }
+ return 'A' <= name[0] && name[0] <= 'Z' // TODO What about Unicode?
+}
+
+func goStructEnumerate(self *_object, all bool, each func(string) bool) {
+ object := self.value.(*_goStructObject)
+
+ // Enumerate fields
+ for index := 0; index < reflect.Indirect(object.value).NumField(); index++ {
+ name := reflect.Indirect(object.value).Type().Field(index).Name
+ if validGoStructName(name) {
+ if !each(name) {
+ return
+ }
+ }
+ }
+
+ // Enumerate methods
+ for index := 0; index < object.value.NumMethod(); index++ {
+ name := object.value.Type().Method(index).Name
+ if validGoStructName(name) {
+ if !each(name) {
+ return
+ }
+ }
+ }
+
+ objectEnumerate(self, all, each)
+}
+
+func goStructCanPut(self *_object, name string) bool {
+ object := self.value.(*_goStructObject)
+ value := object.getValue(name)
+ if value.IsValid() {
+ return true
+ }
+
+ return objectCanPut(self, name)
+}
+
+func goStructPut(self *_object, name string, value Value, throw bool) {
+ object := self.value.(*_goStructObject)
+ if object.setValue(name, value) {
+ return
+ }
+
+ objectPut(self, name, value, throw)
+}
+
+func goStructMarshalJSON(self *_object) json.Marshaler {
+ object := self.value.(*_goStructObject)
+ goValue := reflect.Indirect(object.value).Interface()
+ switch marshaler := goValue.(type) {
+ case json.Marshaler:
+ return marshaler
+ }
+ return nil
+}