<commit_before>use v6;
use BSON::EDCTools;

package BSON {

  class Javascript {

    has Str $.javascript;
    has $.scope;

    has Bool $.has-javascript = False;
    has Bool $.has-scope = False;

    #---------------------------------------------------------------------------
    #
    submethod BUILD ( Str:D :$javascript, :$scope ) {

      # Store the attribute values. ? sets True if defined and filled.
      #
      $!javascript = $javascript;
      $!scope = $scope;

      $!has-javascript = ?$!javascript;
      $!has-scope = ?$!scope if $scope.^name ~~ 'BSON::Document';
    }

    #---------------------------------------------------------------------------
    #
    method encode-javascript ( Str $key-name, $bson-obj --> Buf ) {
      if $!has-javascript {
        my Buf $js = encode-string($!javascript);

        if $!has-scope {
          my Buf $doc = $bson-obj.encode-document($!scope);
          return [~] Buf.new(0x0F), encode-e-name($key-name),
                     encode-int32([+] $js.elems, $doc.elems, 4), $js, $doc;
        }

        else {
          return [~] Buf.new(0x0D), encode-e-name($key-name), $js;
        }
      }

      else {
        die X::BSON::ImProperUse.new( :operation('encode'),
                                      :type('javascript 0x0D/0x0F'),
                                      :emsg('cannot send empty code')
                                    );
      }
    }

    #---------------------------------------------------------------------------
    #
    method decode-javascript ( Array $a, $index is rw --> Pair ) {

      return decode-e-name( $a, $index) =>
        BSON::Javascript.new( :javascript(decode-string( $a, $index)));
    }
  }
}
<commit_msg>removed encoding and decoding from Javascript module. Document doesn't need it. BSON::Bson uses Javascript-old.<commit_after>use v6;
use BSON::EDCTools;

package BSON {

  class Javascript {

    has Str $.javascript;
    has $.scope;

    has Bool $.has-javascript = False;
    has Bool $.has-scope = False;

    #---------------------------------------------------------------------------
    #
    submethod BUILD ( Str:D :$javascript, :$scope ) {

      # Store the attribute values. ? sets True if defined and filled.
      #
      $!javascript = $javascript;
      $!scope = $scope;

      $!has-javascript = ?$!javascript;
      $!has-scope = ?$!scope if $scope.^name ~~ 'BSON::Document';
    }
  }
}

{'fraction_non_alphanumeric': 0.25637860082304526, 'fraction_numerical': 0.005349794238683128, 'mean_word_length': 1.3465250965250966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5865062', 'n_tokens_mistral': 732, 'n_tokens_neox': 687, 'n_words': 165}