Exemple #1
0
//horrific way to do map(func)
func extractAllLetters(obj js.Object) js.Object {
	result := js.Global.Get("Array").New()
	for i := 0; i < obj.Length(); i++ {
		result.SetIndex(i, extractLetter(obj.Index(i)))
	}
	return result
}
Exemple #2
0
func wrapNodes(o *js.Object) []dom.Node {
	l := o.Length()
	toRet := make([]dom.Node, l)
	for i := 0; i < l; i++ {
		toRet[i] = dom.WrapNode(o.Index(i))
	}
	return toRet
}
Exemple #3
0
func getJSONTag(tag *js.Object) string {
	strLen := tag.Length()
	var val *js.Object
	for i := 0; i < strLen; i++ {
		start := i
		for i < strLen && tag.Call("charCodeAt", i).Int() == ' ' {
			i++
		}
		var char int
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char <= ' ' || char == ':' || char == '"' {
				break
			}
		}
		if i+1 >= strLen || char != ':' || tag.Call("charCodeAt", i+1).Int() != '"' {
			break
		}
		name := tag.Call("substring", start, i)
		i += 2
		start = i
		for ; i < strLen; i++ {
			char = tag.Call("charCodeAt", i).Int()
			if char == '\\' {
				i++
			} else if char == '"' {
				break
			}
		}
		if name.String() == "json" {
			val = tag.Call("substring", start, i)
			break
		}
	}
	if val == nil {
		return ""
	}
	return val.String()
}
Exemple #4
0
func isEmpty(v, t *js.Object) bool {
	switch t.Get("kind").Int() {
	case boolKind:
		return !v.Bool()
	case int8Kind, int16Kind, int32Kind, intKind, uint8Kind, uint16Kind, uint32Kind, uintKind:
		return v.Int() == 0
	case int64Kind, uint64Kind:
		return v.Int64() == 0
	case float32Kind, float64Kind:
		return v.Float() == 0
	case arrayKind, sliceKind, stringKind:
		return v.Length() == 0
	case ptrKind:
		return v == t.Get("nil")
	case interfaceKind:
		if v.Get("$val") == js.Undefined {
			return true
		}
		return isEmpty(v.Get("$val"), v.Get("constructor"))
	case mapKind:
		return js.Global.Get("Object").Call("keys", v).Length() == 0
	}
	return false
}
Exemple #5
0
func getFloats(obj *js.Object) (ret []float64) {
	if (obj == js.Undefined) || (obj == nil) || (obj.Length() == 0) {
		return nil
	}

	ret = make([]float64, 0, obj.Length())
	for i := 0; i < obj.Length(); i++ {
		ret = append(ret, obj.Index(i).Float())
	}

	return
}
Exemple #6
0
func dataLength(x *js.Object) int {
	return x.Length()
}