<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/erb/test_erb.rb, branch v4.0.3</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>[ruby/erb] Prohibit def_method on marshal-loaded ERB instances</title>
<updated>2026-04-21T08:16:04+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2026-04-21T07:27:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=fce0a26bca7b9a7c7e6642bd77ce0311664a4e31'/>
<id>fce0a26bca7b9a7c7e6642bd77ce0311664a4e31</id>
<content type='text'>
Extends the @_init guard to def_method so that an ERB object created
via Marshal.load (which bypasses initialize) raises ArgumentError
instead of evaluating arbitrary source. def_module and def_class both
delegate to def_method and are covered by the same check.

Co-authored-by: Tristan Madani &lt;TristanInSec@gmail.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extends the @_init guard to def_method so that an ERB object created
via Marshal.load (which bypasses initialize) raises ArgumentError
instead of evaluating arbitrary source. def_module and def_class both
delegate to def_method and are covered by the same check.

Co-authored-by: Tristan Madani &lt;TristanInSec@gmail.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Reapply "[ruby/erb] Reapply "Remove safe_level and further positional"</title>
<updated>2025-11-12T20:36:44+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2025-11-12T20:31:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=6365d7b0a585c1cd416a52058b0daa9a87d0c8d0'/>
<id>6365d7b0a585c1cd416a52058b0daa9a87d0c8d0</id>
<content type='text'>
This reverts commit 5b6658a406b5f1c535aed4cb68e8e18a3cbabb81.

With a ruby spec fix.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit 5b6658a406b5f1c535aed4cb68e8e18a3cbabb81.

With a ruby spec fix.
</pre>
</div>
</content>
</entry>
<entry>
<title>Revert "[ruby/erb] Reapply "Remove safe_level and further positional"</title>
<updated>2025-11-12T19:59:48+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2025-11-12T19:59:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=5b6658a406b5f1c535aed4cb68e8e18a3cbabb81'/>
<id>5b6658a406b5f1c535aed4cb68e8e18a3cbabb81</id>
<content type='text'>
This reverts commit 6ea4f36716f8970f418f32837575405ddeea75aa.

I'll fix ruby/spec shortly. For now, let me just revert it for ruby/ruby.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit 6ea4f36716f8970f418f32837575405ddeea75aa.

I'll fix ruby/spec shortly. For now, let me just revert it for ruby/ruby.
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Reapply "Remove safe_level and further positional</title>
<updated>2025-11-12T19:53:36+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashi.kokubun@shopify.com</email>
</author>
<published>2025-11-12T19:53:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=6ea4f36716f8970f418f32837575405ddeea75aa'/>
<id>6ea4f36716f8970f418f32837575405ddeea75aa</id>
<content type='text'>
arguments (https://github.com/ruby/erb/pull/7)"
(https://github.com/ruby/erb/pull/95)

This reverts commit https://github.com/ruby/erb/commit/1c02d23dc618.

https://github.com/ruby/erb/commit/4162a24ecc
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
arguments (https://github.com/ruby/erb/pull/7)"
(https://github.com/ruby/erb/pull/95)

This reverts commit https://github.com/ruby/erb/commit/1c02d23dc618.

https://github.com/ruby/erb/commit/4162a24ecc
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Fix integer overflow</title>
<updated>2025-10-12T04:57:43+00:00</updated>
<author>
<name>Nobuyoshi Nakada</name>
<email>nobu@ruby-lang.org</email>
</author>
<published>2025-10-12T04:50:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7cc3191ea1d8cb637e65cd6c2e9229de0e627643'/>
<id>7cc3191ea1d8cb637e65cd6c2e9229de0e627643</id>
<content type='text'>
Fix https://github.com/ruby/erb/pull/87

https://github.com/ruby/erb/commit/75764f022b
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fix https://github.com/ruby/erb/pull/87

https://github.com/ruby/erb/commit/75764f022b
</pre>
</div>
</content>
</entry>
<entry>
<title>Inline Class#new.</title>
<updated>2025-04-25T20:46:05+00:00</updated>
<author>
<name>Aaron Patterson</name>
<email>tenderlove@ruby-lang.org</email>
</author>
<published>2025-03-17T23:59:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=8ac8225c504dee57454131e7cde2c47126596fdc'/>
<id>8ac8225c504dee57454131e7cde2c47126596fdc</id>
<content type='text'>
This commit inlines instructions for Class#new.  To make this work, we
added a new YARV instructions, `opt_new`.  `opt_new` checks whether or
not the `new` method is the default allocator method.  If it is, it
allocates the object, and pushes the instance on the stack.  If not, the
instruction jumps to the "slow path" method call instructions.

Old instructions:

```
&gt; ruby --dump=insns -e'Object.new'
== disasm: #&lt;ISeq:&lt;main&gt;@-e:1 (1,0)-(1,10)&gt;
0000 opt_getconstant_path                   &lt;ic:0 Object&gt;             (   1)[Li]
0002 opt_send_without_block                 &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;
0004 leave
```

New instructions:

```
&gt; ./miniruby --dump=insns -e'Object.new'
== disasm: #&lt;ISeq:&lt;main&gt;@-e:1 (1,0)-(1,10)&gt;
0000 opt_getconstant_path                   &lt;ic:0 Object&gt;             (   1)[Li]
0002 putnil
0003 swap
0004 opt_new                                &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;, 11
0007 opt_send_without_block                 &lt;calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE&gt;
0009 jump                                   14
0011 opt_send_without_block                 &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;
0013 swap
0014 pop
0015 leave
```

This commit speeds up basic object allocation (`Foo.new`) by 60%, but
classes that take keyword parameters see an even bigger benefit because
no hash is allocated when instantiating the object (3x to 6x faster).

Here is an example that uses `Hash.new(capacity: 0)`:

```
&gt; hyperfine "ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'"
Benchmark 1: ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):      1.082 s ±  0.004 s    [User: 1.074 s, System: 0.008 s]
  Range (min … max):    1.076 s …  1.088 s    10 runs

Benchmark 2: ./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):     627.9 ms ±   3.5 ms    [User: 622.7 ms, System: 4.8 ms]
  Range (min … max):   622.7 ms … 633.2 ms    10 runs

Summary
  ./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end' ran
    1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
```

This commit changes the backtrace for `initialize`:

```
aaron@tc ~/g/ruby (inline-new)&gt; cat test.rb
class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

hello
aaron@tc ~/g/ruby (inline-new)&gt; ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
test.rb:8:in 'Class#new'
test.rb:8:in 'Object#hello'
test.rb:11:in '&lt;main&gt;'
aaron@tc ~/g/ruby (inline-new)&gt; ./miniruby -v test.rb
ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24]
test.rb:8:in 'Object#hello'
test.rb:11:in '&lt;main&gt;'
```

It also increases memory usage for calls to `new` by 122 bytes:

```
aaron@tc ~/g/ruby (inline-new)&gt; cat test.rb
require "objspace"

class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello)))
aaron@tc ~/g/ruby (inline-new)&gt; make runruby
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems  ./test.rb
656
aaron@tc ~/g/ruby (inline-new)&gt; ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
544
```

Thanks to @ko1 for coming up with this idea!

Co-Authored-By: John Hawthorn &lt;john@hawthorn.email&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit inlines instructions for Class#new.  To make this work, we
added a new YARV instructions, `opt_new`.  `opt_new` checks whether or
not the `new` method is the default allocator method.  If it is, it
allocates the object, and pushes the instance on the stack.  If not, the
instruction jumps to the "slow path" method call instructions.

Old instructions:

```
&gt; ruby --dump=insns -e'Object.new'
== disasm: #&lt;ISeq:&lt;main&gt;@-e:1 (1,0)-(1,10)&gt;
0000 opt_getconstant_path                   &lt;ic:0 Object&gt;             (   1)[Li]
0002 opt_send_without_block                 &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;
0004 leave
```

New instructions:

```
&gt; ./miniruby --dump=insns -e'Object.new'
== disasm: #&lt;ISeq:&lt;main&gt;@-e:1 (1,0)-(1,10)&gt;
0000 opt_getconstant_path                   &lt;ic:0 Object&gt;             (   1)[Li]
0002 putnil
0003 swap
0004 opt_new                                &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;, 11
0007 opt_send_without_block                 &lt;calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE&gt;
0009 jump                                   14
0011 opt_send_without_block                 &lt;calldata!mid:new, argc:0, ARGS_SIMPLE&gt;
0013 swap
0014 pop
0015 leave
```

This commit speeds up basic object allocation (`Foo.new`) by 60%, but
classes that take keyword parameters see an even bigger benefit because
no hash is allocated when instantiating the object (3x to 6x faster).

Here is an example that uses `Hash.new(capacity: 0)`:

```
&gt; hyperfine "ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'"
Benchmark 1: ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):      1.082 s ±  0.004 s    [User: 1.074 s, System: 0.008 s]
  Range (min … max):    1.076 s …  1.088 s    10 runs

Benchmark 2: ./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):     627.9 ms ±   3.5 ms    [User: 622.7 ms, System: 4.8 ms]
  Range (min … max):   622.7 ms … 633.2 ms    10 runs

Summary
  ./ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end' ran
    1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i &lt; 10_000_000; Hash.new(capacity: 0); i += 1; end'
```

This commit changes the backtrace for `initialize`:

```
aaron@tc ~/g/ruby (inline-new)&gt; cat test.rb
class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

hello
aaron@tc ~/g/ruby (inline-new)&gt; ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
test.rb:8:in 'Class#new'
test.rb:8:in 'Object#hello'
test.rb:11:in '&lt;main&gt;'
aaron@tc ~/g/ruby (inline-new)&gt; ./miniruby -v test.rb
ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24]
test.rb:8:in 'Object#hello'
test.rb:11:in '&lt;main&gt;'
```

It also increases memory usage for calls to `new` by 122 bytes:

```
aaron@tc ~/g/ruby (inline-new)&gt; cat test.rb
require "objspace"

class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello)))
aaron@tc ~/g/ruby (inline-new)&gt; make runruby
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems  ./test.rb
656
aaron@tc ~/g/ruby (inline-new)&gt; ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
544
```

Thanks to @ko1 for coming up with this idea!

Co-Authored-By: John Hawthorn &lt;john@hawthorn.email&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Fix line numbers after multi-line &lt;%#</title>
<updated>2022-11-29T04:56:03+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2022-11-29T04:55:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=129d208f9a5d54faf2eb4d944bc874fe347bfd64'/>
<id>129d208f9a5d54faf2eb4d944bc874fe347bfd64</id>
<content type='text'>
(https://github.com/ruby/erb/pull/42)

https://github.com/ruby/erb/commit/526885923e
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
(https://github.com/ruby/erb/pull/42)

https://github.com/ruby/erb/commit/526885923e
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Copy CGI.escapeHTML to ERB::Util.html_escape</title>
<updated>2022-11-04T07:07:23+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2022-11-03T05:28:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=dc5d06e9b145f7d5f8c5f7c3757b43f2d68833fd'/>
<id>dc5d06e9b145f7d5f8c5f7c3757b43f2d68833fd</id>
<content type='text'>
https://github.com/ruby/erb/commit/ac9b219fa9
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/erb/commit/ac9b219fa9
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Skip a test for JRuby</title>
<updated>2022-11-03T05:58:14+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2022-11-03T05:56:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7b6c5f9b5b16d244268f700aa5cd60bdde3e34d6'/>
<id>7b6c5f9b5b16d244268f700aa5cd60bdde3e34d6</id>
<content type='text'>
https://github.com/ruby/erb/commit/48a75665ab
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/erb/commit/48a75665ab
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/erb] Skip tests for truffleruby</title>
<updated>2022-11-03T05:58:14+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2022-11-03T05:53:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=f667d3afc9096ea32f6f84204529b95099062e86'/>
<id>f667d3afc9096ea32f6f84204529b95099062e86</id>
<content type='text'>
https://github.com/ruby/erb/commit/65a7c70a00
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/erb/commit/65a7c70a00
</pre>
</div>
</content>
</entry>
</feed>
