protected:
void *operator new(size_t n)
{
+ /*
+ ** Assume that browser has a smarter memory allocator
+ ** than plain old malloc() and use it instead.
+ */
return NPN_MemAlloc(n);
};
void operator delete(void *p)
{
- /*
- ** Some memory scribble happens occasionally on freed object
- ** when used on Firefox (MacOS X) and may cause crash, a leak
- ** sounds like the better option.
- */
- //NPN_MemFree(p);
+ NPN_MemFree(p);
+ };
+
+ bool isValid()
+ {
+ return _instance != NULL;
};
RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance)
{
_class = const_cast<NPClass *>(aClass);
- //referenceCount = 1;
+ referenceCount = 1;
};
virtual ~RuntimeNPObject() {};
static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
- if( vObj->_instance )
+ if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
- if( vObj->_instance )
+ if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
static bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
- if( vObj->_instance )
+ if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
- if( vObj->_instance )
+ if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfMethod(name);
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
- if( vObj->_instance )
+ if( vObj->isValid() )
{
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
}