Skip to content

Commit

Permalink
toU16/U32/I32 => toUint16/Uint32/Int32
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkrimen committed Feb 18, 2013
1 parent e4583ba commit bdaa008
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
30 changes: 15 additions & 15 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func builtinGlobal_parseInt(call FunctionCall) Value {
radix := call.Argument(1)
radixValue := 0
if radix.IsDefined() {
radixValue = int(toI32(radix))
radixValue = int(toInt32(radix))
}
value, err := strconv.ParseInt(string_, radixValue, 64)
if err != nil {
Expand Down Expand Up @@ -241,7 +241,7 @@ func builtinFunction_apply(call FunctionCall) Value {

arrayObject := argumentList._object()
thisObject := call.thisObject()
length := uint(toUI32(arrayObject.get("length")))
length := uint(toUint32(arrayObject.get("length")))
valueArray := make([]Value, length)
for index := uint(0); index < length; index++ {
valueArray[index] = arrayObject.get(arrayIndexToString(index))
Expand Down Expand Up @@ -295,7 +295,7 @@ func builtinNewString(self *_object, _ Value, argumentList []Value) Value {
func builtinString_fromCharCode(call FunctionCall) Value {
chrList := make([]uint16, len(call.ArgumentList))
for index, value := range call.ArgumentList {
chrList[index] = toUI16(value)
chrList[index] = toUint16(value)
}
return toValue(string(utf16.Decode(chrList)))
}
Expand Down Expand Up @@ -555,7 +555,7 @@ func builtinString_split(call FunctionCall) Value {
limitValue := call.Argument(1)
limit := -1
if limitValue.IsDefined() {
limit = int(toUI32(limitValue))
limit = int(toUint32(limitValue))
}

if limit == 0 {
Expand Down Expand Up @@ -741,7 +741,7 @@ func builtinNewArrayNative(runtime *_runtime, argumentList []Value) *_object {
if len(argumentList) == 1 {
value := argumentList[0]
if value.IsNumber() {
numberValue := uint(toUI32(value))
numberValue := uint(toUint32(value))
if float64(numberValue) == toFloat(value) {
valueArray = make([]Value, numberValue)
} else {
Expand Down Expand Up @@ -782,7 +782,7 @@ func builtinArray_concat(call FunctionCall) Value {

func builtinArray_shift(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
if 0 == length {
thisObject.put("length", toValue(length), true)
return UndefinedValue()
Expand All @@ -805,7 +805,7 @@ func builtinArray_shift(call FunctionCall) Value {
func builtinArray_push(call FunctionCall) Value {
thisObject := call.thisObject()
itemList := call.ArgumentList
index := uint(toUI32(thisObject.get("length")))
index := uint(toUint32(thisObject.get("length")))
for len(itemList) > 0 {
thisObject.put(arrayIndexToString(index), itemList[0], true)
itemList = itemList[1:]
Expand All @@ -818,7 +818,7 @@ func builtinArray_push(call FunctionCall) Value {

func builtinArray_pop(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
if 0 == length {
thisObject.put("length", toValue(length), true)
return UndefinedValue()
Expand All @@ -842,7 +842,7 @@ func builtinArray_join(call FunctionCall) Value {
return toValue(builtinArray_joinNative(stash.valueArray, separator))
}
// Generic .join
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
if length == 0 {
return toValue("")
}
Expand Down Expand Up @@ -917,7 +917,7 @@ func rangeStartLength(source []Value, size uint) (start, length int64) {

func builtinArray_splice(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))

start := valueToArrayIndex(call.Argument(0), length, false)
deleteCount := valueToArrayIndex(call.Argument(1), length-start, true)
Expand Down Expand Up @@ -994,7 +994,7 @@ func builtinArray_splice(call FunctionCall) Value {
func builtinArray_slice(call FunctionCall) Value {
thisObject := call.thisObject()

length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
start, end := rangeStartEnd(call.ArgumentList, length, false)

if start >= end {
Expand All @@ -1021,7 +1021,7 @@ func builtinArray_slice(call FunctionCall) Value {

func builtinArray_unshift(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
itemList := call.ArgumentList
itemCount := uint(len(itemList))

Expand All @@ -1046,7 +1046,7 @@ func builtinArray_unshift(call FunctionCall) Value {

func builtinArray_reverse(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))

lower := struct {
name string
Expand Down Expand Up @@ -1136,7 +1136,7 @@ func sortCompare(thisObject *_object, index0, index1 uint, compare *_object) int
return 1
}

return int(toI32(compare.Call(UndefinedValue(), []Value{x, y})))
return int(toInt32(compare.Call(UndefinedValue(), []Value{x, y})))
}

func arraySortSwap(thisObject *_object, index0, index1 uint) {
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func arraySortQuickSort(thisObject *_object, left, right uint, compare *_object)

func builtinArray_sort(call FunctionCall) Value {
thisObject := call.thisObject()
length := uint(toUI32(thisObject.get("length")))
length := uint(toUint32(thisObject.get("length")))
compareValue := call.Argument(0)
compare := compareValue._object()
if compareValue.IsUndefined() {
Expand Down
14 changes: 7 additions & 7 deletions evaluate_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (self *_runtime) evaluateUnaryOperation(node *_unaryOperationNode) Value {
}
return TrueValue()
case "~":
integerValue := toI32(targetValue)
integerValue := toInt32(targetValue)
return toValue(^integerValue)
case "+":
return toValue(targetValue.toFloat())
Expand Down Expand Up @@ -226,26 +226,26 @@ func (self *_runtime) calculateBinaryOperation(operator string, left Value, righ
// Bitwise
case "&":
rightValue := self.GetValue(right)
return toValue(toI32(leftValue) & toI32(rightValue))
return toValue(toInt32(leftValue) & toInt32(rightValue))
case "|":
rightValue := self.GetValue(right)
return toValue(toI32(leftValue) | toI32(rightValue))
return toValue(toInt32(leftValue) | toInt32(rightValue))
case "^":
rightValue := self.GetValue(right)
return toValue(toI32(leftValue) ^ toI32(rightValue))
return toValue(toInt32(leftValue) ^ toInt32(rightValue))

// Shift
// (Masking of 0x1f is to restrict the shift to a maximum of 31 places)
case "<<":
rightValue := self.GetValue(right)
return toValue(toI32(leftValue) << (toUI32(rightValue) & 0x1f))
return toValue(toInt32(leftValue) << (toUint32(rightValue) & 0x1f))
case ">>":
rightValue := self.GetValue(right)
return toValue(toI32(leftValue) >> (toUI32(rightValue) & 0x1f))
return toValue(toInt32(leftValue) >> (toUint32(rightValue) & 0x1f))
case ">>>":
rightValue := self.GetValue(right)
// Shifting an unsigned integer is a logical shift
return toValue(toUI32(leftValue) >> (toUI32(rightValue) & 0x1f))
return toValue(toUint32(leftValue) >> (toUint32(rightValue) & 0x1f))

case "instanceof":
rightValue := self.GetValue(right)
Expand Down
2 changes: 1 addition & 1 deletion type_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (self *_arrayStash) canPut(name string) bool {
func (self *_arrayStash) put(name string, value Value) {
// length
if name == "length" {
value := uint(toUI32(value))
value := uint(toUint32(value))
length := uint(len(self.valueArray))
if value > length {
valueArray := make([]Value, value)
Expand Down
6 changes: 3 additions & 3 deletions value_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func toInteger(value Value) int64 {
}

// ECMA 262: 9.5
func toI32(value Value) int32 {
func toInt32(value Value) int32 {
{
switch value := value.value.(type) {
case int8:
Expand Down Expand Up @@ -212,7 +212,7 @@ func toI32(value Value) int32 {
return int32(remainder)
}

func toUI32(value Value) uint32 {
func toUint32(value Value) uint32 {
{
switch value := value.value.(type) {
case int8:
Expand Down Expand Up @@ -243,7 +243,7 @@ func toUI32(value Value) uint32 {
return uint32(remainder)
}

func toUI16(value Value) uint16 {
func toUint16(value Value) uint16 {
{
switch value := value.value.(type) {
case int8:
Expand Down
16 changes: 8 additions & 8 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ func TestToString(t *testing.T) {
Is(toValue(false), "false")
}

func TestToI32(t *testing.T) {
func Test_toInt32(t *testing.T) {
Terst(t)

Is(toI32(toValue(0)), "0")
Is(toI32(toValue(1)), "1")
Is(toI32(toValue(-2147483649.0)), "2147483647")
Is(toI32(toValue(-4294967297.0)), "-1")
Is(toI32(toValue(-4294967296.0)), "0")
Is(toI32(toValue(-4294967295.0)), "1")
Is(toInt32(toValue(0)), "0")
Is(toInt32(toValue(1)), "1")
Is(toInt32(toValue(-2147483649.0)), "2147483647")
Is(toInt32(toValue(-4294967297.0)), "-1")
Is(toInt32(toValue(-4294967296.0)), "0")
Is(toInt32(toValue(-4294967295.0)), "1")
}

func TestsameValue(t *testing.T) {
func Test_sameValue(t *testing.T) {
Terst(t)

IsFalse(sameValue(positiveZeroValue(), negativeZeroValue()))
Expand Down

0 comments on commit bdaa008

Please sign in to comment.