barefoot_js 0.39.2 → 0.39.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/barefoot_js/evaluator.rb +10 -13
- data/lib/barefoot_js.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c580c611349599cee9196a947d183ff3db8bf9e686cddb22f2a89db07b0756f9
|
|
4
|
+
data.tar.gz: 8ca4936908abe8290062b911284be9a88dd1eee21dc24661104b7f54c412425d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b682cfb8e51594866f226b62adc416fc0e35b45c1f20b6500e73670f6c71bf86cfa2da104c465ad5f8227d83e1aaee347606abbf8bef141938e75283d72109c
|
|
7
|
+
data.tar.gz: 8e43ed9624e01bba9b63ac69872e46a45632f7bb9807c9e70b4ed98c1d0e043ab2c0709eb38857e182de4c9ea5e07e006f0d9d4e9d56ee02c4fddacf9c1e1e56
|
|
@@ -257,6 +257,15 @@ module BarefootJS
|
|
|
257
257
|
# Operators
|
|
258
258
|
# ---------------------------------------------------------------------
|
|
259
259
|
|
|
260
|
+
# JS `/`: both operands through `to_number` (JS `Number()`), then IEEE
|
|
261
|
+
# Float division, which already gives JS's division-by-zero results
|
|
262
|
+
# (`1 / 0` -> Infinity, `1 / -0` -> -Infinity, `0 / 0` -> NaN). Shared by
|
|
263
|
+
# callback-body evaluation (`binary`) and template-emitted division
|
|
264
|
+
# (`Context#div`), so both coerce and divide identically (#3328).
|
|
265
|
+
def divide(l, r)
|
|
266
|
+
to_number(l).to_f / to_number(r).to_f
|
|
267
|
+
end
|
|
268
|
+
|
|
260
269
|
def binary(op, l, r)
|
|
261
270
|
case op
|
|
262
271
|
when '+'
|
|
@@ -267,19 +276,7 @@ module BarefootJS
|
|
|
267
276
|
to_number(l) + to_number(r)
|
|
268
277
|
when '-' then to_number(l) - to_number(r)
|
|
269
278
|
when '*' then to_number(l) * to_number(r)
|
|
270
|
-
when '/'
|
|
271
|
-
ln = to_number(l).to_f
|
|
272
|
-
rn = to_number(r).to_f
|
|
273
|
-
if rn.zero?
|
|
274
|
-
# JS division by zero is finite-valued, not an error.
|
|
275
|
-
if ln.zero? || ln.nan?
|
|
276
|
-
Float::NAN
|
|
277
|
-
else
|
|
278
|
-
ln.positive? ? Float::INFINITY : -Float::INFINITY
|
|
279
|
-
end
|
|
280
|
-
else
|
|
281
|
-
ln / rn
|
|
282
|
-
end
|
|
279
|
+
when '/' then divide(l, r)
|
|
283
280
|
when '%'
|
|
284
281
|
rn = to_number(r).to_f
|
|
285
282
|
rn.zero? ? Float::NAN : to_number(l).to_f.remainder(rn)
|
data/lib/barefoot_js.rb
CHANGED
|
@@ -521,6 +521,15 @@ module BarefootJS
|
|
|
521
521
|
html_escape(string(value))
|
|
522
522
|
end
|
|
523
523
|
|
|
524
|
+
# JS `/`: always a Number quotient. Ruby's `/` on two Integers is
|
|
525
|
+
# integer division (`1234567890 / 4` -> `308641972`, `-7 / 4` -> `-2`),
|
|
526
|
+
# so template-emitted division goes through the shared evaluator's JS
|
|
527
|
+
# division instead -- JS operand coercion, fractional quotient kept,
|
|
528
|
+
# division by zero yielding Infinity / -Infinity / NaN (#3328).
|
|
529
|
+
def div(left, right)
|
|
530
|
+
Evaluator.divide(left, right)
|
|
531
|
+
end
|
|
532
|
+
|
|
524
533
|
# JS truthiness (falsy: false, nil, 0, NaN, ""). Delegates to the
|
|
525
534
|
# shared evaluator so template-emitted conditionals
|
|
526
535
|
# (`if bf.truthy?(x)`) and callback-body evaluation agree byte-for-byte.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: barefoot_js
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.39.
|
|
4
|
+
version: 0.39.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kobaken
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: tzinfo
|