Dynamic Behaviour of the JavaScript Program

Analytics of programs dynamic behaviors using some special technique
Dynamic Behaviour of the JavaScript Program
Source:  Unsplash

For general-purpose computing, JavaScript is an object-oriented and widely used Programming language. Unlike more traditional language such as C#, Java, it does not have classes and does not encourage encapsulation or structured Programming. Instead of JavaScript strives to maximize flexibility. Let’s see how dynamic behaviour of javascript program works.

JavaScript became a general-purpose computing platform with office applications, browsers, and development environments. It is a dubbed version of the “Assembly language” of the internet and targeted by code generators from the likes of java and Scheme. In this response, it started to gain attention and respect.

According to researchers, Security is the most pressing problem because a number of attacks have been discovered that exploit the language’s dynamism.

JavaScript is an imperative, object-oriented language with Java-like syntax, but unlike Java, it employs a prototype-based object system and extremely flexible and it also has some dynamic behaviour.

Some Assumptions about the dynamic behavior of JavaScript —

1. Prototype hierarchy is invariant

Any modification to the prototype hierarchy can potentially impact the control flow graph of the application just as well as the types of affected objects.

2. Properties are added at object initialization

It is embodied by the assumption that most changes to the fields and methods of objects occur at initialization, and thus that it is reasonable to assign an almost complete type to objects at creation, leaving a small number of properties as potential.

3. Properties are rarely deleted

Field or method removal is too difficult to accommodate in type system as it permits non-monotonic evolution of types that break subtyping enforces in modern languages.

4. Usage of eval is infrequent and doesn’t affect the semantics

The usage of eval on arbitrary strings has the potential of string invalidating the results obtained by static type checking.

5. Call site dynamism is low

A huge JavaScript implementation like chrome’s V8 engine relies on javascript programs like creating classed for objects and inline caches.

6. Execution time is dominated by hot loops

A fine compiler like TraceMonkey relies on the traditional assumption that execution time changed by small loops.

7. The industry benchmark is representative of JavaScript’s power

Standard implementation like Spider, Dromaeo are used JavaScript implementation and accuracy of static analytics.

Tracing and analysis Infrastructure:

Your instrumented browser records a trace containing most operations performed by interpreter events for garbage collection and source file loads. Invocations to eval trigger an event similar to the one for source file loads, and the evaluated string is saved and traced like any other part of the program’s execution. Every traces are stored in your storage. While some performance overheated happens on our instrumentation, never shut down this application and users never complained about it so everything analyzes offline and results stored on your storage. It is able to replay any trace creating an abstract representation of the heap state of the corresponding JavaScript program. These techniques like this are often used to work around bugs in the JavaScript library includes the following check for WebKit.

WebKit: ua.indexOf(’AppleWebKit/’) > -1

It then uses that check to create different implementations ofsetOpacity, getRootElement, shouldUseXPath, and other functions that may exhibit browser-dependent behavior.

Measuring Program Dynamism —

1. Call site dynamism

The main feature of Object-oriented Programming is dynamic binding.

Example — for (…) { … = { f : function (x) { return x; } }; }

Dynamic Behaviour of the JavaScript Program
Source

The following code fragmentation will create many objects, that all have a method f(), but each has a different function object bound to f. Naively, one could count calls, x.f(), with different receivers as being polymorphic. We argue that for our purposes it is preferable to count a call site as polymorphic only if it dispatches to a function with a different body, i.e.
calls to clones should be considered monomorphic.

2. Function Variability

The arity of a function in JavaScript doesn’t have to respected by callers. If too few arguments are supplied, the value of the meaning arguments will be set to undefine. If any function can be called with an arbitrary number of arguments and an arbitrary context by using the built-in function declare as variadic.

3. Object Protocol Dynamisms

It is often asserted that although properties can be added to objects at any point, they are generally added only during initial construction, and are later only read and updated. The measure of the number of fields/methods that are added or deleted after initialization is thus likely to be a good metric of the dynamism of JavaScript programs.

Dynamic Behaviour of the JavaScript Program
source

4. Constructor Polymorphism

JavaScript’s mechanism for constructing objects is more dynamic than that of class-based languages because a constructor is simply a function that initializes fields programmatically.

Example — function C(b) { if(b) this.y = 0; else this.x = 0; }

It returns by new c(true) and new c(false) would be different sets of properties. The majority of the constructors always return the same set of properties.

Of course, polymorphism can arise for a lot of reasons, but the common one is the dynamism of JavaScript allows abstract away the details of implementing object hierarchies. A simple function from prototype library —

function C(b) { if(b) this.y = 0; else this.x = 0; }

5. Effect of JavaScript libraries

There are many popular libraries on the market. These libraries provide simplified and well tested coding patterns for problems in UI, Animation, Asynchronous loading, and Class-based prototype system.

Here discuss some from the many behaviors of JavaScript programs. Through this behavior, you know how these assumptions are violating. There are many optimizations require.


Read the official paper here.

Please let me know your thought as a response.

Leave a Reply

Your email address will not be published.