Properly root CopyStruct/CopyArray.
Properly root CopyStruct/CopyArray.
1.1 --- a/src/Interpreter.cpp Sun Sep 02 13:06:09 2012 -0700
1.2 +++ b/src/Interpreter.cpp Thu Sep 13 23:52:25 2012 -0700
1.3 @@ -81,20 +81,27 @@
1.4 return true;
1.5 }
1.6
1.7 -static bool CopyStruct(Zone *zone, Struct *left, Struct *right);
1.8 +static bool CopyStruct(Zone *zone, Handle<Struct> left, Handle<Struct> right);
1.9
1.10 // Even though this function can fail, we immediately bail out, so it doesn't
1.11 // matter if we've leaving things unrooted.
1.12 static bool
1.13 -CopyArray(Zone *zone, Array *source, Array *dest)
1.14 +CopyArray(Zone *zone, Handle<Array> source, Handle<Array> dest)
1.15 {
1.16 + if (source->length() != dest->length()) {
1.17 +// if (!ChangeArrayLength(zone, source, dest))
1.18 +// return false;
1.19 + }
1.20 +
1.21 if (source->type()->contained()->isArray()) {
1.22 assert(dest->type()->contained()->isArray());
1.23 assert(source->length() == dest->length());
1.24
1.25 + Local<Array> left(zone);
1.26 + Local<Array> right(zone);
1.27 for (unsigned i = 0; i < source->length(); i++) {
1.28 - Array *left = Array::cast(source->readObject(i));
1.29 - Array *right = Array::cast(dest->readObject(i));
1.30 + left = Array::cast(source->readObject(i));
1.31 + right = Array::cast(dest->readObject(i));
1.32 if (!CopyArray(zone, left, right))
1.33 return false;
1.34 }
1.35 @@ -102,9 +109,11 @@
1.36 assert(dest->type()->contained() == source->type()->contained());
1.37 assert(source->length() == dest->length());
1.38
1.39 + Local<Struct> left(zone);
1.40 + Local<Struct> right(zone);
1.41 for (unsigned i = 0; i < source->length(); i++) {
1.42 - Struct *left = Struct::cast(source->readObject(i));
1.43 - Struct *right = Struct::cast(dest->readObject(i));
1.44 + left = Struct::cast(source->readObject(i));
1.45 + right = Struct::cast(dest->readObject(i));
1.46 if (!CopyStruct(zone, left, right))
1.47 return false;
1.48 }
1.49 @@ -226,11 +235,15 @@
1.50 // Even though this function can fail, we immediately bail out, so it doesn't
1.51 // matter if we've leaving things unrooted.
1.52 static bool
1.53 -CopyStruct(Zone *zone, Struct *left, Struct *right)
1.54 +CopyStruct(Zone *zone, Handle<Struct> left, Handle<Struct> right)
1.55 {
1.56 assert(left->map()->type() == right->map()->type());
1.57
1.58 - Type *type = left->map()->type();
1.59 + Local<Type> type(zone, left->map()->type());
1.60 + Local<Struct> leftStruct(zone);
1.61 + Local<Struct> rightStruct(zone);
1.62 + Local<Array> leftArray(zone);
1.63 + Local<Array> rightArray(zone);
1.64 for (unsigned i = 0; i < type->fields()->length(); i++) {
1.65 Descriptor *desc = Descriptor::cast(type->fields()->at(i));
1.66
1.67 @@ -242,13 +255,17 @@
1.68 LocalSlot lval;
1.69
1.70 GetField(left, desc, &lval);
1.71 - if (!CopyStruct(zone, Struct::cast(lval.obj), Struct::cast(rval.obj)))
1.72 + leftStruct = Struct::cast(lval.obj);
1.73 + rightStruct = Struct::cast(rval.obj);
1.74 + if (!CopyStruct(zone, leftStruct, rightStruct))
1.75 return false;
1.76 } else if (desc->type()->isArray()) {
1.77 LocalSlot lval;
1.78
1.79 GetField(left, desc, &lval);
1.80 - if (!CopyArray(zone, Array::cast(lval.obj), Array::cast(rval.obj)))
1.81 + leftArray = Array::cast(lval.obj);
1.82 + rightArray = Array::cast(rval.obj);
1.83 + if (!CopyArray(zone, leftArray, rightArray))
1.84 return false;
1.85 } else {
1.86 SetField(zone, left, desc, rval);
1.87 @@ -904,7 +921,9 @@
1.88 {
1.89 // Note for this assignment opcode, we return the left-hand side, not the
1.90 // right, since in this case the result of the expression could be different.
1.91 - if (!CopyArray(zone, top.sp[-2].array, top.sp[-1].array))
1.92 + Local<Array> left(zone, Array::cast(top.sp[-2].array));
1.93 + Local<Array> right(zone, Array::cast(top.sp[-1].array));
1.94 + if (!CopyArray(zone, left, right))
1.95 goto error;
1.96 top.sp--;
1.97 break;
1.98 @@ -1075,7 +1094,9 @@
1.99
1.100 case OP_COPYSTRUCT:
1.101 {
1.102 - if (!CopyStruct(zone, Struct::cast(top.sp[-2].obj), Struct::cast(top.sp[-1].obj)))
1.103 + Local<Struct> left(zone, Struct::cast(top.sp[-2].obj));
1.104 + Local<Struct> right(zone, Struct::cast(top.sp[-1].obj));
1.105 + if (!CopyStruct(zone, left, right))
1.106 goto error;
1.107 top.sp[-2].obj = top.sp[-1].obj;
1.108 top.sp--;