JSSEEK – Javascript Error Generator – Why?



JSSEEK – Javascript Error Generator – Why?

1 0


jsseek-presentation


On Github danielconnor / jsseek-presentation

JSSEEK

Javascript Error Generator

Daniel Connor - C00137906

IT Carlow - 22/03/2013

What?

A javascript error generator that takes a function as input and creates test cases to show any errors that can be found

Uses

  • Integration into an IDE or text editor.
  • As part of a test suite or build process.

Similar tools

  • Static analysers such as
  • Hand coded tests.
  • Code coverage tools.

Why?

Javascript

  • Dynamic typing
  • Type coercion
  • Objects that act like hash maps
  • Prototypal inheritance

Dynamic Typing

Variables can contain any type of value.

var a;
a = 1;  // number
a = ""; // string
a = {}; // object
a = []; // array
a = /^regular expression$/g; // regular expression
						

Dynamic Objects

  • Objects act something like hashmaps.
  • Properties can be added and removed
var a = {};
a.property = "a string";

function example(a) {
	// checking if a will have a certain property
	if(a.property != null) {
		// do something...
	}
}
						

Type Errors

TypeErrors are the most common type of error.

function example(callback) {
	//do something

	callback();
}
						

Possible Solution

TypeScript - By Microsoft
function greeter(person: string) {
		return "Hello, " + person;
}

var user = "Jane User";

document.body.innerHTML = greeter(user);
						

Type Coercion

Values can be coerced to perform operations on different types.

"1" + 2 + 3 = "123"
"3" - 1 = 2
null == undefined
						

Symbolic Execution

Execution of a program using symbolic values rather than real ones.

Symbolic Execution - Problems

  • Loops
  • Path explosion
  • Representation of multiple types
  • Strings and Arrays

Example

function example(obj) {
	if(obj != null) {
		if(obj.prop == null) {
			obj.prop = {};
		}
		obj.prop.value = 10;
	}
}
						

Technology

  • ptc-solver - number constraint solving
  • Javascript - Node.js
  • esprima.js - Parser

Questions?