<commit_before>#include "ArgConverter.h"
#include "ObjectManager.h"
#include "JniLocalRef.h"
#include "Util.h"
#include "V8GlobalHelpers.h"
#include "V8StringConstants.h"
#include "NativeScriptAssert.h"
#include <assert.h>
#include <sstream>
#include <cstdlib>

using namespace v8;
using namespace std;
using namespace tns;

void ArgConverter::Init(JavaVM *jvm)
{
	ArgConverter::jvm = jvm;

	auto isolate = Isolate::GetCurrent();

	auto ft = FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongFunctionCallback);
	ft->SetClassName(V8StringConstants::GetLongNumber());
	ft->InstanceTemplate()->Set(V8StringConstants::GetValueOf(), FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongValueOfFunctionCallback));
	ft->InstanceTemplate()->Set(V8StringConstants::GetToString(), FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongToStringFunctionCallback));
	NATIVESCRIPT_NUMERA_CTOR_FUNC = new Persistent<Function>(isolate, ft->GetFunction());

	auto nanObject = Number::New(isolate, numeric_limits<double>::quiet_NaN()).As<NumberObject>();
	NAN_NUMBER_OBJECT = new Persistent<NumberObject>(isolate, nanObject);

	JEnv env;

	STRING_CLASS = env.FindClass("java/lang/String");
	assert(STRING_CLASS != nullptr);

	GET_BYTES_METHOD_ID = env.GetMethodID(STRING_CLASS, "getBytes", "(Ljava/lang/String;)[B");
	assert(GET_BYTES_METHOD_ID != nullptr);

	JniLocalRef encoding(env.NewStringUTF("UTF-8"));
	UTF_8_ENCODING = (jstring)env.NewGlobalRef(encoding);
	assert(UTF_8_ENCODING != nullptr);
}

void ArgConverter::NativeScriptLongValueOfFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	auto isolate = Isolate::GetCurrent();
	args.GetReturnValue().Set(Number::New(isolate, numeric_limits<double>::quiet_NaN()));
}

void ArgConverter::NativeScriptLongToStringFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	args.GetReturnValue().Set(args.This()->Get(V8StringConstants::GetValue()));
}

void ArgConverter::NativeScriptLongFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	auto isolate = Isolate::GetCurrent();
	args.This()->SetHiddenValue(V8StringConstants::GetJavaLong(), Boolean::New(isolate, true));
	args.This()->SetHiddenValue(ConvertToV8String(V8StringConstants::MARKED_AS_LONG), args[0]);
	args.This()->Set(V8StringConstants::GetValue(), args[0]);

	args.This()->SetPrototype(Local<NumberObject>::New(Isolate::GetCurrent(), *NAN_NUMBER_OBJECT));
}


jlong ArgConverter::ObjectToLong(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "longValue", "()J");

	return env.CallLongMethod(object, methodID);
}

jboolean ArgConverter::ObjectToBoolean(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "booleanValue", "()Z");

	return env.CallBooleanMethod(object, methodID);
}

jchar ArgConverter::ObjectToChar(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "characterValue", "()C");

	return env.CallCharMethod(object, methodID);
}


jbyte ArgConverter::ObjectToByte(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "byteValue", "()B");

	return env.CallByteMethod(object, methodID);
}

jshort ArgConverter::ObjectToShort(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup<commit_msg>fix issue #64<commit_after>#include "ArgConverter.h"
#include "ObjectManager.h"
#include "JniLocalRef.h"
#include "Util.h"
#include "V8GlobalHelpers.h"
#include "V8StringConstants.h"
#include "NativeScriptAssert.h"
#include <assert.h>
#include <sstream>
#include <cstdlib>

using namespace v8;
using namespace std;
using namespace tns;

void ArgConverter::Init(JavaVM *jvm)
{
	ArgConverter::jvm = jvm;

	auto isolate = Isolate::GetCurrent();

	auto ft = FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongFunctionCallback);
	ft->SetClassName(V8StringConstants::GetLongNumber());
	ft->InstanceTemplate()->Set(V8StringConstants::GetValueOf(), FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongValueOfFunctionCallback));
	ft->InstanceTemplate()->Set(V8StringConstants::GetToString(), FunctionTemplate::New(isolate, ArgConverter::NativeScriptLongToStringFunctionCallback));
	NATIVESCRIPT_NUMERA_CTOR_FUNC = new Persistent<Function>(isolate, ft->GetFunction());

	auto nanObject = Number::New(isolate, numeric_limits<double>::quiet_NaN()).As<NumberObject>();
	NAN_NUMBER_OBJECT = new Persistent<NumberObject>(isolate, nanObject);

	JEnv env;

	STRING_CLASS = env.FindClass("java/lang/String");
	assert(STRING_CLASS != nullptr);

	GET_BYTES_METHOD_ID = env.GetMethodID(STRING_CLASS, "getBytes", "(Ljava/lang/String;)[B");
	assert(GET_BYTES_METHOD_ID != nullptr);

	JniLocalRef encoding(env.NewStringUTF("UTF-8"));
	UTF_8_ENCODING = (jstring)env.NewGlobalRef(encoding);
	assert(UTF_8_ENCODING != nullptr);
}

void ArgConverter::NativeScriptLongValueOfFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	auto isolate = Isolate::GetCurrent();
	args.GetReturnValue().Set(Number::New(isolate, numeric_limits<double>::quiet_NaN()));
}

void ArgConverter::NativeScriptLongToStringFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	args.GetReturnValue().Set(args.This()->Get(V8StringConstants::GetValue()));
}

void ArgConverter::NativeScriptLongFunctionCallback(const v8::FunctionCallbackInfo<Value>& args)
{
	auto isolate = Isolate::GetCurrent();
	args.This()->SetHiddenValue(V8StringConstants::GetJavaLong(), Boolean::New(isolate, true));
	args.This()->SetHiddenValue(ConvertToV8String(V8StringConstants::MARKED_AS_LONG), args[0]);
	args.This()->Set(V8StringConstants::GetValue(), args[0]);

	args.This()->SetPrototype(Local<NumberObject>::New(Isolate::GetCurrent(), *NAN_NUMBER_OBJECT));
}


jlong ArgConverter::ObjectToLong(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "longValue", "()J");

	return env.CallLongMethod(object, methodID);
}

jboolean ArgConverter::ObjectToBoolean(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "booleanValue", "()Z");

	return env.CallBooleanMethod(object, methodID);
}

jchar ArgConverter::ObjectToChar(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "charValue", "()C");

	return env.CallCharMethod(object, methodID);
}


jbyte ArgConverter::ObjectToByte(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
	jmethodID methodID = env.GetMethodID(argClass, "byteValue", "()B");

	return env.CallByteMethod(object, methodID);
}

jshort ArgConverter::ObjectToShort(jobject object)
{
	JEnv env;

	JniLocalRef argClass(env.GetObjectClass(object));

	//TODO: Lubo: cache this methodId on startup
{'fraction_non_alphanumeric': 0.13963782696177063, 'fraction_numerical': 0.0053655264922870555, 'mean_word_length': 8.595881595881595, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 49, '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': '7286707', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2387, 'n_words': 421}