barefoot_js 0.39.7 → 0.39.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2dee751fa656f2231c7d6cee7f3ab165f508ad988a58c0930419dbc3de1132e
4
- data.tar.gz: 5ecd00ba7237eac6ef23a9172e53c9b7968077d6097080ba86c0759c8b9dfc64
3
+ metadata.gz: 727248cd6dcc7a533846854d5a8d4675ac946390d5750df49b03e25dad8cd3e5
4
+ data.tar.gz: 508a38a3a2d56d99af75875be59b6989103ab3adf3fe6e42bae3e040cd69d608
5
5
  SHA512:
6
- metadata.gz: 8c781e4df474f753e1c58fe3c1e2e25ca7cf1af53fdae23909e98cc5382d3156103abac6ca4d97ce78a180d64213c52aec0e2674cc56f5e7250ced001843ef6f
7
- data.tar.gz: 7e96d3a6a087381bce7afcb51f746f82bc6276b465cce68b57f8ac978dd32c960ada3b846fb0e11652a7c79c0511de41068fb5b831f229ba672fc0ae62f5a790
6
+ metadata.gz: e91debd9fe87d53e154cd53a7be218efd5c3dec07e64f3b57cb3c4cd0d2406f1a5846f84bde2d9cb49f73a5236c6979649e89f50879f2511e31dda9191ed060b
7
+ data.tar.gz: 5b617131eebba68e976d362993fba1f85e8cadd86fff1258ab029d44a4bdbdf64013aa3b8d739229deff1497c411af7205e016b05ff1bfbf877cf85b2ab27e22
@@ -286,6 +286,26 @@ module BarefootJS
286
286
  to_number(l).to_f / to_number(r).to_f
287
287
  end
288
288
 
289
+ # JS `%`: the truncated remainder, which takes the dividend's sign
290
+ # (`-7 % 2` -> -1) and keeps a fraction (`7.5 % 2` -> 1.5); Ruby's `%`
291
+ # floors instead (`-7 % 2` -> 1). A zero divisor, or a NaN / infinite
292
+ # dividend, gives NaN. Two Integer operands keep an Integer result, as
293
+ # Ruby's own `%` did, except for a zero remainder of a negative dividend:
294
+ # JS gives -0 there (`-4 % 2`), which only shows through later
295
+ # arithmetic (`1 / (-4 % 2)` is -Infinity), so it is the Float -0.0. An
296
+ # Array still takes it as index 0 and `number_to_string` spells it "0".
297
+ # Shared by callback-body evaluation (`binary`) and the template-emitted
298
+ # remainder (`Context#mod`, #3474).
299
+ def remainder(l, r)
300
+ ln = to_number(l)
301
+ rn = to_number(r)
302
+ return Float::NAN if rn.zero?
303
+ return ln.to_f.remainder(rn.to_f) unless ln.is_a?(Integer) && rn.is_a?(Integer)
304
+
305
+ m = ln.remainder(rn)
306
+ m.zero? && ln.negative? ? -0.0 : m
307
+ end
308
+
289
309
  def binary(op, l, r)
290
310
  case op
291
311
  when '+'
@@ -297,9 +317,7 @@ module BarefootJS
297
317
  when '-' then to_number(l) - to_number(r)
298
318
  when '*' then to_number(l) * to_number(r)
299
319
  when '/' then divide(l, r)
300
- when '%'
301
- rn = to_number(r).to_f
302
- rn.zero? ? Float::NAN : to_number(l).to_f.remainder(rn)
320
+ when '%' then remainder(l, r)
303
321
  when '<', '<=', '>', '>=' then relational(op, l, r)
304
322
  when '===' then strict_eq(l, r)
305
323
  when '!==' then !strict_eq(l, r)
data/lib/barefoot_js.rb CHANGED
@@ -530,6 +530,15 @@ module BarefootJS
530
530
  Evaluator.divide(left, right)
531
531
  end
532
532
 
533
+ # JS `%`: the truncated remainder, which takes the dividend's sign
534
+ # (`-7 % 2` -> -1). Ruby's `%` floors (`-7 % 2` -> 1), so
535
+ # template-emitted remainders go through the shared evaluator's JS
536
+ # remainder instead: a fraction is kept, and a zero divisor gives NaN
537
+ # rather than raising (#3474).
538
+ def mod(left, right)
539
+ Evaluator.remainder(left, right)
540
+ end
541
+
533
542
  # JS truthiness (falsy: false, nil, 0, NaN, ""). Delegates to the
534
543
  # shared evaluator so template-emitted conditionals
535
544
  # (`if bf.truthy?(x)`) and callback-body evaluation agree byte-for-byte.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barefoot_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.39.7
4
+ version: 0.39.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kobaken