<commit_before>//
// SessionWrapper.cpp
//
// $Id$
//
// Copyright (c) 2015-2016, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: Apache-2.0
//


#include "SessionWrapper.h"
#include "Poco/OSP/ServiceRegistry.h"
#include "Poco/OSP/ServiceFinder.h"
#include "Poco/OSP/Auth/AuthService.h"


namespace Poco {
namespace OSP {
namespace JS {
namespace Web {


SessionWrapper::SessionWrapper()
{
}


SessionWrapper::~SessionWrapper()
{
}


v8::Handle<v8::ObjectTemplate> SessionWrapper::objectTemplate(v8::Isolate* pIsolate)
{
	v8::EscapableHandleScope handleScope(pIsolate);
	v8::Local<v8::ObjectTemplate> bundleTemplate = v8::ObjectTemplate::New();
	bundleTemplate->SetInternalFieldCount(1);
	bundleTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "id"), id);
	bundleTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "username"), username);
	bundleTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "authenticated"), authenticated);
	bundleTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "csrfToken"), csrfToken);
	bundleTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "clientAddress"), clientAddress);
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "setInt"), v8::FunctionTemplate::New(pIsolate, setInt));
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "getInt"), v8::FunctionTemplate::New(pIsolate, getInt));
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "setString"), v8::FunctionTemplate::New(pIsolate, setString));
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "getString"), v8::FunctionTemplate::New(pIsolate, getString));
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "erase"), v8::FunctionTemplate::New(pIsolate, erase));
	bundleTemplate->Set(v8::String::NewFromUtf8(pIsolate, "authorize"), v8::FunctionTemplate::New(pIsolate, authorize));
	return handleScope.Escape(bundleTemplate);
}

<commit_msg>fixed a memory leak issue with SessionWrapper: a new object template would be created for each new HTTP request having a session, instead of using the object template pooling mechanism, causing the JS heap to grow with each request<commit_after>//
// SessionWrapper.cpp
//
// $Id$
//
// Copyright (c) 2015-2016, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: Apache-2.0
//


#include "SessionWrapper.h"
#include "Poco/OSP/ServiceRegistry.h"
#include "Poco/OSP/ServiceFinder.h"
#include "Poco/OSP/Auth/AuthService.h"
#include "Poco/JS/Core/PooledIsolate.h"


namespace Poco {
namespace OSP {
namespace JS {
namespace Web {


SessionWrapper::SessionWrapper()
{
}


SessionWrapper::~SessionWrapper()
{
}


v8::Handle<v8::ObjectTemplate> SessionWrapper::objectTemplate(v8::Isolate* pIsolate)
{
	v8::EscapableHandleScope handleScope(pIsolate);
	Poco::JS::Core::PooledIsolate* pPooledIso = Poco::JS::Core::PooledIsolate::fromIsolate(pIsolate);
	poco_check_ptr (pPooledIso);
	v8::Persistent<v8::ObjectTemplate>& pooledSessionTemplate(pPooledIso->objectTemplate("Web.Session"));
	if (pooledSessionTemplate.IsEmpty())
	{
		v8::Local<v8::ObjectTemplate> sessionTemplate = v8::ObjectTemplate::New();
		sessionTemplate->SetInternalFieldCount(1);
		sessionTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "id"), id);
		sessionTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "username"), username);
		sessionTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "authenticated"), authenticated);
		sessionTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "csrfToken"), csrfToken);
		sessionTemplate->SetAccessor(v8::String::NewFromUtf8(pIsolate, "clientAddress"), clientAddress);
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "setInt"), v8::FunctionTemplate::New(pIsolate, setInt));
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "getInt"), v8::FunctionTemplate::New(pIsolate, getInt));
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "setString"), v8::FunctionTemplate::New(pIsolate, setString));
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "getString"), v8::FunctionTemplate::New(pIsolate, getString));
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "erase"), v8::FunctionTemplate::New(pIsolate, erase));
		sessionTemplate->Set(v8::String::NewFromUtf8(pIsolate, "authorize"), v8::FunctionTemplate::New(pIsolate, authorize));
		pooledSessionTemplate.Reset(pIsolate, sessionTemplate);
	}
	v8::Local<v8::ObjectTemplate> sessionTemplate = v8::Local<v8::ObjectTemplate>::New(pIsolate, pooledSessionTemplate);
	return handleScope.Escape(sessionTemplate);
}


{'fraction_non_alphanumeric': 0.15959991302457055, 'fraction_numerical': 0.0213089802130898, 'mean_word_length': 9.176991150442477, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 35, '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': '4728305', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1534, 'n_words': 221}