From e130a5b963d0f34d0e95f247804e7440efaf3607 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Tue, 18 Sep 2012 13:22:17 -0400 Subject: [PATCH] Some refactoring of prologue.js and preamble.js to use more consistent names. --- .../js/test/TestSimpleCallGraphShape.java | 6 +- .../js/test/TestSimplePageCallGraphShape.java | 52 ++-- com.ibm.wala.cast.js/dat/preamble.js | 232 ++++++++++++--- com.ibm.wala.cast.js/dat/prologue.js | 273 ++++++++++++++---- ...ScriptFunctionApplyContextInterpreter.java | 2 +- ...avaScriptFunctionApplyContextSelector.java | 4 +- ...JavaScriptFunctionApplyTargetSelector.java | 6 +- ...vaScriptFunctionDotCallTargetSelector.java | 2 +- .../correlations/CorrelationFinder.java | 8 +- .../correlations/CorrelationSummary.java | 4 + .../CorrelatedPairExtractorFactory.java | 2 +- 11 files changed, 452 insertions(+), 139 deletions(-) diff --git a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java index ff7b1e337..b2df1de5c 100755 --- a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java +++ b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java @@ -67,7 +67,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape { new Object[] { "tests/simple.js/rubbish", new String[] { "tests/simple.js/weirder", "tests/simple.js/stranger", "tests/simple.js/rubbish" } }, new Object[] { "tests/simple.js/fib", new String[] { "tests/simple.js/fib" } }, - new Object[] { "tests/simple.js/weirder", new String[] { "prologue.js/abs" } } }; + new Object[] { "tests/simple.js/weirder", new String[] { "prologue.js/Math_abs" } } }; @Test public void testSimple() throws IOException, IllegalArgumentException, CancelException { @@ -241,7 +241,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape { private static final Object[][] assertionsForStringPrims = new Object[][] { new Object[] { ROOT, new String[] { "tests/string-prims.js" } }, - new Object[] { "tests/string-prims.js", new String[] { "prologue.js/stringSplit", "prologue.js/toUpperCase" } } }; + new Object[] { "tests/string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } }; @Test public void testStringPrims() throws IOException, IllegalArgumentException, CancelException { @@ -486,7 +486,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape { private static final Object[][] assertionsForFunctionIsAFunction = new Object[][] { new Object[] { ROOT, new String[] { "tests/Function_is_a_function.js" } }, - new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:functionCall" } } }; + new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:Function_prototype_call" } } }; @Test public void testFunctionIsAFunction() throws IOException, IllegalArgumentException, CancelException { diff --git a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java index 1b0a6dc91..acff3ab54 100755 --- a/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java +++ b/com.ibm.wala.cast.js.test/harness-src/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java @@ -44,9 +44,9 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape new Object[] { ROOT, new String[] { "page1.html" } }, new Object[] { "page1.html", new String[] { "page1.html/__WINDOW_MAIN__" } }, new Object[] { "page1.html/__WINDOW_MAIN__", - new String[] { "prologue.js/substring", - "prologue.js/indexOf", - "preamble.js/DOMDocument/write_to_dom", + new String[] { "prologue.js/String_prototype_substring", + "prologue.js/String_prototype_indexOf", + "preamble.js/DOMDocument/Document_prototype_write", "prologue.js/encodeURI" } } @@ -73,9 +73,9 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape new Object[] { ROOT, new String[] { "page11.html" } }, new Object[] { "page11.html", new String[] { "page11.html/__WINDOW_MAIN__" } }, new Object[] { "page11.html/__WINDOW_MAIN__", - new String[] { "preamble.js/DOMDocument/createElement", - "preamble.js/DOMNode/appendChild", - "preamble.js/DOMElement/setAttribute" + new String[] { "preamble.js/DOMDocument/Document_prototype_createElement", + "preamble.js/DOMNode/Node_prototype_appendChild", + "preamble.js/DOMElement/Element_prototype_setAttribute" } } }; @@ -90,9 +90,9 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape new Object[] { ROOT, new String[] { "page11b.html" } }, new Object[] { "page11b.html", new String[] { "page11b.html/__WINDOW_MAIN__" } }, new Object[] { "page11b.html/__WINDOW_MAIN__", - new String[] { "preamble.js/DOMDocument/createElement", - "preamble.js/DOMNode/appendChild", - "preamble.js/DOMElement/setAttribute" + new String[] { "preamble.js/DOMDocument/Document_prototype_createElement", + "preamble.js/DOMNode/Node_prototype_appendChild", + "preamble.js/DOMElement/Element_prototype_setAttribute" } } }; @@ -113,18 +113,18 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape } }, new Object[]{ "page12.html/__WINDOW_MAIN__/callXHR", - new String[] { "preamble.js/DOMDocument/getElementById", - "preamble.js/_XMLHttpRequest/xhr_open", - "preamble.js/_XMLHttpRequest/xhr_send" + new String[] { "preamble.js/DOMDocument/Document_prototype_getElementById", + "preamble.js/XMLHttpRequest/xhr_open", + "preamble.js/XMLHttpRequest/xhr_send" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_open", - new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" } + new Object[]{ "preamble.js/XMLHttpRequest/xhr_open", + new String[] { "preamble.js/XMLHttpRequest/xhr_orsc_handler" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_send", - new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" } + new Object[]{ "preamble.js/XMLHttpRequest/xhr_send", + new String[] { "preamble.js/XMLHttpRequest/xhr_orsc_handler" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_orsc_handler", + new Object[]{ "preamble.js/XMLHttpRequest/xhr_orsc_handler", new String[] { "page12.html/__WINDOW_MAIN__/handler" } }, }; @@ -145,19 +145,19 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape } }, new Object[]{ "page13.html/__WINDOW_MAIN__/callXHR", - new String[] { "preamble.js/DOMDocument/getElementById", - "preamble.js/_XMLHttpRequest/xhr_open", - "preamble.js/_XMLHttpRequest/xhr_setRequestHeader", - "preamble.js/_XMLHttpRequest/xhr_send" + new String[] { "preamble.js/DOMDocument/Document_prototype_getElementById", + "preamble.js/XMLHttpRequest/xhr_open", + "preamble.js/XMLHttpRequest/xhr_setRequestHeader", + "preamble.js/XMLHttpRequest/xhr_send" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_open", - new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" } + new Object[]{ "preamble.js/XMLHttpRequest/xhr_open", + new String[] { "preamble.js/XMLHttpRequest/xhr_orsc_handler" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_send", - new String[] { "preamble.js/_XMLHttpRequest/xhr_orsc_handler" } + new Object[]{ "preamble.js/XMLHttpRequest/xhr_send", + new String[] { "preamble.js/XMLHttpRequest/xhr_orsc_handler" } }, - new Object[]{ "preamble.js/_XMLHttpRequest/xhr_orsc_handler", + new Object[]{ "preamble.js/XMLHttpRequest/xhr_orsc_handler", new String[] { "page13.html/__WINDOW_MAIN__/handler" } } }; diff --git a/com.ibm.wala.cast.js/dat/preamble.js b/com.ibm.wala.cast.js/dat/preamble.js index b5fd30cdd..caad70cc6 100644 --- a/com.ibm.wala.cast.js/dat/preamble.js +++ b/com.ibm.wala.cast.js/dat/preamble.js @@ -90,20 +90,20 @@ NamedNodeList = function NamedNodeList() { DOMNode = function DOMNode() { // An impostor for the Node class this.childNodes = new NamedNodeList(); - this.insertBefore = function insertBefore(newChild, refChild) { + this.insertBefore = function Node_prototype_insertBefore(newChild, refChild) { this.childNodes.insertBefore(newChild, refChild); } - this.replaceChild = function replaceChild(newChild, oldChild) { + this.replaceChild = function Node_prototype_replaceChild(newChild, oldChild) { this.childNodes.replace(newChild, oldChild); } - this.removeChild = function removeChild(oldChild) { + this.removeChild = function Node_prototype_removeChild(oldChild) { this.childNodes.remove(oldChild); } - this.appendChild = function appendChild(newChild) { + this.appendChild = function Node_prototype_appendChild(newChild) { this.childNodes.add(newChild); newChild.parentNode = this; } - this.hasChildNodes = function hasChildNodes() { + this.hasChildNodes = function Node_prototype_hasChildNodes() { return this.childNodes.hasElements(); } @@ -117,39 +117,77 @@ DOMNode = function DOMNode() { // An impostor for the Node class } this.childNodes.collect(predicate, result); } - this.addEventListener = function(name, fn) { - fn(); - }; +}; + +DOMNode.prototype.addEventListener = function Node_prototype_addEventListener(name, fn) { fn(); }; + +DOMNode.prototype.removeEventListener = function Node_prototype_removeEventListener(name) {}; + +DOMNode.prototype.cloneNode = function Node_prototype_cloneNode() { + // TODO: model me +}; + +DOMNode.prototype.compareDocumentPosition = function Node_prototype_compareDocumentPosition() { + // TODO: model me +}; + +DOMNode.prototype.contains = function Node_prototype_contains() { + return true || false; } DOMDocument = function DOMDocument() { - this.temp = DOMNode; - this.temp(); + this.DOMNode = DOMNode; + this.DOMNode(); + delete this.DOMNode; - this.createElement = function createElement(name) { + this.createElement = function Document_prototype_createElement(name) { // TODO : to be implemented accurately - var toReturn = new DOMHTMLGenericElement(name); - return toReturn; + return new DOMHTMLGenericElement(name); } - this.getElementById = function getElementById(id) { - var result = new Array(); - this.collect(function check_id(x) { return x.id == id; }, result); - return result[0]; - } - - this.write = function write_to_dom (stuff) { - + this.getElementById = function Document_prototype_getElementById(id) { + var result = new Array(); + this.collect(function check_id(x) { return x.id == id; }, result); + return result[0]; }; -} + + this.getElementsByTagName = function Document_prototype_getElementsByTagName(name) { + // TODO: implement + }; + + this.createTextNode = function Document_prototype_createTextNode(txt) { + // TODO: not very precise + return new DOMHTMLGenericElement("text"); + }; + + this.write = function Document_prototype_write (stuff) { + + }; +}; +DOMDocument.prototype.createDocumentFragment = function Document_prototype_createDocumentFragment() { + // TODO: model me +}; +DOMDocument.prototype.createComment = function Document_prototype_createComment() { + // TODO: model me +}; +DOMDocument.prototype.getElementsByClassName = function Document_prototype_getElementsByClassName() { + // TODO: model me +}; +DOMDocument.prototype.querySelectorAll = function Document_prototype_querySelectorAll() { + // TODO: model me +}; + + HTMLBody = function HTMLBody(){ this.innerHTML = new String(); } DOMHTMLDocument = function DOMHTMLDocument() { - this.temp = DOMDocument; - this.temp(); + this.DOMDocument = DOMDocument; + this.DOMDocument(); + delete this.DOMDocument; + this.URL = new String(); this.body = new HTMLBody(); this.forms = new Array(); @@ -168,16 +206,54 @@ Location = function Location(){ } } +Image = function Image() { + this.name = new String(); + this.src = new String(); + this.align = new String(); + this.alt = new String(); + this.border = new String(); + this.height = 1/2; + this.hspace = 1/2; + this.isMap = true || false; + this.longDesc = new String(); + this.useMap = new String(); + this.vspace = 1/2; + this.width = 1/2; +}; + DOMWindow = function DOMWindow(){ this.name = new String(); this.open = function window_open(url, stuff) { note_url(url); }; - this.addEventListener = function(name, fn) { + this.addEventListener = function Window_prototype_addEventListener(name, fn) { fn(); }; -} + this.alert = function Window_prototype_alert(msg) { + // as everyone knows, alert is pure + }; + this.setInterval = function Window_prototype_setInterval(fn, interval) { + fn(); + }; + this.setTimeout = function Window_prototype_setTimeout(fn, timeout) { + fn(); + }; + this.clearInterval = function Window_prototype_clearInterval(interval) {}; + this.clearTimeout = function Window_prototype_clearTimeout(timeout) {}; +}; +DOMWindow.prototype.getComputedStyle = function Window_prototype_getComputedStyle(elt, pseudoElt) { + return new CSS2Properties(); +}; +DOMWindow.prototype.focus = function Window_prototype_focus() { + // TODO: model me +}; +DOMWindow.prototype.prompt = function Window_prototype_prompt() { +}; + +CSS2Properties = function CSS2Properties() { + this.cssText = new String(); +}; DOJOObj = function DOJOObj(){ this.moduleUrl = function module_url(str1, str2){ @@ -201,40 +277,75 @@ window.document = document; document.defaultView = window; window.XMLHttpRequest = XMLHttpRequest; +setInterval = window.setInterval; +setTimeout = window.setTimeout; +clearInterval = window.clearInterval; + var dojo = new DOJOObj(); DOMElement = function DOMElement() { // An impostor for the Element class // inherits from Node - this.temp = DOMNode; - this.temp(); + this.DOMNode = DOMNode; + this.DOMNode(); + delete this.DOMNode; // The get/set/remove attribute methods cannot be run using 'onclick','onmouseover', 'on...' kind of arguments for name. // since that would be used as a workaround for eval - this.getAttribute = function getAttribute(name) { + this.getAttribute = function Element_prototype_getAttribute(name) { return this[name]; - } - this.setAttribute = function setAttribute(name, value) { + }; + + this.setAttribute = function Element_prototype_setAttribute(name, value) { this[name] = value; - } + }; - this.removeAttribute = function removeAttribute(name) { - this[name] = undefined; - } + this.removeAttribute = function Element_prototype_removeAttribute(name) { + delete this[name]; + }; - this.getElementsByTagName = function _getElementsByTagName(tagName) { + this.getElementsByTagName = function Element_prototype_getElementsByTagName(tagName) { var result = new Array(); this.collect(function check_tag(x) { return x.name == tagName; }, result); return result; - } + }; -} + this.focus = function Element_prototype_focus() {}; +}; + +DOMElement.prototype.querySelectorAll = function Element_prototype_querySelectorAll() { + // TODO: model me +}; + +DOMElement.prototype.getElementsByClassName = function Element_prototype_getElementsByClassName() { + // TODO: model me +}; + +DOMElement.prototype.getBoundingClientRect = function Element_prototype_getBoundingClientRect() { + // TODO: model me +}; + +DOMElement.prototype.focus = function Element_prototype_focus() { +}; + +Event = function Event() { + // TODO: model me +}; + +Event.prototype.stopPropagation = function Event_prototype_stopPropagation() { + // TODO: model me +}; + +Event.prototype.preventDefault = function Event_prototype_preventDefault() { + // TODO: model me +}; DOMHTMLElement = function DOMHTMLElement() { // An impostor for the HTMLElement class // inherits from Element - this.temp = DOMElement; - this.temp(); + this.DOMElement = DOMElement; + this.DOMElement(); + delete this.DOMElement; // Set HTML Attribute Defaults this.id = null; @@ -253,8 +364,9 @@ DOMHTMLElement = function DOMHTMLElement() { // An impostor for the HTMLElement // Just a hack until all HTML elements have corresponding constructors DOMHTMLGenericElement = function DOMHTMLGenericElement(tagName) { // inherits from Element - this.temp = DOMHTMLElement; - this.temp(); + this.DOMHTMLElement = DOMHTMLElement; + this.DOMHTMLElement(); + delete this.DOMHTMLElement; // Set just the tag name this.nodeName = tagName; @@ -263,14 +375,32 @@ DOMHTMLGenericElement = function DOMHTMLGenericElement(tagName) { // load 'src' if appropriate this.src.loadFile = String.prototype.loadFile; this.src.loadFile(); -} + + // this property only exists on iframes; putting it here for now + this.documentWindow = window; + + this.getContext = function() { return new CanvasRenderingContext2D(); }; +}; + +CanvasRenderingContext2D = function CanvasRenderingContext2D() {}; +CanvasRenderingContext2D.prototype = { + beginPath: function CanvasRenderingContext2D_prototype_beginPath() {}, + moveTo: function CanvasRenderingContext2D_prototype_moveTo() {}, + lineTo: function CanvasRenderingContext2D_prototype_lineTo() {}, + closePath: function CanvasRenderingContext2D_prototype_closePath() {}, + fill: function CanvasRenderingContext2D_prototype_fill() {}, + stroke: function CanvasRenderingContext2D_prototype_stroke() {}, + clearRect: function CanvasRenderingContext2D_prototype_clearRect() {}, + fillRect: function CanvasRenderingContext2D_prototype_fillRect() {} +}; var formCount = 0; DOMHTMLFormElement = function DOMHTMLFormElement() { // inherits from HTMLElement - this.temp = DOMHTMLElement; - this.temp(); + this.DOMHTMLElement = DOMHTMLElement; + this.DOMHTMLElement(); + delete this.DOMHTMLElement; // add to 'forms' property document.forms[formCount++] = this; @@ -297,14 +427,15 @@ DOMHTMLFormElement = function DOMHTMLFormElement() { DOMHTMLTableElement = function DOMHTMLTableElement () { // inherits from HTMLElement - this.temp = DOMHTMLElement; - this.temp(); + this.DOMHTMLElement = DOMHTMLElement; + this.DOMHTMLElement(); + delete this.DOMHTMLElement; this.rows = function table_elt_rows() { } } -XMLHttpRequest = function _XMLHttpRequest() { +XMLHttpRequest = function XMLHttpRequest() { this.UNSENT = 0; this.OPENED = 1; @@ -345,6 +476,11 @@ XMLHttpRequest = function _XMLHttpRequest() { }; +XMLSerializer = function XMLSerializer() {}; +XMLSerializer.prototype.serializeToString = function XMLSerializer_prototype_serializeToString() { + // TODO: model me +}; + for(var n = 0; n < dom_nodes.length; n++) { dom_nodes[n].onload(); dom_nodes[n].onreadystatechange(); diff --git a/com.ibm.wala.cast.js/dat/prologue.js b/com.ibm.wala.cast.js/dat/prologue.js index 63c83dd34..ea9ec16cc 100755 --- a/com.ibm.wala.cast.js/dat/prologue.js +++ b/com.ibm.wala.cast.js/dat/prologue.js @@ -90,15 +90,15 @@ Object.prototype = { valueOf: function valueOf() { return this }, - hasOwnProperty: function hasOwnProperty (V) { + hasOwnProperty: function Object_prototype_hasOwnProperty (V) { return primitive("ObjectHasOwnProperty", this, V); }, - isPrototypeOf: function isPrototypeOf (V) { + isPrototypeOf: function Object_prototype_isPrototypeOf (V) { return primitive("ObjectIsPrototypeOf", this, V); }, - - propertyIsEnumerable: function propertyIsEnumerable (V) { + + propertyIsEnumerable: function Object_prototype_propertyIsEnumerable (V) { return primitive("ObjectPropertyIsEnumerable", this, V); } }; @@ -115,17 +115,22 @@ local_function.prototype = { __proto__: Object.prototype, - toString: function functionToString() { + toString: function Function_prototype_toString() { return primitive("FunctionToString", this); }, - apply: function functionApply (thisArg, argArray) { + apply: function Function_prototype_apply (thisArg, argArray) { return primitive("FunctionApply", this, thisArg, argArray); }, - call: function functionCall (thisArg) { + call: function Function_prototype_call (thisArg) { arguments.shift(); - return primitive("FunctionApply", this, thisArg, arguments); + return primitive("FunctionCall", this, thisArg, arguments); + }, + + bind: function Function_prototype_bind (thisArg) { + arguments.shift(); + return primitive("FunctionBind", this, thisArg, arguments); } }; @@ -143,11 +148,11 @@ local_array.prototype = { constructor: Array, - toString: function arrayToString () { + toString: function Array_prototype_toString () { return this.join(","); }, - toLocaleString: function arrayToLocalString () { + toLocaleString: function Array_prototype_toLocaleString () { var result = ""; var limit = this.length; for(var k = 0; k < limit; k++) { @@ -158,7 +163,7 @@ local_array.prototype = { return result; }, - concat: function concat () { + concat: function Array_prototype_concat () { var result = new Array(); var n = 0; @@ -174,7 +179,7 @@ local_array.prototype = { return result; }, - join: function join (separator) { + join: function Array_prototype_join (separator) { var result = ""; var limit = this.length; for(var k = 0; k < limit; k++) { @@ -185,11 +190,11 @@ local_array.prototype = { return result; }, - pop: function pop () { + pop: function Array_prototype_pop () { return this[ --this.length ]; }, - push: function push () { + push: function Array_prototype_push () { var n = this.length; for(var i = 0; i < arguments.length; i++) { this[ n++ ] = arguments[i]; @@ -199,7 +204,7 @@ local_array.prototype = { return n; }, - reverse: function reverse () { + reverse: function Array_prototype_reverse () { var n = this.length; for (var k = 0; k < (n/2); k++) { var tmp = this[k]; @@ -210,7 +215,7 @@ local_array.prototype = { return this; }, - shift: function shift () { + shift: function Array_prototype_shift () { var result = this[ 0 ]; for(var i = 0; i < this.length-1; i++) this[i] = this[i+1]; @@ -220,7 +225,17 @@ local_array.prototype = { return result; }, - slice: function slice (start, end) { + unshift: function Array_prototype_unshift () { + var n = arguments.length; + for(var i=this.length+n-1;i>=n;--i) + this[i] = this[i-n]; + for(;i>=0;--i) + this[i] = arguments[i]; + this.length += n; + return this.length; + }, + + slice: function Array_prototype_slice (start, end) { var j = 0; if (start < 0) start = this.length + start; if (end < 0) end = this.length + end; @@ -233,7 +248,7 @@ local_array.prototype = { return result; }, - sort: function sort (fn) { + sort: function Array_prototype_sort (fn) { for(var l = 0; i < this.length; l++) { var mindex = l; for(var i = l; i < this.length; i++) { @@ -248,9 +263,59 @@ local_array.prototype = { this[mindex] = this[l]; } } + }, + + splice: function Array_prototype_splice(start, delete_count) { + var old_len = arguments.length, + new_count = arguments.length - 2; + new_len = old_len - deleteCount + new_count; + + var deleted = this.slice(start, start + delete_count), + remainder = this.slice(start + delete_count, old_len); + + for(var i=start;i i) @@ -397,7 +480,7 @@ Math = { return i; }, - min: function min () { + min: function Math_min () { var i = Infinity; for(var j = 0; j < arguments.length; j++) if (arguments[j] < i) @@ -406,17 +489,17 @@ Math = { return i; }, - pow: function pow (x, y) { return primitive("MathPow", x, y); }, + pow: function Math_pow (x, y) { return primitive("MathPow", x, y); }, - random: function random() { return primitive("MathRandom"); }, + random: function Math_random() { return primitive("MathRandom"); }, - round: function round (x) { return primitive("MathRound", x); }, + round: function Math_round (x) { return primitive("MathRound", x); }, - sin: function sin (x) { return primitive("MathSin", x); }, + sin: function Math_sin (x) { return primitive("MathSin", x); }, - sqrt: function sqrt (x) { return primitive("MathSqrt", x);}, + sqrt: function Math_sqrt (x) { return primitive("MathSqrt", x);}, - tan: function tan (x) { return primitive("MathTan", x); } + tan: function Math_tan (x) { return primitive("MathTan", x); } }; @@ -430,8 +513,98 @@ local_regexp.prototype = { __proto__: Object.prototype, - constructor: RegExp + constructor: RegExp, + + exec: function RegExp_prototype_exec(string) { + return new Array(primitive("RegexpExec", this, string)); + }, + + test: function RegExp_prototype_test(string) { + return true || false; + } }; +/************************************************************************/ +/* Date properties, see spec 15.9 */ +/************************************************************************/ + +Date = function Date() {}; + +Date.prototype = { + + __proto__: Object.prototype, + + constructor: Date, + + getTime: function Date_prototype_getTime() { + return primitive("DateGetTime", this); + }, + + getDate: function Date_prototype_getDate() { + // TODO: model me + }, + + setDate: function Date_prototype_setDate() { + // TODO: model me + }, + + getDay: function Date_prototype_getDay() { + // TODO: model me + }, + + setDay: function Date_prototype_setDay() { + // TODO: model me + }, + + getMonth: function Date_prototype_getMonth() { + // TODO: model me + }, + + setMonth: function Date_prototype_setMonth() { + // TODO: model me + }, + + getHours: function Date_prototype_getHours() { + // TODO: model me + }, + + setHours: function Date_prototype_setHours() { + // TODO: model me + }, + + getMinutes: function Date_prototype_getMinutes() { + // TODO: model me + }, + + setMinutes: function Date_prototype_setMinutes() { + // TODO: model me + }, + + getSeconds: function Date_prototype_getSeconds() { + // TODO: model me + }, + + setSeconds: function Date_prototype_setSeconds() { + // TODO: model me + }, + + getMilliseconds: function Date_prototype_getMilliseconds() { + // TODO: model me + }, + + setMilliseconds: function Date_prototype_setMilliseconds() { + // TODO: model me + }, + + getFullYear: function Date_prototype_getFullYear() { + // TODO: model me + } + +}; + +Date.now = function Date_now() { + return new Date().valueOf(); +}; + diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextInterpreter.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextInterpreter.java index bdd73eba5..7a2568784 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextInterpreter.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextInterpreter.java @@ -26,7 +26,7 @@ import com.ibm.wala.types.TypeName; */ public class JavaScriptFunctionApplyContextInterpreter extends AstContextInsensitiveSSAContextInterpreter { - private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/functionApply"); + private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_apply"); public JavaScriptFunctionApplyContextInterpreter(AnalysisOptions options, AnalysisCache cache) { super(options, cache); diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextSelector.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextSelector.java index d52e25fc9..a7ca70392 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextSelector.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyContextSelector.java @@ -26,9 +26,9 @@ public class JavaScriptFunctionApplyContextSelector implements ContextSelector { /* whether to use a one-level callstring context in addition to the apply context */ private static final boolean USE_ONE_LEVEL = true; - private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/functionApply"); + private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_apply"); - private static final TypeName CALL_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/functionCall"); + private static final TypeName CALL_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_call"); public static final ContextKey APPLY_NON_NULL_ARGS = new ContextKey() { }; diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyTargetSelector.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyTargetSelector.java index b621006da..f7ecfa1fd 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyTargetSelector.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionApplyTargetSelector.java @@ -16,8 +16,8 @@ import com.ibm.wala.util.strings.Atom; /** * We need to generate synthetic methods for Function.apply() in the target - * selector, so that the AstMethod for functionApply() in the prologue doesn't - * actually get used in the CGNodes used for calls to Function.apply(). The + * selector, so that the AstMethod for Function_prototype_apply() in the prologue doesn't + * actually get used in the CGNodes used for calls to Function.prototype.apply(). The * generated dummy methods should never actually be used except as a * stub. */ @@ -25,7 +25,7 @@ public class JavaScriptFunctionApplyTargetSelector implements MethodTargetSelect private final MethodTargetSelector base; - private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/functionApply"); + private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_apply"); private IMethod applyMethod; public JavaScriptFunctionApplyTargetSelector(MethodTargetSelector base) { diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionDotCallTargetSelector.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionDotCallTargetSelector.java index eecd8ecf4..aa13687fa 100755 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionDotCallTargetSelector.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/JavaScriptFunctionDotCallTargetSelector.java @@ -48,7 +48,7 @@ public class JavaScriptFunctionDotCallTargetSelector implements MethodTargetSele public static final boolean DEBUG_SYNTHETIC_CALL_METHODS = false; - private static final TypeName CALL_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/functionCall"); + private static final TypeName CALL_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_call"); private final MethodTargetSelector base; public JavaScriptFunctionDotCallTargetSelector(MethodTargetSelector base) { diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationFinder.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationFinder.java index a065da1d2..254de5034 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationFinder.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationFinder.java @@ -77,7 +77,7 @@ public class CorrelationFinder { private final JavaScriptTranslatorFactory translatorFactory; @SuppressWarnings("unused") - private CorrelationSummary findCorrelatedAccesses(IMethod method, IR ir) { + public static CorrelationSummary findCorrelatedAccesses(IMethod method, IR ir) { AstMethod astMethod = (AstMethod)method; DefUse du = new DefUse(ir); OrdinalSetMapping instrIndices = new ObjectArrayMapping(ir.getInstructions()); @@ -160,7 +160,7 @@ public class CorrelationFinder { // tries to determine which source level variable an SSA variable corresponds to // if it does not correspond to any variable, or to more than one, null is returned - private String getSourceLevelName(AstMethod astMethod, int v) { + private static String getSourceLevelName(AstMethod astMethod, int v) { String indexName = null; String[][] sourceNamesForValues = astMethod.debugInfo().getSourceNamesForValues(); @@ -178,7 +178,7 @@ public class CorrelationFinder { return indexName; } - private Set getSourceLevelNames(AstMethod astMethod, IntSet vs) { + private static Set getSourceLevelNames(AstMethod astMethod, IntSet vs) { Set res = new HashSet(); for(IntIterator iter=vs.intIterator();iter.hasNext();) { String name = getSourceLevelName(astMethod, iter.next()); @@ -189,7 +189,7 @@ public class CorrelationFinder { } // checks whether the given SSA variable must always be assigned a numeric value - private boolean mustBeNumeric(IR ir, DefUse du, int v) { + private static boolean mustBeNumeric(IR ir, DefUse du, int v) { LinkedList worklist = new LinkedList(); MutableIntSet done = new BitVectorIntSet(); worklist.add(v); diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationSummary.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationSummary.java index f7b51dacd..1f3b930bb 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationSummary.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/CorrelationSummary.java @@ -52,6 +52,10 @@ public final class CorrelationSummary { public Set getCorrelations() { return correlations; } + + public boolean isEmpty() { + return correlations.isEmpty(); + } public SSASourcePositionMap getPositions() { return positions; diff --git a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/CorrelatedPairExtractorFactory.java b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/CorrelatedPairExtractorFactory.java index e8052a01a..4cacfaa3d 100644 --- a/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/CorrelatedPairExtractorFactory.java +++ b/com.ibm.wala.cast.js/source/com/ibm/wala/cast/js/ipa/callgraph/correlations/extraction/CorrelatedPairExtractorFactory.java @@ -37,7 +37,7 @@ public class CorrelatedPairExtractorFactory implements CAstRewriterFactory createCAstRewriter(CAst ast) { + public ClosureExtractor createCAstRewriter(CAst ast) { ExtractionPolicyFactory policyFactory = new ExtractionPolicyFactory() { @Override public ExtractionPolicy createPolicy(CAstEntity entity) {