handlebars-engine 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2de45a7681908a24300e3a25cbe7c21b4d8d5b298dc82b53bc3edaef26f55bb4
4
- data.tar.gz: d2afacff1230d65503a5b0c122b6a95dd53938d0fd42c04c371862024c846535
3
+ metadata.gz: 93107a1a86ac4a02cadbbfd8221cba9515ff839e948e39dc37c61a3de1d15400
4
+ data.tar.gz: '0091362554954a3f86ab24b7c0bc701595818b9b72af4b8780bccd3d6e4193ec'
5
5
  SHA512:
6
- metadata.gz: 49847c2af822e87e0ee9172f3f8e70a53d7fcd14aa957e5143bce1f501582f95bf4fe9fc03e93a261843a6f98a15c6a82537430ebc415dc7b5e20511cb9930d0
7
- data.tar.gz: 040e2931e222abf524d8379ff8b079354b292a31be9c5ce8097ccfbe154989cbf8233c9602d2319b4502f54b2828ad2063665512bd996416eaf0c47fcc1af1ac
6
+ metadata.gz: 7cd86ebb6fbeb64acd29dc3c4cb0f6853a7193983c53e05d32e42490a38b70f37c8d99ae7b214e3f76923c7931b46c1d3dcda1326339dfcdfa00ec29be745ae9
7
+ data.tar.gz: 6f5fd77a08e73e9f2b9f40c1c769f2eca5a0359a35e9aa02ca9fd7d430e83e8f61d6c26541f0b2bbaf5caf3ff990663962cdedfc5dd61e8892c842a8b6404fec
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.2] - 2022-02-17
11
+
12
+ ### Changed
13
+ - `engine`: fixed issue with memory leak ([#15](https://github.com/gi/handlebars-ruby/pull/15))
14
+
10
15
  ## [0.3.1] - 2022-02-04
11
16
 
12
17
  ### Added
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Handlebars
4
+ class Engine
5
+ # A proxy for a JavaScript function defined in the context.
6
+ class Function
7
+ def initialize(context, name)
8
+ @context = context
9
+ @name = name
10
+ ObjectSpace.define_finalizer(self, self.class.finalizer(context, name))
11
+ end
12
+
13
+ def call(*args)
14
+ @context.call(@name, *args)
15
+ end
16
+
17
+ def self.finalizer(context, name)
18
+ proc {
19
+ begin
20
+ context.eval("delete #{name}")
21
+ rescue ThreadError # rubocop:disable Lint/SuppressedException
22
+ end
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Handlebars
4
4
  class Engine
5
- VERSION = "0.3.1"
5
+ VERSION = "0.3.2"
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@ require "handlebars/source"
4
4
  require "json"
5
5
  require "mini_racer"
6
6
  require "securerandom"
7
+ require_relative "engine/function"
7
8
  require_relative "engine/version"
8
9
 
9
10
  module Handlebars
@@ -199,9 +200,7 @@ module Handlebars
199
200
  result = evaluate(code)
200
201
 
201
202
  if var && result.is_a?(MiniRacer::JavaScriptFunction)
202
- result = ->(*a) { @context.call(var, *a) }
203
- finalizer = ->(*) { evaluate("delete #{var}") }
204
- ObjectSpace.define_finalizer(result, finalizer)
203
+ result = Function.new(@context, var)
205
204
  end
206
205
 
207
206
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handlebars-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Gianos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-05 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-source
@@ -61,6 +61,7 @@ files:
61
61
  - exe/handlebars
62
62
  - lib/handlebars-engine.rb
63
63
  - lib/handlebars/engine.rb
64
+ - lib/handlebars/engine/function.rb
64
65
  - lib/handlebars/engine/init.js
65
66
  - lib/handlebars/engine/version.rb
66
67
  homepage: https://github.com/gi/handlebars-ruby