private IMethod makeNullaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory) cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 1); S.addConstant(new Integer(2), new ConstantValue(0.0)); S.addStatement(insts.ReturnInstruction(2, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls); }
private IMethod makeUnaryNumberCall(IClass cls) { JSInstructionFactory insts = (JSInstructionFactory) cls.getClassLoader().getInstructionFactory(); MethodReference ref = AstMethodReference.fnReference(JavaScriptTypes.Number); JavaScriptSummary S = new JavaScriptSummary(ref, 2); S.addStatement(insts.GetInstruction(4, 2, "toNumber")); S.getNextProgramCounter(); CallSiteReference cs = new JSCallSiteReference(S.getNextProgramCounter()); S.addStatement(insts.Invoke(4, 5, new int[] {2}, 6, cs)); S.addStatement(insts.ReturnInstruction(5, false)); S.getNextProgramCounter(); return new JavaScriptConstructor(ref, S, cls); }
protected void doCall( WalkContext context, CAstNode call, int result, int exception, CAstNode name, int receiver, int[] arguments) { MethodReference ref = name.getValue().equals("ctor") ? JavaScriptMethods.ctorReference : name.getValue().equals("dispatch") ? JavaScriptMethods.dispatchReference : AstMethodReference.fnReference(JavaScriptTypes.CodeBody); context .cfg() .addInstruction( ((JSInstructionFactory) insts) .Invoke( receiver, result, arguments, exception, new JSCallSiteReference(ref, context.cfg().getCurrentInstruction()))); context.cfg().addPreNode(call, context.getUnwindState()); // this new block is for the normal termination case context.cfg().newBlock(true); // exceptional case: flow to target given in CAst, or if null, the exit node if (context.getControlFlow().getTarget(call, null) != null) context.cfg().addPreEdge(call, context.getControlFlow().getTarget(call, null), true); else context.cfg().addPreEdgeToExit(call, true); }
public class LoadFileTargetSelector implements MethodTargetSelector { private final MethodTargetSelector base; private final JSSSAPropagationCallGraphBuilder builder; private final TypeReference loadFileRef = TypeReference.findOrCreate( JavaScriptTypes.jsLoader, TypeName.string2TypeName("Lprologue.js/loadFile")); private final MethodReference loadFileFunRef = AstMethodReference.fnReference(loadFileRef); private final HashSet<URL> loadedFiles = HashSetFactory.make(); @Override 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()]; 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, 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' } } } } return target; } public LoadFileTargetSelector( MethodTargetSelector base, JSSSAPropagationCallGraphBuilder builder) { super(); this.base = base; this.builder = builder; } }