Sirikata
|
00001 00002 #ifndef __OBJECT_STRUCT_UTIL_HPP__ 00003 #define __OBJECT_STRUCT_UTIL_HPP__ 00004 00005 namespace Sirikata{ 00006 namespace JS{ 00007 00008 00015 #define CHECK_INTERNAL_FIELD_COUNT(obj,struct,shouldBeFieldCount,optionalReturn) \ 00016 {\ 00017 if(obj->InternalFieldCount() != shouldBeFieldCount)\ 00018 {\ 00019 JSLOG(error, "Error when cleaning up " #struct ". Has incorrect number of internal fields.");\ 00020 return optionalReturn; \ 00021 }\ 00022 } 00023 00024 00031 #define DEL_TYPEID_AND_CHECK(obj,struct,shouldBeTypeID,optionalReturn) \ 00032 { \ 00033 v8::Local<v8::Value> typeidVal = obj->GetInternalField(TYPEID_FIELD); \ 00034 if (typeidVal.IsEmpty()) \ 00035 { \ 00036 JSLOG(error, "Error when cleaning up " #struct ". No value in type id."); \ 00037 return optionalReturn; \ 00038 } \ 00039 if(typeidVal->IsNull() || typeidVal->IsUndefined()) \ 00040 { \ 00041 JSLOG(error, "Error when cleaning up " #struct ". Null or undefined type id."); \ 00042 return optionalReturn; \ 00043 } \ 00044 \ 00045 v8::Local<v8::External> wrapped = v8::Local<v8::External>::Cast(typeidVal); \ 00046 void* ptr = wrapped->Value(); \ 00047 std::string* typeId = static_cast<std::string*>(ptr); \ 00048 if(typeId == NULL) \ 00049 { \ 00050 JSLOG(detailed, "Potential error when cleaning up " #struct ". Casting typeid to string produces null."); \ 00051 return optionalReturn; \ 00052 } \ 00053 if (*typeId != shouldBeTypeID) \ 00054 { \ 00055 JSLOG(error, "Error when cleaning up "#struct ". Incorrect type id received: " + (*typeId)); \ 00056 return optionalReturn; \ 00057 } \ 00058 delete typeId; \ 00059 obj->SetInternalField(TYPEID_FIELD,v8::External::New(NULL)); \ 00060 } 00061 00062 00063 }//close namespace js 00064 }//close namespace sirikata 00065 00066 #endif