'Lint the JavaScript contexts for JavaScript violations inside a Mako
template.
Arguments:
mako_template: The contents of the Mako template.
contexts: A list of context dicts with \'type\' and \'index\'.
results: A list of results into which violations will be added.
Side effect:
Adds JavaScript violations to results.'

def _check_javascript_contexts(self, mako_template, contexts, results):

    javascript_start_index = None
    for context in contexts:
        if (context['type'] == 'javascript'):
            if (javascript_start_index < 0):
                javascript_start_index = context['index']
        elif (javascript_start_index is not None):
            javascript_end_index = context['index']
            javascript_code = mako_template[javascript_start_index:javascript_end_index]
            self._check_javascript_context(javascript_code, javascript_start_index, results)
            javascript_start_index = None
    if (javascript_start_index is not None):
        javascript_code = mako_template[javascript_start_index:]
        self._check_javascript_context(javascript_code, javascript_start_index, results)
