This source file includes following definitions.
- hasMethod
- invoke
- hasProperty
- getProperty
- NPP_GetValue
#include "PluginTest.h"
using namespace std;
class NPRuntimeObjectFromDestroyedPlugin : public PluginTest {
public:
NPRuntimeObjectFromDestroyedPlugin(NPP npp, const string& identifier)
: PluginTest(npp, identifier)
{
}
private:
class TestObject : public Object<TestObject> { };
class ScriptableObject : public Object<ScriptableObject> {
public:
bool hasMethod(NPIdentifier methodName)
{
return identifierIs(methodName, "evaluate");
}
bool invoke(NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (!identifierIs(methodName, "evaluate"))
return false;
if (argCount != 1 || !NPVARIANT_IS_STRING(args[0]))
return false;
return pluginTest()->executeScript(&NPVARIANT_TO_STRING(args[0]), result);
}
bool hasProperty(NPIdentifier propertyName)
{
return identifierIs(propertyName, "testObject");
}
bool getProperty(NPIdentifier propertyName, NPVariant* result)
{
if (propertyName != pluginTest()->NPN_GetStringIdentifier("testObject"))
return false;
NPObject* testObject = TestObject::create(pluginTest());
OBJECT_TO_NPVARIANT(testObject, *result);
return true;
}
};
virtual NPError NPP_GetValue(NPPVariable variable, void *value) OVERRIDE
{
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*(NPObject**)value = ScriptableObject::create(this);
return NPERR_NO_ERROR;
}
};
static PluginTest::Register<NPRuntimeObjectFromDestroyedPlugin> npRuntimeObjectFromDestroyedPlugin("npruntime-object-from-destroyed-plugin");