<commit_before>#include <v8.h>
#include <node.h>
#include <tcl.h>


using namespace node;
using namespace v8;

class NodeTcl : ObjectWrap
{
private:
  Tcl_Interp *m_interp;
public:

  static Persistent<FunctionTemplate> s_ct;
  static void Init(Handle<Object> target)
  {
    HandleScope scope;

    Local<FunctionTemplate> t = FunctionTemplate::New(New);

    s_ct = Persistent<FunctionTemplate>::New(t);
    s_ct->InstanceTemplate()->SetInternalFieldCount(1);
    s_ct->SetClassName(String::NewSymbol("NodeTcl"));

    NODE_SET_PROTOTYPE_METHOD(s_ct, "eval", Eval);

    target->Set(String::NewSymbol("NodeTcl"), s_ct->GetFunction());
  }

  NodeTcl()
  {
    m_interp = Tcl_CreateInterp();
  }

  ~NodeTcl()
  {
    Tcl_DeleteInterp(m_interp);
    m_interp = NULL;
  }

  static Handle<Value> New(const Arguments& args)
  {
    HandleScope scope;
    NodeTcl* hw = new NodeTcl();
    if (Tcl_Init(hw->m_interp) == TCL_ERROR) {
      return ThrowException(Exception::Error(String::New(Tcl_GetStringResult(hw->m_interp))));
    }
    hw->Wrap(args.This());
    return args.This();
  }

  static Handle<Value> Eval(const Arguments& args)
  {
    HandleScope scope;

    if (args.Length() <= 0 || !args[0]->IsString()) {
      return ThrowException(Exception::TypeError(String::New("Argument must be a string")));
    }

    Local<String> script = Local<String>::Cast(args[0]);
<commit_msg>avoid leaking an object when Tcl_Init fails.<commit_after>#include <v8.h>
#include <node.h>
#include <tcl.h>


using namespace node;
using namespace v8;

class NodeTcl : ObjectWrap
{
private:
  Tcl_Interp *m_interp;
public:

  static Persistent<FunctionTemplate> s_ct;
  static void Init(Handle<Object> target)
  {
    HandleScope scope;

    Local<FunctionTemplate> t = FunctionTemplate::New(New);

    s_ct = Persistent<FunctionTemplate>::New(t);
    s_ct->InstanceTemplate()->SetInternalFieldCount(1);
    s_ct->SetClassName(String::NewSymbol("NodeTcl"));

    NODE_SET_PROTOTYPE_METHOD(s_ct, "eval", Eval);

    target->Set(String::NewSymbol("NodeTcl"), s_ct->GetFunction());
  }

  NodeTcl()
  {
    m_interp = Tcl_CreateInterp();
  }

  ~NodeTcl()
  {
    Tcl_DeleteInterp(m_interp);
    m_interp = NULL;
  }

  static Handle<Value> New(const Arguments& args)
  {
    HandleScope scope;
    NodeTcl* hw = new NodeTcl();
    if (Tcl_Init(hw->m_interp) == TCL_ERROR) {
      Local<String> err = String::New(Tcl_GetStringResult(hw->m_interp));
      delete hw;
      return ThrowException(Exception::Error(err));
    }
    hw->Wrap(args.This());
    return args.This();
  }

  static Handle<Value> Eval(const Arguments& args)
  {
    HandleScope scope;

    if (args.Length() <= 0 || !args[0]->IsString()) {
      return ThrowException(Exception::TypeError(String::New("Argument must be a string")));
    }

    Local<String> script = Local<String>::Cast(args[0]);

{'fraction_non_alphanumeric': 0.14910745537276865, 'fraction_numerical': 0.004200210010500525, 'mean_word_length': 4.177536231884058, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 44, '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': '5466331', 'n_tokens_mistral': 1018, 'n_tokens_neox': 989, 'n_words': 183}