Skip to content

Commit

Permalink
check call has enough arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
juliandolby committed Jun 22, 2016
1 parent 76286a3 commit aeac2a6
Showing 1 changed file with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,46 @@ public class LoadFileTargetSelector implements MethodTargetSelector {
public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) {
IMethod target = base.getCalleeTarget(caller, site, receiver);
if (target != null && target.getReference().equals(loadFileFunRef)) {

Set<String> names = new HashSet<String>();
SSAInstruction call = caller.getIR().getInstructions()[caller.getIR().getCallInstructionIndices(site).intIterator().next()];
LocalPointerKey fileNameV = new LocalPointerKey(caller, call.getUse(1));
OrdinalSet<InstanceKey> ptrs = builder.getPointerAnalysis().getPointsToSet(fileNameV);
for(InstanceKey k : ptrs) {
if (k instanceof ConstantKey) {
Object v = ((ConstantKey)k).getValue();
if (v instanceof String) {
names.add((String)v);
if (call.getNumberOfUses() > 1) {
LocalPointerKey fileNameV = new LocalPointerKey(caller, call.getUse(1));
OrdinalSet<InstanceKey> ptrs = builder.getPointerAnalysis().getPointsToSet(fileNameV);
for(InstanceKey k : ptrs) {
if (k instanceof ConstantKey) {
Object v = ((ConstantKey)k).getValue();
if (v instanceof String) {
names.add((String)v);
}
}
}
}

if (names.size() == 1) {
String str = names.iterator().next();
try {
JavaScriptLoader cl = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader);
URL url = new URL(builder.getBaseURL(), str);
if(!loadedFiles.contains(url)) {
// try to open the input stream for the URL. if it fails, we'll get an IOException and fall through to default case
InputStream inputStream = url.openConnection().getInputStream();
inputStream.close();
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy() , cl, str, url);
loadedFiles.add(url);
IClass script = builder.getClassHierarchy().lookupClass(TypeReference.findOrCreate(cl.getReference(), "L" + url.getFile()));
return script.getMethod(JavaScriptMethods.fnSelector);

if (names.size() == 1) {
String str = names.iterator().next();
try {
JavaScriptLoader cl = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader);
URL url = new URL(builder.getBaseURL(), str);
if(!loadedFiles.contains(url)) {
// try to open the input stream for the URL. if it fails, we'll get an IOException and fall through to default case
InputStream inputStream = url.openConnection().getInputStream();
inputStream.close();
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy() , cl, str, url);
loadedFiles.add(url);
IClass script = builder.getClassHierarchy().lookupClass(TypeReference.findOrCreate(cl.getReference(), "L" + url.getFile()));
return script.getMethod(JavaScriptMethods.fnSelector);
}
} catch (MalformedURLException e1) {
// do nothing, fall through and return 'target'
} catch (IOException e) {
// do nothing, fall through and return 'target'
} catch (RuntimeException e) {
// do nothing, fall through and return 'target'
}
} catch (MalformedURLException e1) {
// do nothing, fall through and return 'target'
} catch (IOException e) {
// do nothing, fall through and return 'target'
} catch (RuntimeException e) {
// do nothing, fall through and return 'target'
}
}
}

return target;
}

Expand Down

0 comments on commit aeac2a6

Please sign in to comment.