<commit_before>#include "NodeTools.h"

v8::Persistent<v8::Object> thisModule;

template<>
std::vector<std::string> FromJsValue<std::vector<std::string> >( const v8::Local<v8::Value>& value )
{
    std::vector<std::string> result;

    if( value->IsArray() ) {
        v8::Local<v8::Array> jsArray = v8::Local<v8::Array>::Cast( value );

        for( unsigned i = 0 ; i < jsArray->Length(); ++i ) {
            v8::String::Utf8Value item( jsArray->Get(i)->ToString() );
            if( item.length() ) {
                result.emplace( result.end(), *item );
            }
        }
    }

    return std::move( result );
}

v8::Local<v8::Function> RequireFunc()
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    Local<Object> global = isolate->GetCurrentContext()->Global();

    return
        Local<Function>::Cast(
            global->Get(
                String::NewFromUtf8( isolate,
                                     "require",
                                     String::kInternalizedString ) ) );
}

v8::Local<v8::Object> Require( const char* module )
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    Local<Object> global = isolate->GetCurrentContext()->Global();

    Local<Value> argv[] =
        { String::NewFromUtf8( isolate, module, String::kInternalizedString ) };
<commit_msg>use current module for "require" access<commit_after>#include "NodeTools.h"

v8::Persistent<v8::Object> thisModule;

template<>
std::vector<std::string> FromJsValue<std::vector<std::string> >( const v8::Local<v8::Value>& value )
{
    std::vector<std::string> result;

    if( value->IsArray() ) {
        v8::Local<v8::Array> jsArray = v8::Local<v8::Array>::Cast( value );

        for( unsigned i = 0 ; i < jsArray->Length(); ++i ) {
            v8::String::Utf8Value item( jsArray->Get(i)->ToString() );
            if( item.length() ) {
                result.emplace( result.end(), *item );
            }
        }
    }

    return std::move( result );
}

v8::Local<v8::Function> RequireFunc()
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    Local<Object> module = Local<Object>::New( Isolate::GetCurrent(), ::thisModule );

    return
        Local<Function>::Cast(
            module->Get(
                String::NewFromUtf8( isolate,
                                     "require",
                                     String::kInternalizedString ) ) );
}

v8::Local<v8::Object> Require( const char* module )
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    Local<Object> global = isolate->GetCurrentContext()->Global();

    Local<Value> argv[] =
        { String::NewFromUtf8( isolate, module, String::kInternalizedString ) };

{'fraction_non_alphanumeric': 0.1634510374954496, 'fraction_numerical': 0.01383327266108482, 'mean_word_length': 2.6205533596837944, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3780429', 'n_tokens_mistral': 865, 'n_tokens_neox': 825, 'n_words': 155}