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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/handlebars/engine/function.rb +27 -0
- data/lib/handlebars/engine/version.rb +1 -1
- data/lib/handlebars/engine.rb +2 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93107a1a86ac4a02cadbbfd8221cba9515ff839e948e39dc37c61a3de1d15400
|
4
|
+
data.tar.gz: '0091362554954a3f86ab24b7c0bc701595818b9b72af4b8780bccd3d6e4193ec'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/handlebars/engine.rb
CHANGED
@@ -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 =
|
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.
|
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-
|
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
|