<commit_before>import math
import re
import types

import spidermonkey
import instanceactions
import instanceproperties
from appvalidator.python.copy import deepcopy
from appvalidator.constants import (BUGZILLA_BUG, DESCRIPTION_TYPES,
                                    MAX_STR_SIZE)
from jstypes import *


NUMERIC_TYPES = (int, long, float, complex)

# None of these operations (or their augmented assignment counterparts) should
# be performed on non-numeric data. Any time we get non-numeric data for these
# guys, we just return window.NaN.
NUMERIC_OPERATORS = ("-", "*", "/", "%", "<<", ">>", ">>>", "|", "^", "&")
NUMERIC_OPERATORS += tuple("%s=" % op for op in NUMERIC_OPERATORS)


def get_NaN(traverser):
    # If we've cached the traverser's NaN instance, just use that.
    ncache = getattr(traverser, "NAN_CACHE", None)
    if ncache is not None:
        return ncache

    # Otherwise, we need to import GLOBAL_ENTITIES and build a raw copy.
    from predefinedentities import GLOBAL_ENTITIES
    ncache = traverser._build_global("NaN", GLOBAL_ENTITIES[u"NaN"])
    # Cache it so we don't need to do this again.
    traverser.NAN_CACHE = ncache
    return ncache


def _get_member_exp_property(traverser, node):
    """Return the string value of a member expression's property."""

    if node["property"]["type"] == "Identifier" and not node["computed"]:
        return unicode(node["property"]["name"])
    else:
        eval_exp = traverser._traverse_node(node["property"])
        return _get_as_str(eval_exp.get_literal_value())


def _expand_globals(traverser, node):
    """Expands a global object that has a lambda value."""
    
    if not isinstance(node, JSWrapper):
        return node

    if node.is_global and callable(node.value.get("value")):

        result = node.value["value"](t=traverser)
        if isinstance(result, dict):
            output = traverser._build_global("--", result)
        elif isinstance(result, JSWrapper):
            output = result
        else:
            output = JSWrapper(result, traverser)

        return output<commit_msg>Wrap unwrapped globals when expanded<commit_after>import math
import re
import types

import spidermonkey
import instanceactions
import instanceproperties
from appvalidator.python.copy import deepcopy
from appvalidator.constants import (BUGZILLA_BUG, DESCRIPTION_TYPES,
                                    MAX_STR_SIZE)
from jstypes import *


NUMERIC_TYPES = (int, long, float, complex)

# None of these operations (or their augmented assignment counterparts) should
# be performed on non-numeric data. Any time we get non-numeric data for these
# guys, we just return window.NaN.
NUMERIC_OPERATORS = ("-", "*", "/", "%", "<<", ">>", ">>>", "|", "^", "&")
NUMERIC_OPERATORS += tuple("%s=" % op for op in NUMERIC_OPERATORS)


def get_NaN(traverser):
    # If we've cached the traverser's NaN instance, just use that.
    ncache = getattr(traverser, "NAN_CACHE", None)
    if ncache is not None:
        return ncache

    # Otherwise, we need to import GLOBAL_ENTITIES and build a raw copy.
    from predefinedentities import GLOBAL_ENTITIES
    ncache = traverser._build_global("NaN", GLOBAL_ENTITIES[u"NaN"])
    # Cache it so we don't need to do this again.
    traverser.NAN_CACHE = ncache
    return ncache


def _get_member_exp_property(traverser, node):
    """Return the string value of a member expression's property."""

    if node["property"]["type"] == "Identifier" and not node["computed"]:
        return unicode(node["property"]["name"])
    else:
        eval_exp = traverser._traverse_node(node["property"])
        return _get_as_str(eval_exp.get_literal_value())


def _expand_globals(traverser, node):
    """Expands a global object that has a lambda value."""
    
    if not isinstance(node, JSWrapper):
        return JSWrapper(node, traverser=traverser)

    if node.is_global and callable(node.value.get("value")):

        result = node.value["value"](t=traverser)
        if isinstance(result, dict):
            output = traverser._build_global("--", result)
        elif isinstance(result, JSWrapper):
            output = result
        else:
            output = JSWrapper(result, traverser)

        return output
{'fraction_non_alphanumeric': 0.10856738258201558, 'fraction_numerical': 0.0, 'mean_word_length': 3.442348008385744, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4729741', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1268, 'n_words': 378}