<commit_before>#ifndef RDB_PROTOCOL_TERMS_JS_HPP_
#define RDB_PROTOCOL_TERMS_JS_HPP_

#include <string>

#include "errors.hpp"
#include <boost/variant/static_visitor.hpp>

#include "rdb_protocol/op.hpp"
#include "rdb_protocol/error.hpp"
#include "rdb_protocol/js.hpp"

namespace ql {

static const char *const js_optargs[] = {"timeout"};
class javascript_term_t : public op_term_t {
public:
    javascript_term_t(env_t *env, const Term *term)
        : op_term_t(env, term, argspec_t(1), optargspec_t(js_optargs)) { }
private:

    virtual val_t *eval_impl() {
        std::string source = arg(0)->as_datum()->as_str();

        boost::shared_ptr<js::runner_t> js = env->get_js_runner();

        // Optarg seems designed to take a default vaule as the second argument
        // but nowhere else is this actually used.
        double timeout_s = 5.0;
        val_t *timeout_opt = optarg("timeout", NULL);
        if (timeout_opt) {
            timeout_s = timeout_opt->as_num();
        }

        // JS runner configuration is limited to setting an execution timeout.
        js::runner_t::req_config_t config;
        config.timeout_ms = timeout_s * 1000;

        try {
            js::js_result_t result = js->eval(source, &config);
            return boost::apply_visitor(js_result_visitor_t(env, this), result);
        } catch (const interrupted_exc_t &e) {
            rfail("JavaScript query \"%s\" timed out after "DBLPRI" seconds", source.c_str(), timeout_s);
        }

    }
    virtual const char *name() const { return "javascript"; }

    // No JS term is considered deterministic
    virtual bool is_deterministic_impl() const {
        return false;
    }
};

}

#endif // RDB_PROTOCOL_TERMS_JS_HPP_<commit_msg>changes JS timeout reporting again to use narrower precision<commit_after>#ifndef RDB_PROTOCOL_TERMS_JS_HPP_
#define RDB_PROTOCOL_TERMS_JS_HPP_

#include <string>

#include "errors.hpp"
#include <boost/variant/static_visitor.hpp>

#include "rdb_protocol/op.hpp"
#include "rdb_protocol/error.hpp"
#include "rdb_protocol/js.hpp"

namespace ql {

static const char *const js_optargs[] = {"timeout"};
class javascript_term_t : public op_term_t {
public:
    javascript_term_t(env_t *env, const Term *term)
        : op_term_t(env, term, argspec_t(1), optargspec_t(js_optargs)) { }
private:

    virtual val_t *eval_impl() {
        std::string source = arg(0)->as_datum()->as_str();

        boost::shared_ptr<js::runner_t> js = env->get_js_runner();

        // Optarg seems designed to take a default vaule as the second argument
        // but nowhere else is this actually used.
        double timeout_s = 5.0;
        val_t *timeout_opt = optarg("timeout", NULL);
        if (timeout_opt) {
            timeout_s = timeout_opt->as_num();
        }

        // JS runner configuration is limited to setting an execution timeout.
        js::runner_t::req_config_t config;
        config.timeout_ms = timeout_s * 1000;

        try {
            js::js_result_t result = js->eval(source, &config);
            return boost::apply_visitor(js_result_visitor_t(env, this), result);
        } catch (const interrupted_exc_t &e) {
            rfail("JavaScript query \"%s\" timed out after %.2G seconds", source.c_str(), timeout_s);
        }

    }
    virtual const char *name() const { return "javascript"; }

    // No JS term is considered deterministic
    virtual bool is_deterministic_impl() const {
        return false;
    }
};

}

#endif // RDB_PROTOCOL_TERMS_JS_HPP_
{'fraction_non_alphanumeric': 0.11247502141021981, 'fraction_numerical': 0.004852983157293748, 'mean_word_length': 3.1223529411764708, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4414522', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1125, 'n_words': 281}