Skip to content

Commit

Permalink
isComputed flag added to getField and putField
Browse files Browse the repository at this point in the history
  • Loading branch information
ksen007 committed Dec 4, 2014
1 parent 5c57512 commit 9b8044b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 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){return {base:base,offset:offset,skip:false};};
this.getFieldPre = function(iid, base, offset, isComputed){return {base:base,offset:offset,skip:false};};
this.getField = function(iid, base, offset, val){return {result:val};};
this.getField = function(iid, base, offset, val, isComputed){return {result:val};};
this.putFieldPre = function(iid, base, offset, val){return {base:base,offset:offset,val:val,skip:false};};
this.putFieldPre = function(iid, base, offset, val, isComputed){return {base:base,offset:offset,val:val,skip:false};};
this.putField = function(iid, base, offset, val){return {result:val};};
this.putField = function(iid, base, offset, val, isComputed){return {result:val};};
this.read = function(iid, name, val, isGlobal, isPseudoGlobal){return {result:val};};
Expand Down
20 changes: 10 additions & 10 deletions src/js/instrument/esnstrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ if (typeof J$ === 'undefined') {
newNode.raw = oldNode.loc;
}

function wrapPutField(node, base, offset, rvalue) {
if (!Config.INSTR_PUTFIELD || Config.INSTR_PUTFIELD(node.computed ? null : offset.value, node)) {
function wrapPutField(node, base, offset, rvalue, isComputed) {
if (!Config.INSTR_PUTFIELD || Config.INSTR_PUTFIELD(isComputed ? null : offset.value, node)) {
printIidToLoc(node);
var ret = replaceInExpr(
logPutFieldFunName +
"(" + RP + "1, " + RP + "2, " + RP + "3, " + RP + "4)",
"(" + RP + "1, " + RP + "2, " + RP + "3, " + RP + "4,"+(isComputed?"true":"false")+")",
getIid(),
base,
offset,
Expand Down Expand Up @@ -316,11 +316,11 @@ if (typeof J$ === 'undefined') {
}
}

function wrapMethodCall(node, base, offset, isCtor) {
function wrapMethodCall(node, base, offset, isCtor, isComputed) {
printIidToLoc(node);
printSpecialIidToLoc(node.callee);
var ret = replaceInExpr(
logMethodCallFunName + "(" + RP + "1, " + RP + "2, " + RP + "3, " + (isCtor ? "true" : "false") + ")",
logMethodCallFunName + "(" + RP + "1, " + RP + "2, " + RP + "3, " + (isCtor ? "true" : "false") + ","+ (isComputed ? "true" : "false") + ")",
getIid(),
base,
offset
Expand All @@ -340,11 +340,11 @@ if (typeof J$ === 'undefined') {
return ret;
}

function wrapGetField(node, base, offset) {
function wrapGetField(node, base, offset, isComputed) {
if (!Config.INSTR_GETFIELD || Config.INSTR_GETFIELD(node.computed ? null : offset.value, node)) {
printIidToLoc(node);
var ret = replaceInExpr(
logGetFieldFunName + "(" + RP + "1, " + RP + "2, " + RP + "3)",
logGetFieldFunName + "(" + RP + "1, " + RP + "2, " + RP + "3,"+(isComputed?"true":"false")+")",
getIid(),
base,
offset
Expand Down Expand Up @@ -872,7 +872,7 @@ if (typeof J$ === 'undefined') {
if (ast.type === 'MemberExpression') {
ret = wrapMethodCall(callAst, ast.object,
getPropertyAsAst(ast),
isCtor);
isCtor, ast.computed);
return ret;
} else if (ast.type === 'Identifier' && ast.name === "eval") {
return ast;
Expand All @@ -894,7 +894,7 @@ if (typeof J$ === 'undefined') {
node.right = ret;
return node;
} else {
ret = wrapPutField(node, node.left.object, getPropertyAsAst(node.left), node.right);
ret = wrapPutField(node, node.left.object, getPropertyAsAst(node.left), node.right, node.left.computed);
return ret;
}
}
Expand All @@ -919,7 +919,7 @@ if (typeof J$ === 'undefined') {
//return ret;
//}
} else if (ast.type === 'MemberExpression') {
return wrapGetField(ast, ast.object, getPropertyAsAst(ast));
return wrapGetField(ast, ast.object, getPropertyAsAst(ast), ast.computed);
} else {
return ast;
}
Expand Down
16 changes: 8 additions & 8 deletions src/js/runtime/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ if (typeof J$ === 'undefined') {
}

// Method call (e.g., e.f())
function M(iid, base, offset, isConstructor) {
function M(iid, base, offset, isConstructor, isComputed) {
return function () {
var f = G(iid + 2, base, offset);
var f = G(iid + 2, base, offset, isComputed);
return (sandbox.lastValue = invokeFun(iid, base, f, arguments, isConstructor, true));
};
}
Expand Down Expand Up @@ -205,11 +205,11 @@ if (typeof J$ === 'undefined') {
}

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

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

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

if (sandbox.analysis && sandbox.analysis.putFieldPre) {
aret = sandbox.analysis.putFieldPre(iid, base, offset, val);
aret = sandbox.analysis.putFieldPre(iid, base, offset, val, isComputed);
if (aret) {
base = aret.base;
offset = aret.offset;
Expand All @@ -247,7 +247,7 @@ if (typeof J$ === 'undefined') {
base[offset] = val;
}
if (sandbox.analysis && sandbox.analysis.putField) {
aret = sandbox.analysis.putField(iid, base, offset, val);
aret = sandbox.analysis.putField(iid, base, offset, val, isComputed);
if (aret) {
val = aret.result;
}
Expand Down
8 changes: 4 additions & 4 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){return {base:base,offset:offset,skip:false};};
this.getFieldPre = function(iid, base, offset, isComputed){return {base:base,offset:offset,skip:false};};

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

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

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

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

Expand Down

0 comments on commit 9b8044b

Please sign in to comment.