Skip to content

Commit

Permalink
added extra boolean parameters to putField*, getField*, and binary*
Browse files Browse the repository at this point in the history
  • Loading branch information
ksen007 committed Dec 4, 2014
1 parent 41b9a63 commit 058b217
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 44 deletions.
14 changes: 14 additions & 0 deletions .idea/libraries/jalangi2_node_modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions docs/analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ API compared to analysis.js. An analysis in analysis.js can be written using th
this.declare = function (iid, name, val, isArgument, argumentIndex, isCatchParam){return {result:val};};
this.getFieldPre = function(iid, base, offset, isComputed){return {base:base,offset:offset,skip:false};};
this.getFieldPre = function(iid, base, offset, isComputed, isOpAssign, isMethodCall){return {base:base,offset:offset,skip:false};};
this.getField = function(iid, base, offset, val, isComputed){return {result:val};};
this.getField = function(iid, base, offset, val, isComputed, isOpAssign, isMethodCall){return {result:val};};
this.putFieldPre = function(iid, base, offset, val, isComputed){return {base:base,offset:offset,val:val,skip:false};};
this.putFieldPre = function(iid, base, offset, val, isComputed, isOpAssign){return {base:base,offset:offset,val:val,skip:false};};
this.putField = function(iid, base, offset, val, isComputed){return {result:val};};
this.putField = function(iid, base, offset, val, isComputed, isOpAssign){return {result:val};};
this.read = function(iid, name, val, isGlobal, isPseudoGlobal){return {result:val};};
Expand All @@ -51,9 +51,9 @@ API compared to analysis.js. An analysis in analysis.js can be written using th
this.scriptExit = function(iid, exceptionVal){return {exceptionVal:exceptionVal,isBacktrack:false};};
this.binaryPre = function(iid, op, left, right){return {op:op,left:left,right:right,skip:false};};
this.binaryPre = function(iid, op, left, right, isOpAssign, isSwitchCaseComparison){return {op:op,left:left,right:right,skip:false};};
this.binary = function(iid, op, left, right, result){return {result:result};};
this.binary = function(iid, op, left, right, result, isOpAssign, isSwitchCaseComparison){return {result:result};};
this.unaryPre = function(iid, op, left) {return {op:op,left:left,skip:false};};
Expand All @@ -63,22 +63,23 @@ API compared to analysis.js. An analysis in analysis.js can be written using th
this.instrumentCodePre = function(iid, code){return {code:code,skip:false};};
this.instrumentCode = function(iid, newCode, newAst){return {result:newCode};};
this.instrumentCode = function(iid, newCode, newAst){ return {result:newCode};};
this.endExecution = function() {};
}
sandbox.analysis = new MyAnalysis();
}
sandbox.analysis = new MyAnalysis();
})(J$);
```

An analysis can be performed on a JavaScript file by issuing the following commands:

node src/js/instrument/esnstrument.js tests/octane/deltablue.js
node src/js/commands/esnstrument_cli.js --inlineIID --inlineSource tests/octane/deltablue.js
node src/js/commands/direct.js --analysis src/js/sample_analyses/ChainedAnalyses.js --analysis src/js/sample_analyses/dlint/Utils.js --analysis src/js/sample_analyses/dlint/CheckNaN.js --analysis src/js/sample_analyses/dlint/FunCalledWithMoreArguments.js --analysis src/js/sample_analyses/dlint/CompareFunctionWithPrimitives.js --analysis src/js/sample_analyses/dlint/ShadowProtoProperty.js --analysis src/js/sample_analyses/dlint/ConcatUndefinedToString.js --analysis src/js/sample_analyses/dlint/UndefinedOffset.js tests/octane/deltablue_jalangi_.js
An analysis can be performed on an web app using the Chrome browser by issuing the following commands:

node src/js/commands/instrument.js --analysis src/js/sample_analyses/ChainedAnalyses.js --analysis src/js/sample_analyses/dlint/Utils.js --analysis src/js/sample_analyses/dlint/CheckNaN.js --analysis src/js/sample_analyses/dlint/FunCalledWithMoreArguments.js --analysis src/js/sample_analyses/dlint/CompareFunctionWithPrimitives.js --analysis src/js/sample_analyses/dlint/ShadowProtoProperty.js --analysis src/js/sample_analyses/dlint/ConcatUndefinedToString.js --analysis src/js/sample_analyses/dlint/UndefinedOffset.js --outputDir /tmp tests/tizen/annex
node src/js/commands/instrument.js --inlineIID --inlineSource --analysis src/js/sample_analyses/ChainedAnalyses.js --analysis src/js/sample_analyses/dlint/Utils.js --analysis src/js/sample_analyses/dlint/CheckNaN.js --analysis src/js/sample_analyses/dlint/FunCalledWithMoreArguments.js --analysis src/js/sample_analyses/dlint/CompareFunctionWithPrimitives.js --analysis src/js/sample_analyses/dlint/ShadowProtoProperty.js --analysis src/js/sample_analyses/dlint/ConcatUndefinedToString.js --analysis src/js/sample_analyses/dlint/UndefinedOffset.js --outputDir /tmp tests/tizen/annex
open file:///tmp/annex/index.html

While performing analysis in a browser, one needs to press Alt-Shift-T to end the analysis and to print the analysis results in the console.
Expand Down
26 changes: 15 additions & 11 deletions src/js/instrument/esnstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ if (typeof J$ === 'undefined') {
}
}

function wrapModAssign(node, base, offset, op, rvalue) {
function wrapModAssign(node, base, offset, op, rvalue, isComputed) {
if (!Config.INSTR_PROPERTY_BINARY_ASSIGNMENT || Config.INSTR_PROPERTY_BINARY_ASSIGNMENT(op, node.computed ? null : offset.value, node)) {
printIidToLoc(node);
var ret = replaceInExpr(
logAssignFunName + "(" + RP + "1," + RP + "2," + RP + "3," + RP + "4)(" + RP + "5)",
logAssignFunName + "(" + RP + "1," + RP + "2," + RP + "3," + RP + "4,"+(isComputed?"true":"false")+")(" + RP + "5)",
getIid(),
base,
offset,
Expand Down Expand Up @@ -947,7 +947,7 @@ if (typeof J$ === 'undefined') {
var ret = wrapModAssign(node, node.left.object,
getPropertyAsAst(node.left),
node.operator.substring(0, node.operator.length - 1),
node.right);
node.right, node.left.computed);
return ret;
}
}
Expand Down Expand Up @@ -1514,25 +1514,29 @@ if (typeof J$ === 'undefined') {
var newCode = escodegen.generate(newAst);
code = newCode + "\n" + noInstr + "\n";
}
iidSourceInfo.nBranches = condIid / IID_INC_STEP * 2;
iidSourceInfo.originalCodeFileName = origCodeFileName;
iidSourceInfo.instrumentedCodeFileName = instCodeFileName;

var tmp = {};

tmp.nBranches = iidSourceInfo.nBranches = condIid / IID_INC_STEP * 2;
tmp.originalCodeFileName = iidSourceInfo.originalCodeFileName = origCodeFileName;
tmp.instrumentedCodeFileName = iidSourceInfo.instrumentedCodeFileName = instCodeFileName;
if (url) {
iidSourceInfo.url = url;
tmp.url = iidSourceInfo.url = url;
}
if (isEval) {
iidSourceInfo.evalSid = sandbox.sid;
iidSourceInfo.evalIid = thisIid;
tmp.evalSid = iidSourceInfo.evalSid = sandbox.sid;
tmp.evalIid = iidSourceInfo.evalIid = thisIid;
}
if (inlineSource) {
iidSourceInfo.code = options.code;
tmp.code = iidSourceInfo.code = options.code;
}

var prepend = JSON.stringify(iidSourceInfo);
var instCode;
if (options.inlineSourceMap) {
instCode = JALANGI_VAR + ".iids = " + prepend + ";\n" + code;
} else {
instCode = code;
instCode = JALANGI_VAR + ".iids = " + JSON.stringify(tmp) + ";\n" + code;
}

if (isEval && sandbox.analysis && sandbox.analysis.instrumentCode) {
Expand Down
30 changes: 15 additions & 15 deletions src/js/runtime/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if (typeof J$ === 'undefined') {
// Method call (e.g., e.f())
function M(iid, base, offset, isConstructor, isComputed) {
return function () {
var f = G(iid + 2, base, offset, isComputed);
var f = G(iid + 2, base, offset, isComputed, false, true);
return (lastComputedValue = invokeFun(iid, base, f, arguments, isConstructor, true));
};
}
Expand Down Expand Up @@ -239,11 +239,11 @@ if (typeof J$ === 'undefined') {
}

// getField (property read)
function G(iid, base, offset, isComputed) {
function G(iid, base, offset, isComputed, isOpAssign, isMethodCall) {
var aret, skip = false, val;

if (sandbox.analysis && sandbox.analysis.getFieldPre) {
aret = sandbox.analysis.getFieldPre(iid, base, offset, isComputed);
aret = sandbox.analysis.getFieldPre(iid, base, offset, isComputed, !!isOpAssign, !!isMethodCall);
if (aret) {
base = aret.base;
offset = aret.offset;
Expand All @@ -255,7 +255,7 @@ if (typeof J$ === 'undefined') {
val = base[offset];
}
if (sandbox.analysis && sandbox.analysis.getField) {
aret = sandbox.analysis.getField(iid, base, offset, val, isComputed);
aret = sandbox.analysis.getField(iid, base, offset, val, isComputed, !!isOpAssign, !!isMethodCall);
if (aret) {
val = aret.result;
}
Expand All @@ -264,11 +264,11 @@ if (typeof J$ === 'undefined') {
}

// putField (property write)
function P(iid, base, offset, val, isComputed) {
function P(iid, base, offset, val, isComputed, isOpAssign) {
var aret, skip = false;

if (sandbox.analysis && sandbox.analysis.putFieldPre) {
aret = sandbox.analysis.putFieldPre(iid, base, offset, val, isComputed);
aret = sandbox.analysis.putFieldPre(iid, base, offset, val, isComputed, !!isOpAssign);
if (aret) {
base = aret.base;
offset = aret.offset;
Expand All @@ -281,7 +281,7 @@ if (typeof J$ === 'undefined') {
base[offset] = val;
}
if (sandbox.analysis && sandbox.analysis.putField) {
aret = sandbox.analysis.putField(iid, base, offset, val, isComputed);
aret = sandbox.analysis.putField(iid, base, offset, val, isComputed, !!isOpAssign);
if (aret) {
val = aret.result;
}
Expand Down Expand Up @@ -409,20 +409,20 @@ if (typeof J$ === 'undefined') {


// Modify and assign +=, -= ...
function A(iid, base, offset, op) {
var oprnd1 = G(iid, base, offset);
function A(iid, base, offset, op, isComputed) {
var oprnd1 = G(iid, base, offset, isComputed, true, false);
return function (oprnd2) {
var val = B(iid, op, oprnd1, oprnd2);
return P(iid, base, offset, val);
var val = B(iid, op, oprnd1, oprnd2, true, false);
return P(iid, base, offset, val, isComputed, true);
};
}

// Binary operation
function B(iid, op, left, right) {
function B(iid, op, left, right, isOpAssign, isSwitchCaseComparison) {
var result, aret, skip = false;

if (sandbox.analysis && sandbox.analysis.binaryPre) {
aret = sandbox.analysis.binaryPre(iid, op, left, right);
aret = sandbox.analysis.binaryPre(iid, op, left, right, !!isOpAssign, !!isSwitchCaseComparison);
if (aret) {
op = aret.op;
left = aret.left;
Expand Down Expand Up @@ -507,7 +507,7 @@ if (typeof J$ === 'undefined') {
}

if (sandbox.analysis && sandbox.analysis.binary) {
aret = sandbox.analysis.binary(iid, op, left, right, result);
aret = sandbox.analysis.binary(iid, op, left, right, result, !!isOpAssign, !!isSwitchCaseComparison);
if (aret) {
result = aret.result;
}
Expand Down Expand Up @@ -585,7 +585,7 @@ if (typeof J$ === 'undefined') {
function C2(iid, left) {
var aret, result;

result = B(iid, "===", switchLeft, left);
result = B(iid, "===", switchLeft, left, false, true);

if (sandbox.analysis && sandbox.analysis.conditional) {
aret = sandbox.analysis.conditional(iid, result);
Expand Down
12 changes: 6 additions & 6 deletions src/js/runtime/analysisCallbackTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@

this.declare = function (iid, name, val, isArgument, argumentIndex, isCatchParam){return {result:val};};

this.getFieldPre = function(iid, base, offset, isComputed){return {base:base,offset:offset,skip:false};};
this.getFieldPre = function(iid, base, offset, isComputed, isOpAssign, isMethodCall){return {base:base,offset:offset,skip:false};};

this.getField = function(iid, base, offset, val, isComputed){return {result:val};};
this.getField = function(iid, base, offset, val, isComputed, isOpAssign, isMethodCall){return {result:val};};

this.putFieldPre = function(iid, base, offset, val, isComputed){return {base:base,offset:offset,val:val,skip:false};};
this.putFieldPre = function(iid, base, offset, val, isComputed, isOpAssign){return {base:base,offset:offset,val:val,skip:false};};

this.putField = function(iid, base, offset, val, isComputed){return {result:val};};
this.putField = function(iid, base, offset, val, isComputed, isOpAssign){return {result:val};};

this.read = function(iid, name, val, isGlobal, isPseudoGlobal){return {result:val};};

Expand All @@ -65,9 +65,9 @@

this.scriptExit = function(iid, exceptionVal){return {exceptionVal:exceptionVal,isBacktrack:false};};

this.binaryPre = function(iid, op, left, right){return {op:op,left:left,right:right,skip:false};};
this.binaryPre = function(iid, op, left, right, isOpAssign, isSwitchCaseComparison){return {op:op,left:left,right:right,skip:false};};

this.binary = function(iid, op, left, right, result){return {result:result};};
this.binary = function(iid, op, left, right, result, isOpAssign, isSwitchCaseComparison){return {result:result};};

this.unaryPre = function(iid, op, left) {return {op:op,left:left,skip:false};};

Expand Down
6 changes: 5 additions & 1 deletion src/js/runtime/iidToLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ if (typeof J$ === 'undefined') {
if (ret.evalSid !== undefined) {
fname = fname+sandbox.iidToLocation(ret.evalSid, ret.evalIid);
}
return "("+fname/*.replace("_orig_.js", ".js")*/+":"+arr[0]+":"+arr[1]+":"+arr[2]+":"+arr[3]+")";
return "("+fname+":"+arr[0]+":"+arr[1]+":"+arr[2]+":"+arr[3]+")";
}
}
return sid+"";
};

sandbox.getGlobalIID = function(iid) {
return sandbox.sid +":"+iid;
}

}(J$));

0 comments on commit 058b217

Please sign in to comment.