Skip to content

Commit

Permalink
bugfix in CheckSEXPForJSRef and CheckForRefClass
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbecker committed Feb 2, 2013
1 parent a8d9683 commit c8a17d7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 0 additions & 2 deletions R/NPAPI.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
setClass("NPObjectRef", contains="RCStructReference")
setClass("NPVariantRef", contains="RCStructReference")

NP_Invoke = function(...,
plug = PluginInstance,
Expand Down
5 changes: 5 additions & 0 deletions R/classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ setClass("JSValueRef", contains = "RCReference")
setClass("NPNFunctionsRef", contains = "RCStructReference")
setClass("PluginInstance", representation=representation(funcs = "NPNFunctionsRef"), contains="RCStructReference")

setClass("NPObjectRef", contains="RCStructReference")
setClass("NPVariantRef", contains="RCStructReference")

setIs("NPVariantRef", "JSValueRef")

if(FALSE)
{
setClass("NPObjectRef", contains = "RCStructReference")
Expand Down
14 changes: 10 additions & 4 deletions inst/NPAPI/NPConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ bool ConvertRToNP(SEXP val, NPP inst, NPNetscapeFuncs *funcs, NPVariant *ret, co

//If it is a promise we need the actual value.
int err = 0;
int numprot = 0;
if(TYPEOF(val) == PROMSXP)
val = rQueue.requestRCall(val, R_GlobalEnv, &err, inst);
{
PROTECT(val = rQueue.requestRCall(val, R_GlobalEnv, &err, inst));
numprot = 1;
}
//Is it already a reference to an existing NP/JS object? If so just return that object!
if (CheckSEXPForJSRef(val, inst))
{
Expand Down Expand Up @@ -51,6 +55,8 @@ bool ConvertRToNP(SEXP val, NPP inst, NPNetscapeFuncs *funcs, NPVariant *ret, co
MakeRRefForNP(val, inst, funcs, ret);
break;
}
if(numprot)
UNPROTECT(1);
return true;
}

Expand Down Expand Up @@ -691,15 +697,15 @@ bool CheckSEXPForJSRef(SEXP obj, NPP inst)
ptr = CDR(ptr);
SETCAR(ptr, obj);
ptr = CDR(ptr);
// SETCAR(ptr, ScalarString(mkChar("JSValueRef")));
SETCAR(ptr, ScalarString(mkChar("JSValueRef")));

PROTECT(ans = rQueue.requestRCall(call, R_GlobalEnv, &err, inst));
bool ret;
if (ans == R_UnboundValue || ans == R_NilValue)
if (ans == R_UnboundValue || ans == R_NilValue || err)
ret = 0;
else
{

ret = LOGICAL(ans)[0];
if(ret)
{fprintf(stderr, "\nR object contains JS reference.\n");fflush(stderr);}
Expand All @@ -724,7 +730,7 @@ bool checkForRefClass(SEXP obj)
PROTECT(ans = R_tryEval(call, R_GlobalEnv, &err));
if(err || !LOGICAL(ans)[0])
ret = false;

UNPROTECT(2);
return ret;
}

Expand Down
26 changes: 19 additions & 7 deletions src/NPConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ bool ConvertRToNP(SEXP val, NPP inst, NPNetscapeFuncs *funcs, NPVariant *ret, co

//If it is a promise we need the actual value.
int err = 0;
int numprot = 0;
if(TYPEOF(val) == PROMSXP)
val = R_tryEval(val, R_GlobalEnv, &err);
{
PROTECT(val = R_tryEval(val, R_GlobalEnv, &err));
numprot = 1;
}
//Is it already a reference to an existing NP/JS object? If so just return that object!
if (CheckSEXPForJSRef(val, inst))
{
Expand Down Expand Up @@ -46,6 +50,8 @@ bool ConvertRToNP(SEXP val, NPP inst, NPNetscapeFuncs *funcs, NPVariant *ret, co
MakeRRefForNP(val, inst, funcs, ret);
break;
}
if(numprot)
UNPROTECT(1);
return true;
}

Expand Down Expand Up @@ -584,18 +590,24 @@ bool CheckSEXPForJSRef(SEXP obj, NPP inst)
{

SEXP ans, call, ptr;
int err;
int err = 0;
PROTECT(ptr = call= allocVector(LANGSXP, 3));
SETCAR(ptr, Rf_install("is"));
ptr = CDR(ptr);
SETCAR(ptr, obj);
ptr = CDR(ptr);
SETCAR(ptr, ScalarString(mkChar("JSValueRef")));

PROTECT(ans = R_tryEval(call, R_GlobalEnv, &err));
bool ret = LOGICAL(ans)[0];
if(ret)
{fprintf(stderr, "\nR object contains JS reference.\n");fflush(stderr);}

bool ret;
if (ans == R_UnboundValue || ans == R_NilValue || err)
ret = 0;
else
{
ret = LOGICAL(ans)[0];
if(ret)
{fprintf(stderr, "\nR object contains JS reference.\n");fflush(stderr);}
}
UNPROTECT(2);
return ret;

Expand All @@ -616,6 +628,6 @@ bool checkForRefClass(SEXP obj)
PROTECT(ans = R_tryEval(call, R_GlobalEnv, &err));
if(err || !LOGICAL(ans)[0])
ret = false;

UNPROTECT(2);
return ret;
}

0 comments on commit c8a17d7

Please sign in to comment.