binding_of_caller 0.7.2 → 0.7.3
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 +13 -5
- data/.gemtest +0 -0
- data/.gitignore +0 -0
- data/.travis.yml +12 -1
- data/.yardopts +0 -0
- data/HISTORY +35 -0
- data/LICENSE +0 -0
- data/README.md +6 -3
- data/Rakefile +4 -4
- data/binding_of_caller.gemspec +25 -23
- data/examples/benchmark.rb +63 -0
- data/ext/binding_of_caller/extconf.rb +5 -10
- data/lib/binding_of_caller/jruby_interpreted.rb +123 -0
- data/lib/binding_of_caller/rubinius.rb +21 -28
- data/lib/binding_of_caller/version.rb +1 -1
- data/lib/binding_of_caller.rb +4 -4
- data/test/test_binding_of_caller.rb +0 -0
- metadata +13 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
OGRkMDA4ZmZmOTk3NjY5MTk4OTRlNDhiMTIxNTQxZGI4Y2ZhZWYyNQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
ZTk3YjU1ZjJjY2EwYzMzNWM1OTcyODIyNzQ2NzdmZGYzNTlkYjBiNQ==
|
|
5
7
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
M2NhODk4NDJlZDBiNzM1NDFkMzYxNmJmYjQxMjc1Y2I2NTc3YzRmNDVjODE1
|
|
10
|
+
NTU5Zjc0MDM5MDFmNDA0ODc5NDI5ZDdjMTQzODY4OTU4NWVjY2Q1Yzk4Nzcy
|
|
11
|
+
NTM4MDM0ZTRiZTg5NGYzYWU0MWIyMTk4YzA4Y2M4OTBjYThiZmU=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
YzE5MmVhY2U1ZDY5YzdlYjJjZmMwNjY3MzFkMjFmYWE0OTVjYjU1M2IyOWYx
|
|
14
|
+
NmQ1ZjIzNzkyMjJhYTQ5YmI3ZGY0NGY2NzZhNjRiZjZlOTI4MjY0ODA1YWIw
|
|
15
|
+
ZTRiMGUzMTM4MDM1NDhhZTA3ZThlNWE5YjFmNmZkMDRhOTJkYjM=
|
data/.gemtest
CHANGED
|
File without changes
|
data/.gitignore
CHANGED
|
File without changes
|
data/.travis.yml
CHANGED
|
@@ -2,7 +2,10 @@ rvm:
|
|
|
2
2
|
- 1.9.2
|
|
3
3
|
- 1.9.3
|
|
4
4
|
- 2.0.0
|
|
5
|
-
-
|
|
5
|
+
- 2.1.0
|
|
6
|
+
- 2.2.6
|
|
7
|
+
- 2.3.0
|
|
8
|
+
- 2.4.0
|
|
6
9
|
|
|
7
10
|
notifications:
|
|
8
11
|
irc: "irc.freenode.org#pry"
|
|
@@ -13,6 +16,14 @@ branches:
|
|
|
13
16
|
only:
|
|
14
17
|
- master
|
|
15
18
|
|
|
19
|
+
matrix:
|
|
20
|
+
include:
|
|
21
|
+
- rvm: jruby
|
|
22
|
+
env: JRUBY_OPTS=-X-C
|
|
23
|
+
allow_failures:
|
|
24
|
+
- rvm: jruby
|
|
25
|
+
- rvm: 1.9.3
|
|
26
|
+
|
|
16
27
|
#script: rake test --trace
|
|
17
28
|
#
|
|
18
29
|
#before_install:
|
data/.yardopts
CHANGED
|
File without changes
|
data/HISTORY
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
## 0.7.3.pre1 / 2014-08-20
|
|
2
|
+
|
|
3
|
+
This release includes compatibility fixes for different ruby versions
|
|
4
|
+
and some minor enhancements.
|
|
5
|
+
|
|
6
|
+
* C Extensions are only compiled on MRI 1.9.x.
|
|
7
|
+
|
|
8
|
+
For MRI >= 2 the native API is used, so this should speedup
|
|
9
|
+
installation.
|
|
10
|
+
|
|
11
|
+
For JRuby this will avoid crashes on gem installation.
|
|
12
|
+
|
|
13
|
+
This was alredy being checked for Rubinius.
|
|
14
|
+
|
|
15
|
+
*Amadeus Folego*
|
|
16
|
+
|
|
17
|
+
* Added experimental JRuby support for 1.7.x series.
|
|
18
|
+
|
|
19
|
+
Only the main API is implemented and `Binding#eval` is
|
|
20
|
+
monkey-patched as it is private on JRuby.
|
|
21
|
+
|
|
22
|
+
This requires the compiler to be run on interpreted mode,
|
|
23
|
+
otherwise an exception will be thrown when `of_caller` is called.
|
|
24
|
+
|
|
25
|
+
*Charles Nutter*
|
|
26
|
+
|
|
27
|
+
* Remove executability from non-executable files.
|
|
28
|
+
|
|
29
|
+
*David Celis*
|
|
30
|
+
|
|
31
|
+
* Test and notice MRI 2.1 as a working Ruby implementation.
|
|
32
|
+
|
|
33
|
+
*Lennart Fridén*
|
|
34
|
+
|
|
35
|
+
## 0.7.2 / 2013-06-07
|
data/LICENSE
CHANGED
|
File without changes
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@ binding_of_caller
|
|
|
5
5
|
|
|
6
6
|
(C) John Mair (banisterfiend) 2012
|
|
7
7
|
|
|
8
|
-
_Retrieve the binding of a method's caller in MRI 1.9.2
|
|
8
|
+
_Retrieve the binding of a method's caller in MRI (>= 1.9.2) and RBX (Rubinius)_
|
|
9
9
|
|
|
10
10
|
The `binding_of_caller` gem provides the `Binding#of_caller` method.
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ call stack, not limited to just the immediate caller.
|
|
|
15
15
|
|
|
16
16
|
**Recommended for use only in debugging situations. Do not use this in production apps.**
|
|
17
17
|
|
|
18
|
-
**
|
|
18
|
+
**Works in MRI Ruby (>= 1.9.2) and RBX (Rubinius)**
|
|
19
19
|
|
|
20
20
|
* Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
|
|
21
21
|
* See the [source code](http://github.com/banister/binding_of_caller)
|
|
@@ -52,8 +52,11 @@ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
|
|
|
52
52
|
Features and limitations
|
|
53
53
|
-------------------------
|
|
54
54
|
|
|
55
|
-
*
|
|
55
|
+
* Works in MRI (>= 1.9.2) and RBX (Rubinius)
|
|
56
56
|
* Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a `Binding#of_caller` there.
|
|
57
|
+
* There is experimental support for jruby 1.7.x, but it only works in interpreted
|
|
58
|
+
mode (i.e. use the option `-Djruby.compile.mode=OFF` or append
|
|
59
|
+
`compile.mode=OFF` to your `.jrubyrc`)
|
|
57
60
|
|
|
58
61
|
Contact
|
|
59
62
|
-------
|
data/Rakefile
CHANGED
|
@@ -46,12 +46,12 @@ task :default => [:test]
|
|
|
46
46
|
|
|
47
47
|
desc "Run tests"
|
|
48
48
|
task :test do
|
|
49
|
-
unless defined?(Rubinius)
|
|
49
|
+
unless defined?(Rubinius) or defined?(JRuby)
|
|
50
50
|
Rake::Task['compile'].execute
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
$stdout.puts("\033[33m")
|
|
54
|
-
sh "bacon -Itest -rubygems -a -q"
|
|
54
|
+
sh "bacon -Itest -r rubygems -a -q"
|
|
55
55
|
$stdout.puts("\033[0m")
|
|
56
56
|
|
|
57
57
|
unless defined?(Rubinius)
|
|
@@ -89,7 +89,7 @@ end
|
|
|
89
89
|
|
|
90
90
|
desc "build the binaries"
|
|
91
91
|
task :compile => :cleanup do
|
|
92
|
-
if !mri_2?
|
|
92
|
+
if !mri_2?
|
|
93
93
|
chdir "./ext/binding_of_caller/" do
|
|
94
94
|
sh "ruby extconf.rb"
|
|
95
95
|
sh "make"
|
|
@@ -103,7 +103,7 @@ task :cleanup do
|
|
|
103
103
|
if !mri_2?
|
|
104
104
|
sh 'rm -rf lib/binding_of_caller.so'
|
|
105
105
|
chdir "./ext/binding_of_caller/" do
|
|
106
|
-
sh 'make clean'
|
|
106
|
+
sh 'make clean'
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
end
|
data/binding_of_caller.gemspec
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
+
# stub: binding_of_caller 0.7.3 ruby lib
|
|
3
|
+
# stub: ext/binding_of_caller/extconf.rb
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |s|
|
|
4
|
-
s.name = "binding_of_caller"
|
|
5
|
-
s.version = "0.7.
|
|
6
|
+
s.name = "binding_of_caller".freeze
|
|
7
|
+
s.version = "0.7.3"
|
|
6
8
|
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
-
s.
|
|
9
|
-
s.
|
|
10
|
-
s.
|
|
11
|
-
s.
|
|
12
|
-
s.
|
|
13
|
-
s.
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.rubygems_version = "2.
|
|
17
|
-
s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
|
|
18
|
-
s.test_files = ["test/test_binding_of_caller.rb"]
|
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
10
|
+
s.require_paths = ["lib".freeze]
|
|
11
|
+
s.authors = ["John Mair (banisterfiend)".freeze]
|
|
12
|
+
s.date = "2017-10-22"
|
|
13
|
+
s.description = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack.".freeze
|
|
14
|
+
s.email = "jrmair@gmail.com".freeze
|
|
15
|
+
s.extensions = ["ext/binding_of_caller/extconf.rb".freeze]
|
|
16
|
+
s.files = [".gemtest".freeze, ".gitignore".freeze, ".travis.yml".freeze, ".yardopts".freeze, "Gemfile".freeze, "HISTORY".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "binding_of_caller.gemspec".freeze, "examples/benchmark.rb".freeze, "examples/example.rb".freeze, "ext/binding_of_caller/binding_of_caller.c".freeze, "ext/binding_of_caller/extconf.rb".freeze, "ext/binding_of_caller/ruby_headers/192/debug.h".freeze, "ext/binding_of_caller/ruby_headers/192/dln.h".freeze, "ext/binding_of_caller/ruby_headers/192/eval_intern.h".freeze, "ext/binding_of_caller/ruby_headers/192/id.h".freeze, "ext/binding_of_caller/ruby_headers/192/iseq.h".freeze, "ext/binding_of_caller/ruby_headers/192/method.h".freeze, "ext/binding_of_caller/ruby_headers/192/node.h".freeze, "ext/binding_of_caller/ruby_headers/192/regenc.h".freeze, "ext/binding_of_caller/ruby_headers/192/regint.h".freeze, "ext/binding_of_caller/ruby_headers/192/regparse.h".freeze, "ext/binding_of_caller/ruby_headers/192/rubys_gc.h".freeze, "ext/binding_of_caller/ruby_headers/192/thread_pthread.h".freeze, "ext/binding_of_caller/ruby_headers/192/thread_win32.h".freeze, "ext/binding_of_caller/ruby_headers/192/timev.h".freeze, "ext/binding_of_caller/ruby_headers/192/transcode_data.h".freeze, "ext/binding_of_caller/ruby_headers/192/version.h".freeze, "ext/binding_of_caller/ruby_headers/192/vm_core.h".freeze, "ext/binding_of_caller/ruby_headers/192/vm_exec.h".freeze, "ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h".freeze, "ext/binding_of_caller/ruby_headers/192/vm_opts.h".freeze, "ext/binding_of_caller/ruby_headers/193/addr2line.h".freeze, "ext/binding_of_caller/ruby_headers/193/atomic.h".freeze, "ext/binding_of_caller/ruby_headers/193/constant.h".freeze, "ext/binding_of_caller/ruby_headers/193/debug.h".freeze, "ext/binding_of_caller/ruby_headers/193/dln.h".freeze, "ext/binding_of_caller/ruby_headers/193/encdb.h".freeze, "ext/binding_of_caller/ruby_headers/193/eval_intern.h".freeze, "ext/binding_of_caller/ruby_headers/193/id.h".freeze, "ext/binding_of_caller/ruby_headers/193/internal.h".freeze, "ext/binding_of_caller/ruby_headers/193/iseq.h".freeze, "ext/binding_of_caller/ruby_headers/193/method.h".freeze, "ext/binding_of_caller/ruby_headers/193/node.h".freeze, "ext/binding_of_caller/ruby_headers/193/parse.h".freeze, "ext/binding_of_caller/ruby_headers/193/regenc.h".freeze, "ext/binding_of_caller/ruby_headers/193/regint.h".freeze, "ext/binding_of_caller/ruby_headers/193/regparse.h".freeze, "ext/binding_of_caller/ruby_headers/193/revision.h".freeze, "ext/binding_of_caller/ruby_headers/193/rubys_gc.h".freeze, "ext/binding_of_caller/ruby_headers/193/thread_pthread.h".freeze, "ext/binding_of_caller/ruby_headers/193/thread_win32.h".freeze, "ext/binding_of_caller/ruby_headers/193/timev.h".freeze, "ext/binding_of_caller/ruby_headers/193/transcode_data.h".freeze, "ext/binding_of_caller/ruby_headers/193/transdb.h".freeze, "ext/binding_of_caller/ruby_headers/193/version.h".freeze, "ext/binding_of_caller/ruby_headers/193/vm_core.h".freeze, "ext/binding_of_caller/ruby_headers/193/vm_exec.h".freeze, "ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h".freeze, "ext/binding_of_caller/ruby_headers/193/vm_opts.h".freeze, "lib/binding_of_caller.rb".freeze, "lib/binding_of_caller/jruby_interpreted.rb".freeze, "lib/binding_of_caller/mri2.rb".freeze, "lib/binding_of_caller/rubinius.rb".freeze, "lib/binding_of_caller/version.rb".freeze, "test/test_binding_of_caller.rb".freeze]
|
|
17
|
+
s.homepage = "http://github.com/banister/binding_of_caller".freeze
|
|
18
|
+
s.rubygems_version = "2.6.13".freeze
|
|
19
|
+
s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack.".freeze
|
|
20
|
+
s.test_files = ["test/test_binding_of_caller.rb".freeze]
|
|
19
21
|
|
|
20
22
|
if s.respond_to? :specification_version then
|
|
21
23
|
s.specification_version = 4
|
|
22
24
|
|
|
23
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
24
|
-
s.add_runtime_dependency(%q<debug_inspector
|
|
25
|
-
s.add_development_dependency(%q<bacon
|
|
26
|
-
s.add_development_dependency(%q<rake
|
|
26
|
+
s.add_runtime_dependency(%q<debug_inspector>.freeze, [">= 0.0.1"])
|
|
27
|
+
s.add_development_dependency(%q<bacon>.freeze, [">= 0"])
|
|
28
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
|
27
29
|
else
|
|
28
|
-
s.add_dependency(%q<debug_inspector
|
|
29
|
-
s.add_dependency(%q<bacon
|
|
30
|
-
s.add_dependency(%q<rake
|
|
30
|
+
s.add_dependency(%q<debug_inspector>.freeze, [">= 0.0.1"])
|
|
31
|
+
s.add_dependency(%q<bacon>.freeze, [">= 0"])
|
|
32
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
|
31
33
|
end
|
|
32
34
|
else
|
|
33
|
-
s.add_dependency(%q<debug_inspector
|
|
34
|
-
s.add_dependency(%q<bacon
|
|
35
|
-
s.add_dependency(%q<rake
|
|
35
|
+
s.add_dependency(%q<debug_inspector>.freeze, [">= 0.0.1"])
|
|
36
|
+
s.add_dependency(%q<bacon>.freeze, [">= 0"])
|
|
37
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
|
36
38
|
end
|
|
37
39
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'benchmark'
|
|
2
|
+
|
|
3
|
+
unless Object.const_defined? :BindingOfCaller
|
|
4
|
+
$:.unshift File.expand_path '../../lib', __FILE__
|
|
5
|
+
require 'binding_of_caller'
|
|
6
|
+
require 'binding_of_caller/version'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
n = 250000
|
|
11
|
+
|
|
12
|
+
Benchmark.bm(10) do |x|
|
|
13
|
+
x.report("#of_caller") do
|
|
14
|
+
1.upto(n) do
|
|
15
|
+
1.times do
|
|
16
|
+
1.times do
|
|
17
|
+
binding.of_caller(2)
|
|
18
|
+
binding.of_caller(1)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
x.report("#frame_count") do
|
|
25
|
+
1.upto(n) do
|
|
26
|
+
1.times do
|
|
27
|
+
1.times do
|
|
28
|
+
binding.frame_count
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
x.report("#callers") do
|
|
35
|
+
1.upto(n) do
|
|
36
|
+
1.times do
|
|
37
|
+
1.times do
|
|
38
|
+
binding.callers
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
x.report("#frame_description") do
|
|
45
|
+
1.upto(n) do
|
|
46
|
+
1.times do
|
|
47
|
+
1.times do
|
|
48
|
+
binding.of_caller(1).frame_description
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
x.report("#frame_type") do
|
|
55
|
+
1.upto(n) do
|
|
56
|
+
1.times do
|
|
57
|
+
1.times do
|
|
58
|
+
binding.of_caller(1).frame_type
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -4,18 +4,12 @@ def fake_makefile
|
|
|
4
4
|
end
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
def
|
|
7
|
+
def mri_1_9?
|
|
8
8
|
defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
9
|
-
RUBY_VERSION =~ /^
|
|
9
|
+
RUBY_VERSION =~ /^1\.9/
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
if mri_2? || rbx?
|
|
17
|
-
fake_makefile
|
|
18
|
-
else
|
|
12
|
+
if mri_1_9?
|
|
19
13
|
require 'mkmf'
|
|
20
14
|
|
|
21
15
|
$CFLAGS += " -O0"
|
|
@@ -29,5 +23,6 @@ else
|
|
|
29
23
|
end
|
|
30
24
|
|
|
31
25
|
create_makefile('binding_of_caller')
|
|
26
|
+
else
|
|
27
|
+
fake_makefile
|
|
32
28
|
end
|
|
33
|
-
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
module BindingOfCaller
|
|
2
|
+
class JRubyBindingHolder
|
|
3
|
+
java_import org.jruby.RubyBinding
|
|
4
|
+
|
|
5
|
+
def initialize(binding)
|
|
6
|
+
@binding = binding
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def eval(code, file = nil, line = nil)
|
|
10
|
+
b = JRuby.dereference(RubyBinding.new(JRuby.runtime, Binding, @binding))
|
|
11
|
+
if (file == nil)
|
|
12
|
+
Kernel.eval code, b
|
|
13
|
+
else
|
|
14
|
+
Kernel.eval code, b, file, line
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def frame_type
|
|
19
|
+
case
|
|
20
|
+
when block?
|
|
21
|
+
:block
|
|
22
|
+
when eval?
|
|
23
|
+
:eval
|
|
24
|
+
when top?
|
|
25
|
+
:top
|
|
26
|
+
else
|
|
27
|
+
:method
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def frame_description
|
|
32
|
+
"#{block_desc}#{method_desc}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def block?
|
|
38
|
+
@binding.getDynamicScope().getStaticScope().isBlockScope()
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def eval?
|
|
42
|
+
@binding.getFrame().getKlazz().nil? && @binding.getLine() != 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def top?
|
|
46
|
+
@binding.getFrame().getKlazz().nil? && @binding.getLine() == 0
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def block_desc
|
|
50
|
+
if frame_type == :block
|
|
51
|
+
"block in "
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def method_desc
|
|
56
|
+
@binding.getFrame().getName() || "<main>"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
module BindingExtensions
|
|
61
|
+
def of_caller(index = 1)
|
|
62
|
+
index += 1 # always omit this frame
|
|
63
|
+
JRuby.runtime.current_context.binding_of_caller(index)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def callers
|
|
67
|
+
ary = []
|
|
68
|
+
n = 2
|
|
69
|
+
while binding = of_caller(n)
|
|
70
|
+
ary << binding
|
|
71
|
+
n += 1
|
|
72
|
+
end
|
|
73
|
+
ary
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def frame_count
|
|
77
|
+
callers.count - 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def frame_type
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def frame_description
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class org::jruby::runtime::ThreadContext
|
|
92
|
+
java_import org.jruby.runtime.Binding
|
|
93
|
+
java_import org.jruby.RubyInstanceConfig::CompileMode
|
|
94
|
+
|
|
95
|
+
field_accessor :frameStack, :frameIndex,
|
|
96
|
+
:scopeStack, :scopeIndex,
|
|
97
|
+
:backtrace, :backtraceIndex
|
|
98
|
+
|
|
99
|
+
def binding_of_caller(index)
|
|
100
|
+
unless JRuby.runtime.instance_config.compile_mode == CompileMode::OFF
|
|
101
|
+
raise RuntimeError, "caller binding only supported in interpreter"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
index += 1 # always omit this frame
|
|
105
|
+
|
|
106
|
+
return nil if index > frameIndex
|
|
107
|
+
|
|
108
|
+
frame = frameStack[frameIndex - index]
|
|
109
|
+
|
|
110
|
+
return binding_of_caller(index - 1) if index > scopeIndex
|
|
111
|
+
|
|
112
|
+
scope = scopeStack[scopeIndex - index]
|
|
113
|
+
element = backtrace[backtraceIndex - index]
|
|
114
|
+
|
|
115
|
+
binding = Binding.new(frame, scope.static_scope.module, scope, element.clone)
|
|
116
|
+
|
|
117
|
+
BindingOfCaller::JRubyBindingHolder.new(binding)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class ::Binding
|
|
122
|
+
include BindingOfCaller::BindingExtensions
|
|
123
|
+
end
|
|
@@ -4,22 +4,11 @@ module BindingOfCaller
|
|
|
4
4
|
# Retrieve the binding of the nth caller of the current frame.
|
|
5
5
|
# @return [Binding]
|
|
6
6
|
def of_caller(n)
|
|
7
|
-
|
|
7
|
+
location = Rubinius::VM.backtrace(1 + n, true).first
|
|
8
8
|
|
|
9
|
-
raise RuntimeError, "Invalid frame, gone beyond end of stack!" if
|
|
9
|
+
raise RuntimeError, "Invalid frame, gone beyond end of stack!" if location.nil?
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
bt.variables,
|
|
13
|
-
bt.variables.method,
|
|
14
|
-
bt.constant_scope,
|
|
15
|
-
bt.variables.self,
|
|
16
|
-
bt
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
b.instance_variable_set :@frame_description,
|
|
20
|
-
bt.describe.gsub("{ } in", "block in")
|
|
21
|
-
|
|
22
|
-
b
|
|
11
|
+
setup_binding_from_location(location)
|
|
23
12
|
end
|
|
24
13
|
|
|
25
14
|
# The description of the frame.
|
|
@@ -31,25 +20,14 @@ module BindingOfCaller
|
|
|
31
20
|
# Return bindings for all caller frames.
|
|
32
21
|
# @return [Array<Binding>]
|
|
33
22
|
def callers
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
loop do
|
|
37
|
-
begin
|
|
38
|
-
ary << Binding.of_caller(n)
|
|
39
|
-
rescue
|
|
40
|
-
break
|
|
41
|
-
end
|
|
42
|
-
n += 1
|
|
43
|
-
end
|
|
44
|
-
ary.drop_while do |v|
|
|
45
|
-
!(v.frame_type == :method && v.eval("__method__") == :callers)
|
|
46
|
-
end.drop(1)
|
|
23
|
+
Rubinius::VM.backtrace(1, true).map &(method(:setup_binding_from_location).
|
|
24
|
+
to_proc)
|
|
47
25
|
end
|
|
48
26
|
|
|
49
27
|
# Number of parent frames available at the point of call.
|
|
50
28
|
# @return [Fixnum]
|
|
51
29
|
def frame_count
|
|
52
|
-
|
|
30
|
+
Rubinius::VM.backtrace(1).count
|
|
53
31
|
end
|
|
54
32
|
|
|
55
33
|
# The type of the frame.
|
|
@@ -65,6 +43,21 @@ module BindingOfCaller
|
|
|
65
43
|
:method
|
|
66
44
|
end
|
|
67
45
|
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
|
|
49
|
+
def setup_binding_from_location(location)
|
|
50
|
+
binding = Binding.setup location.variables,
|
|
51
|
+
location.variables.method,
|
|
52
|
+
location.constant_scope,
|
|
53
|
+
location.variables.self,
|
|
54
|
+
location
|
|
55
|
+
|
|
56
|
+
binding.instance_variable_set :@frame_description,
|
|
57
|
+
location.describe.gsub("{ } in", "block in")
|
|
58
|
+
|
|
59
|
+
binding
|
|
60
|
+
end
|
|
68
61
|
end
|
|
69
62
|
end
|
|
70
63
|
|
data/lib/binding_of_caller.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
dlext = RbConfig::CONFIG['DLEXT']
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
3
|
+
mri_2 = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
5
4
|
RUBY_VERSION =~ /^2/
|
|
6
|
-
end
|
|
7
5
|
|
|
8
|
-
if mri_2
|
|
6
|
+
if mri_2
|
|
9
7
|
require 'binding_of_caller/mri2'
|
|
10
8
|
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
|
|
11
9
|
require "binding_of_caller.#{dlext}"
|
|
12
10
|
elsif defined?(Rubinius)
|
|
13
11
|
require 'binding_of_caller/rubinius'
|
|
12
|
+
elsif defined?(JRuby)
|
|
13
|
+
require 'binding_of_caller/jruby_interpreted'
|
|
14
14
|
end
|
|
File without changes
|
metadata
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: binding_of_caller
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Mair (banisterfiend)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: debug_inspector
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - '>='
|
|
17
|
+
- - ! '>='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: 0.0.1
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - '>='
|
|
24
|
+
- - ! '>='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.0.1
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bacon
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - '>='
|
|
31
|
+
- - ! '>='
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - '>='
|
|
38
|
+
- - ! '>='
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rake
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - '>='
|
|
45
|
+
- - ! '>='
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - '>='
|
|
52
|
+
- - ! '>='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
description: Retrieve the binding of a method's caller. Can also retrieve bindings
|
|
@@ -70,6 +70,7 @@ files:
|
|
|
70
70
|
- README.md
|
|
71
71
|
- Rakefile
|
|
72
72
|
- binding_of_caller.gemspec
|
|
73
|
+
- examples/benchmark.rb
|
|
73
74
|
- examples/example.rb
|
|
74
75
|
- ext/binding_of_caller/binding_of_caller.c
|
|
75
76
|
- ext/binding_of_caller/extconf.rb
|
|
@@ -122,6 +123,7 @@ files:
|
|
|
122
123
|
- ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h
|
|
123
124
|
- ext/binding_of_caller/ruby_headers/193/vm_opts.h
|
|
124
125
|
- lib/binding_of_caller.rb
|
|
126
|
+
- lib/binding_of_caller/jruby_interpreted.rb
|
|
125
127
|
- lib/binding_of_caller/mri2.rb
|
|
126
128
|
- lib/binding_of_caller/rubinius.rb
|
|
127
129
|
- lib/binding_of_caller/version.rb
|
|
@@ -135,17 +137,17 @@ require_paths:
|
|
|
135
137
|
- lib
|
|
136
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
139
|
requirements:
|
|
138
|
-
- - '>='
|
|
140
|
+
- - ! '>='
|
|
139
141
|
- !ruby/object:Gem::Version
|
|
140
142
|
version: '0'
|
|
141
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
144
|
requirements:
|
|
143
|
-
- - '>='
|
|
145
|
+
- - ! '>='
|
|
144
146
|
- !ruby/object:Gem::Version
|
|
145
147
|
version: '0'
|
|
146
148
|
requirements: []
|
|
147
149
|
rubyforge_project:
|
|
148
|
-
rubygems_version: 2.
|
|
150
|
+
rubygems_version: 2.6.13
|
|
149
151
|
signing_key:
|
|
150
152
|
specification_version: 4
|
|
151
153
|
summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
|