We will be at OWASP APPSEC EUROPE 2017 - Belfast! Let’s talk!MORE INFO

Help Center

Get to know more about our API, Code Annotations and Code Transformations

Assertions Removal

Potency
0 / 3
Resilience
5 / 5
Cost
0 / 5

Tags: assertion,elimination,removal,optimization,assert

Description

An assertion is a statement that contains a test predicate (a true-false
expression) which is expected to always be true, otherwise the assertion will
fail. Typically, assertions are turned off when the code is deployed to
production to avoid any side effects and reduce performance impact. This
transformation can be used to remove all assertions from the production code
including their function declarations.

Example

The following example contains some assertions that will be removed by the
transformation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function assert(result, description) {
// assert code
}
function a() {
// code block
}
function b() {
// code block
}
function c() {
// code block
}
var d = 1;
assert(d === 1);
d += 2;
assert(d > 1, 'd is greater than 1');

Adding assert to the names list removes any function declaration and
function call with that name:

1
2
3
4
5
6
7
8
9
10
11
12
13
function a() {
// code block
}
function b() {
// code block
}
function c() {
// code block
}
var d = 1;
d += 2;

Option Types

Name Required Default Value Description
names Yes [] List containing the names of the assertions to be removed. Each name can be provided as a string or as a regular expression.

API Parameters

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"keys": {
"accessKey": "XXXXXX",
"secretKey": "YYYYYY"
},
"applicationId": "ZZZZZZ",
"params": [
{
"name": "assertionsRemoval",
"options": {
"names": []
}
}
]
}