Class: SMemory

SMemory

new SMemory()

SMemory associates a unique object with every JavaScript object, function, and activation frame during an execution. (Note that a shadow object cannot associated with primitive values, undefined, or null.) A shadow object can be used to store meta-information about an object (e.g. the location at which the object was created). Each shadow object has an unique id, which can be treated as the logical address of the corresponding JavaScript object or activation frame.

To use smemory, one must include --analysis $JALANGI_HOME/src/js/sample_analyses/ChainedAnalyses.js --analysis $JALANGI_HOME/src/js/runtime/SMemory.js as the first two --analysis options during an analysis. smemory can be accessed via J$.smemory or sandbox.smemory. The smemory object defines several methods. Those methods can be used to obtain the shadow memory for an object property or a program variable, respectively. getShadowObject should be used in getFieldPre, putFieldPre, and literal callbacks. (In a literal callback with an object literal, one must go over all the own properties of the literal object to suitably update shadow object.) getShadowFrame should only be used in declare, read, and write callbacks.

Methods

getActualObjectOrFunctionFromShadowObjectOrFrame(obj){*}

Given a shadow object, it returns the actual object. Given a shadow frame, it returns the function whose invocation created the frame.
Name Type Description
obj
Returns:
Type Description
*

getFrame(name){Object}

This method returns the shadow object associated with the activation frame that contains the variable "name". To get the current activation frame, call J$.smemory.getFrame("this");
Name Type Description
name Name of the variable whose owner activation frame's shadow object we want to retrieve
Returns:
Type Description
Object - The shadow object of the activation frame owning the variable.

getIDFromShadowObjectOrFrame(obj){number|undefined}

Given a shadow object or frame, it returns the unique id of the shadow object or frame. It returns undefined, if obj is undefined, null, or not a valid shadow object.
Name Type Description
obj
Returns:
Type Description
number | undefined

getShadowFrame(name){Object}

This method returns the shadow object associated with the activation frame that contains the variable "name".
Name Type Description
name Name of the variable whose owner activation frame's shadow object we want to retrieve
Returns:
Type Description
Object - The shadow object of the activation frame owning the variable.

getShadowObject(obj, prop, isGetField){Object}

This method should be called on a base object and a property name to retrieve the shadow object associated with the object that actually owns the property. When the program performs a putField operation, the third argument should be false and the returned object is the shadow object associated with the base object. When the program performs a getField operation, the third argument should be true and the returned object is the shadow object associated with the object in the prototype chain (or the base object) which owns the property. For a getField operation, the returned value is undefined if none of the objects in the prototype chain owns the property. The return value is an object with two properties: "owner" points to the shadow object and "isProperty" indicates if the property is a concrete property of the object or if the property denotes a getter/setter.
Name Type Description
obj The base object
prop The property name
isGetField True if the property access is a getField operation
Returns:
Type Description
Object

getShadowObjectOfObject(val){Object|undefined}

This method returns the shadow object associated with the argument. If the argument cannot be associated with a shadow object, the function returns undefined.
Name Type Description
val The object whose shadow object the function returns
Returns:
Type Description
Object | undefined - Returns the shadow object associated with val. Return undefined if there is no shadow object assocaited with val Note that a shadow object cannot be associated with a primitive value: number, string, boolean, undefined, or null.