Sirikata
Namespaces | Defines
liboh/plugins/js/JSObjectStructs/Util.hpp File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Sirikata
 

Note: All the classes provided in this file are thin wrappers around the corresponding classes in ASIO.


namespace  Sirikata::JS

Defines

#define CHECK_INTERNAL_FIELD_COUNT(obj, struct, shouldBeFieldCount, optionalReturn)
#define DEL_TYPEID_AND_CHECK(obj, struct, shouldBeTypeID, optionalReturn)

Define Documentation

#define CHECK_INTERNAL_FIELD_COUNT (   obj,
  struct,
  shouldBeFieldCount,
  optionalReturn 
)
Value:
{\
    if(obj->InternalFieldCount() != shouldBeFieldCount)\
    {\
        JSLOG(error, "Error when cleaning up " #struct ".  Has incorrect number of internal fields.");\
        return optionalReturn;                                          \
    }\
}
Parameters:
{v8::Handle<v8::Object>}obj The object whose internal type fields we're checking
{String}struct The struct we're checking the number of internal fields for.
{int}Number of internal fields that should be in object

Referenced by Sirikata::JS::JSTimerStruct::clear(), Sirikata::JS::JSTimerStruct::timerWeakReferenceCleanup(), and Sirikata::JS::JSVisibleStruct::visibleWeakReferenceCleanup().

#define DEL_TYPEID_AND_CHECK (   obj,
  struct,
  shouldBeTypeID,
  optionalReturn 
)
Value:
{                                                                   \
    v8::Local<v8::Value> typeidVal = obj->GetInternalField(TYPEID_FIELD);   \
    if (typeidVal.IsEmpty())                                            \
    {                                                                   \
        JSLOG(error, "Error when cleaning up " #struct ".  No value in type id."); \
        return optionalReturn;                                          \
    }                                                                   \
    if(typeidVal->IsNull() || typeidVal->IsUndefined())                 \
    {                                                                   \
        JSLOG(error, "Error when cleaning up " #struct ".  Null or undefined type id."); \
        return optionalReturn;                                          \
    }                                                                   \
                                                                        \
    v8::Local<v8::External> wrapped  = v8::Local<v8::External>::Cast(typeidVal);  \
    void* ptr = wrapped->Value();                                       \
    std::string* typeId = static_cast<std::string*>(ptr);               \
    if(typeId == NULL)                                                  \
    {                                                                   \
        JSLOG(detailed, "Potential error when cleaning up " #struct ".  Casting typeid to string produces null.");  \
        return optionalReturn;                                          \
    }                                                                   \
    if (*typeId != shouldBeTypeID)                                      \
    {                                                                   \
        JSLOG(error, "Error when cleaning up "#struct ".  Incorrect type id received: " + (*typeId)); \
        return optionalReturn;                                          \
    }                                                                   \
    delete typeId;                                                      \
    obj->SetInternalField(TYPEID_FIELD,v8::External::New(NULL));        \
}
Parameters:
{v8::Handle<v8::Object>}obj The object whose internal type fields we're checking
{String}struct The type of struct we're trying to delete the type id for
{constchar*} Character string that we want to match type to

Referenced by Sirikata::JS::JSTimerStruct::clear(), and Sirikata::JS::JSVisibleStruct::visibleWeakReferenceCleanup().