Allow more empty array creation.
authorDavid Anderson <dvander@alliedmods.net>
Sat Sep 15 19:33:24 2012 -0700 (2012-09-15)
changeset 18603a663e96860
parent 185 10936f3a2ba3
child 187 9308d52205a0
Allow more empty array creation.
src/Array.cpp
src/Interpreter.cpp
src/Types.cpp
src/Types.h
     1.1 --- a/src/Array.cpp	Sat Sep 15 18:25:54 2012 -0700
     1.2 +++ b/src/Array.cpp	Sat Sep 15 19:33:24 2012 -0700
     1.3 @@ -95,7 +95,10 @@
     1.4          Local<ArrayMap> childMap(zone, ArrayMap::cast(map->type()->contained()->newMap()));
     1.5          Local<Array> child(zone);
     1.6          for (unsigned i = 0; i < elements; i++) {
     1.7 -            child = Array::New(zone, childMap, map->type()->contained()->declaredLength(), tenure);
     1.8 +            unsigned length = map->type()->contained()->isFixedLength()
     1.9 +                              ? map->type()->contained()->fixedLength()
    1.10 +                              : 0;
    1.11 +            child = Array::New(zone, childMap, length, tenure);
    1.12              if (!child)
    1.13                  return NULL;
    1.14  
     2.1 --- a/src/Interpreter.cpp	Sat Sep 15 18:25:54 2012 -0700
     2.2 +++ b/src/Interpreter.cpp	Sat Sep 15 19:33:24 2012 -0700
     2.3 @@ -875,7 +875,14 @@
     2.4  case OP_ARRAYREF_LIFO:
     2.5  {
     2.6      Local<Array> array(zone, Array::cast(top.sp[-2].obj));
     2.7 -    Local<Reference> ref(zone, Reference::NewArray(zone, array, top.sp[-1].i32, Heap::Tenure_Stack));
     2.8 +
     2.9 +    int index = top.sp[-1].i32;
    2.10 +    if (index < 0 || unsigned(index) >= array->length()) {
    2.11 +        zone->reportError(Message_ArrayIndexOutOfBounds, index, array->length());
    2.12 +        goto error;
    2.13 +    }
    2.14 +
    2.15 +    Local<Reference> ref(zone, Reference::NewArray(zone, array, index, Heap::Tenure_Stack));
    2.16      if (!ref)
    2.17          goto error;
    2.18      top.sp[-2].ref = ref;
     3.1 --- a/src/Types.cpp	Sat Sep 15 18:25:54 2012 -0700
     3.2 +++ b/src/Types.cpp	Sat Sep 15 19:33:24 2012 -0700
     3.3 @@ -214,7 +214,7 @@
     3.4        {
     3.5          if (left->levels() != right->levels())
     3.6            return false;
     3.7 -        if (left->declaredLength() != right->declaredLength())
     3.8 +        if (left->elements_ != right->elements_)
     3.9              return false;
    3.10          return Compare(left->contained(), right->contained());
    3.11        }
     4.1 --- a/src/Types.h	Sat Sep 15 18:25:54 2012 -0700
     4.2 +++ b/src/Types.h	Sat Sep 15 19:33:24 2012 -0700
     4.3 @@ -170,10 +170,6 @@
     4.4          assert(isArray());
     4.5          return elements_ > 0;
     4.6      }
     4.7 -    int declaredLength() {
     4.8 -        assert(isArray());
     4.9 -        return elements_;
    4.10 -    }
    4.11      unsigned fixedLength() {
    4.12          assert(isFixedLength());
    4.13          return elements_;