289b30715d
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.
104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
package otto
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"regexp"
|
|
"strconv"
|
|
"unicode/utf16"
|
|
)
|
|
|
|
var matchLeading0Exponent = regexp.MustCompile(`([eE][\+\-])0+([1-9])`) // 1e-07 => 1e-7
|
|
|
|
// FIXME
|
|
// https://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/conversions.cc?spec=svn18082&r=18082
|
|
func floatToString(value float64, bitsize int) string {
|
|
// TODO Fit to ECMA-262 9.8.1 specification
|
|
if math.IsNaN(value) {
|
|
return "NaN"
|
|
} else if math.IsInf(value, 0) {
|
|
if math.Signbit(value) {
|
|
return "-Infinity"
|
|
}
|
|
return "Infinity"
|
|
}
|
|
exponent := math.Log10(math.Abs(value))
|
|
if exponent >= 21 || exponent < -6 {
|
|
return matchLeading0Exponent.ReplaceAllString(strconv.FormatFloat(value, 'g', -1, bitsize), "$1$2")
|
|
}
|
|
return strconv.FormatFloat(value, 'f', -1, bitsize)
|
|
}
|
|
|
|
func numberToStringRadix(value Value, radix int) string {
|
|
float := value.float64()
|
|
if math.IsNaN(float) {
|
|
return "NaN"
|
|
} else if math.IsInf(float, 1) {
|
|
return "Infinity"
|
|
} else if math.IsInf(float, -1) {
|
|
return "-Infinity"
|
|
}
|
|
// FIXME This is very broken
|
|
// Need to do proper radix conversion for floats, ...
|
|
// This truncates large floats (so bad).
|
|
return strconv.FormatInt(int64(float), radix)
|
|
}
|
|
|
|
func (value Value) string() string {
|
|
if value.kind == valueString {
|
|
switch value := value.value.(type) {
|
|
case string:
|
|
return value
|
|
case []uint16:
|
|
return string(utf16.Decode(value))
|
|
}
|
|
}
|
|
if value.IsUndefined() {
|
|
return "undefined"
|
|
}
|
|
if value.IsNull() {
|
|
return "null"
|
|
}
|
|
switch value := value.value.(type) {
|
|
case bool:
|
|
return strconv.FormatBool(value)
|
|
case int:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int8:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int16:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int32:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int64:
|
|
return strconv.FormatInt(value, 10)
|
|
case uint:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint8:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint16:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint32:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(value, 10)
|
|
case float32:
|
|
if value == 0 {
|
|
return "0" // Take care not to return -0
|
|
}
|
|
return floatToString(float64(value), 32)
|
|
case float64:
|
|
if value == 0 {
|
|
return "0" // Take care not to return -0
|
|
}
|
|
return floatToString(value, 64)
|
|
case []uint16:
|
|
return string(utf16.Decode(value))
|
|
case string:
|
|
return value
|
|
case *_object:
|
|
return value.DefaultValue(defaultValueHintString).string()
|
|
}
|
|
panic(fmt.Errorf("%v.string( %T)", value.value, value.value))
|
|
}
|