binding_of_caller 0.6.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 +15 -0
- data/.gemtest +0 -0
- data/.gitignore +8 -7
- data/.travis.yml +34 -0
- data/.yardopts +0 -0
- data/Gemfile +2 -0
- data/HISTORY +35 -0
- data/LICENSE +0 -0
- data/README.md +10 -5
- data/Rakefile +134 -81
- data/binding_of_caller.gemspec +39 -0
- data/examples/benchmark.rb +63 -0
- data/ext/binding_of_caller/binding_of_caller.c +9 -4
- data/ext/binding_of_caller/extconf.rb +25 -10
- data/ext/binding_of_caller/ruby_headers/192/version.h +0 -8
- data/lib/binding_of_caller/jruby_interpreted.rb +123 -0
- data/lib/binding_of_caller/mri2.rb +69 -0
- data/lib/binding_of_caller/rubinius.rb +67 -0
- data/lib/binding_of_caller/version.rb +3 -3
- data/lib/binding_of_caller.rb +14 -0
- data/test/test_binding_of_caller.rb +161 -0
- metadata +56 -19
- data/test/test.rb +0 -91
- /data/ext/binding_of_caller/ruby_headers/192/{gc.h → rubys_gc.h} +0 -0
- /data/ext/binding_of_caller/ruby_headers/193/{gc.h → rubys_gc.h} +0 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
OGRkMDA4ZmZmOTk3NjY5MTk4OTRlNDhiMTIxNTQxZGI4Y2ZhZWYyNQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
ZTk3YjU1ZjJjY2EwYzMzNWM1OTcyODIyNzQ2NzdmZGYzNTlkYjBiNQ==
|
|
7
|
+
SHA512:
|
|
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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
Makefile
|
|
2
|
-
*.so
|
|
3
|
-
*.o
|
|
4
|
-
*.def
|
|
5
|
-
doc/
|
|
6
|
-
pkg/
|
|
7
|
-
.yardoc/
|
|
1
|
+
Makefile
|
|
2
|
+
*.so
|
|
3
|
+
*.o
|
|
4
|
+
*.def
|
|
5
|
+
doc/
|
|
6
|
+
pkg/
|
|
7
|
+
.yardoc/
|
|
8
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
rvm:
|
|
2
|
+
- 1.9.2
|
|
3
|
+
- 1.9.3
|
|
4
|
+
- 2.0.0
|
|
5
|
+
- 2.1.0
|
|
6
|
+
- 2.2.6
|
|
7
|
+
- 2.3.0
|
|
8
|
+
- 2.4.0
|
|
9
|
+
|
|
10
|
+
notifications:
|
|
11
|
+
irc: "irc.freenode.org#pry"
|
|
12
|
+
recipients:
|
|
13
|
+
- jrmair@gmail.com
|
|
14
|
+
|
|
15
|
+
branches:
|
|
16
|
+
only:
|
|
17
|
+
- master
|
|
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
|
+
|
|
27
|
+
#script: rake test --trace
|
|
28
|
+
#
|
|
29
|
+
#before_install:
|
|
30
|
+
# - gem update --system
|
|
31
|
+
# - gem --version
|
|
32
|
+
# - gem install rake bacon
|
|
33
|
+
# - rake gem
|
|
34
|
+
# - gem install pkg/*.gem
|
data/.yardopts
CHANGED
|
File without changes
|
data/Gemfile
ADDED
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
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
[](http://travis-ci.org/banister/binding_of_caller)
|
|
2
|
+
|
|
1
3
|
binding_of_caller
|
|
2
4
|
===========
|
|
3
5
|
|
|
4
|
-
(C) John Mair (banisterfiend)
|
|
6
|
+
(C) John Mair (banisterfiend) 2012
|
|
5
7
|
|
|
6
|
-
_Retrieve the binding of a method's caller in MRI 1.9.
|
|
8
|
+
_Retrieve the binding of a method's caller in MRI (>= 1.9.2) and RBX (Rubinius)_
|
|
7
9
|
|
|
8
10
|
The `binding_of_caller` gem provides the `Binding#of_caller` method.
|
|
9
11
|
|
|
@@ -13,7 +15,7 @@ call stack, not limited to just the immediate caller.
|
|
|
13
15
|
|
|
14
16
|
**Recommended for use only in debugging situations. Do not use this in production apps.**
|
|
15
17
|
|
|
16
|
-
**
|
|
18
|
+
**Works in MRI Ruby (>= 1.9.2) and RBX (Rubinius)**
|
|
17
19
|
|
|
18
20
|
* Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
|
|
19
21
|
* See the [source code](http://github.com/banister/binding_of_caller)
|
|
@@ -50,8 +52,11 @@ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
|
|
|
50
52
|
Features and limitations
|
|
51
53
|
-------------------------
|
|
52
54
|
|
|
53
|
-
*
|
|
55
|
+
* Works in MRI (>= 1.9.2) and RBX (Rubinius)
|
|
54
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`)
|
|
55
60
|
|
|
56
61
|
Contact
|
|
57
62
|
-------
|
|
@@ -64,7 +69,7 @@ License
|
|
|
64
69
|
|
|
65
70
|
(The MIT License)
|
|
66
71
|
|
|
67
|
-
Copyright (c)
|
|
72
|
+
Copyright (c) 2012 (John Mair)
|
|
68
73
|
|
|
69
74
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
70
75
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
|
@@ -1,81 +1,134 @@
|
|
|
1
|
-
dlext =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require '
|
|
8
|
-
|
|
9
|
-
require "
|
|
10
|
-
|
|
11
|
-
CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
|
|
12
|
-
CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
|
|
13
|
-
"ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
|
|
14
|
-
"ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake")
|
|
15
|
-
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
s.
|
|
23
|
-
s.
|
|
24
|
-
s.
|
|
25
|
-
s.
|
|
26
|
-
s.
|
|
27
|
-
s.
|
|
28
|
-
s.
|
|
29
|
-
s.
|
|
30
|
-
s.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
1
|
+
dlext = RbConfig::CONFIG['DLEXT']
|
|
2
|
+
direc = File.dirname(__FILE__)
|
|
3
|
+
|
|
4
|
+
$:.unshift 'lib'
|
|
5
|
+
|
|
6
|
+
require 'rake/clean'
|
|
7
|
+
require 'rubygems/package_task'
|
|
8
|
+
|
|
9
|
+
require "binding_of_caller/version"
|
|
10
|
+
|
|
11
|
+
CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
|
|
12
|
+
CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
|
|
13
|
+
"ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
|
|
14
|
+
"ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake", "**/*.rbc")
|
|
15
|
+
|
|
16
|
+
def mri_2?
|
|
17
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
18
|
+
RUBY_VERSION =~ /^2/
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def apply_spec_defaults(s)
|
|
22
|
+
s.name = "binding_of_caller"
|
|
23
|
+
s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
|
|
24
|
+
s.version = BindingOfCaller::VERSION
|
|
25
|
+
s.date = Time.now.strftime '%Y-%m-%d'
|
|
26
|
+
s.author = "John Mair (banisterfiend)"
|
|
27
|
+
s.email = 'jrmair@gmail.com'
|
|
28
|
+
s.description = s.summary
|
|
29
|
+
s.require_path = 'lib'
|
|
30
|
+
s.add_dependency 'debug_inspector', '>= 0.0.1'
|
|
31
|
+
s.add_development_dependency 'bacon'
|
|
32
|
+
s.add_development_dependency 'rake'
|
|
33
|
+
s.homepage = "http://github.com/banister/binding_of_caller"
|
|
34
|
+
s.has_rdoc = 'yard'
|
|
35
|
+
s.files = `git ls-files`.split("\n")
|
|
36
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc "Show version"
|
|
40
|
+
task :version do
|
|
41
|
+
puts "BindingOfCaller version: #{BindingOfCaller::VERSION}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc "run tests"
|
|
45
|
+
task :default => [:test]
|
|
46
|
+
|
|
47
|
+
desc "Run tests"
|
|
48
|
+
task :test do
|
|
49
|
+
unless defined?(Rubinius) or defined?(JRuby)
|
|
50
|
+
Rake::Task['compile'].execute
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
$stdout.puts("\033[33m")
|
|
54
|
+
sh "bacon -Itest -r rubygems -a -q"
|
|
55
|
+
$stdout.puts("\033[0m")
|
|
56
|
+
|
|
57
|
+
unless defined?(Rubinius)
|
|
58
|
+
Rake::Task['cleanup'].execute
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
task :pry do
|
|
63
|
+
puts "loading binding_of_caller into pry"
|
|
64
|
+
sh "pry -r ./lib/binding_of_caller"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
desc "generate gemspec"
|
|
68
|
+
task :gemspec => "ruby:gemspec"
|
|
69
|
+
|
|
70
|
+
namespace :ruby do
|
|
71
|
+
spec = Gem::Specification.new do |s|
|
|
72
|
+
apply_spec_defaults(s)
|
|
73
|
+
s.platform = Gem::Platform::RUBY
|
|
74
|
+
s.extensions = ["ext/binding_of_caller/extconf.rb"]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Gem::PackageTask.new(spec) do |pkg|
|
|
78
|
+
pkg.need_zip = false
|
|
79
|
+
pkg.need_tar = false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
desc "Generate gemspec file"
|
|
83
|
+
task :gemspec do
|
|
84
|
+
File.open("#{spec.name}.gemspec", "w") do |f|
|
|
85
|
+
f << spec.to_ruby
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
desc "build the binaries"
|
|
91
|
+
task :compile => :cleanup do
|
|
92
|
+
if !mri_2?
|
|
93
|
+
chdir "./ext/binding_of_caller/" do
|
|
94
|
+
sh "ruby extconf.rb"
|
|
95
|
+
sh "make"
|
|
96
|
+
sh "cp *.#{dlext} ../../lib/"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
desc 'cleanup the extensions'
|
|
102
|
+
task :cleanup do
|
|
103
|
+
if !mri_2?
|
|
104
|
+
sh 'rm -rf lib/binding_of_caller.so'
|
|
105
|
+
chdir "./ext/binding_of_caller/" do
|
|
106
|
+
sh 'make clean'
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
desc "reinstall gem"
|
|
112
|
+
task :reinstall => :gems do
|
|
113
|
+
sh "gem uninstall binding_of_caller" rescue nil
|
|
114
|
+
sh "gem install #{direc}/pkg/binding_of_caller-#{BindingOfCaller::VERSION}.gem"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
task :install => :reinstall
|
|
118
|
+
|
|
119
|
+
desc "build all platform gems at once"
|
|
120
|
+
task :gems => [:clean, :rmgems, "ruby:gem"]
|
|
121
|
+
|
|
122
|
+
task :gem => [:gems]
|
|
123
|
+
|
|
124
|
+
desc "remove all platform gems"
|
|
125
|
+
task :rmgems => ["ruby:clobber_package"]
|
|
126
|
+
|
|
127
|
+
desc "build and push latest gems"
|
|
128
|
+
task :pushgems => :gems do
|
|
129
|
+
chdir("./pkg") do
|
|
130
|
+
Dir["*.gem"].each do |gemfile|
|
|
131
|
+
sh "gem push #{gemfile}"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
# stub: binding_of_caller 0.7.3 ruby lib
|
|
3
|
+
# stub: ext/binding_of_caller/extconf.rb
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "binding_of_caller".freeze
|
|
7
|
+
s.version = "0.7.3"
|
|
8
|
+
|
|
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]
|
|
21
|
+
|
|
22
|
+
if s.respond_to? :specification_version then
|
|
23
|
+
s.specification_version = 4
|
|
24
|
+
|
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
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"])
|
|
29
|
+
else
|
|
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"])
|
|
33
|
+
end
|
|
34
|
+
else
|
|
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"])
|
|
38
|
+
end
|
|
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
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <ruby.h>
|
|
4
4
|
#include "vm_core.h"
|
|
5
|
-
#include "
|
|
5
|
+
#include "rubys_gc.h"
|
|
6
6
|
|
|
7
7
|
typedef enum { false, true } bool;
|
|
8
8
|
|
|
@@ -24,6 +24,7 @@ threadptr_data_type(void)
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
#define ruby_thread_data_type *threadptr_data_type()
|
|
27
|
+
#define ruby_threadptr_data_type *threadptr_data_type()
|
|
27
28
|
|
|
28
29
|
#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
|
|
29
30
|
|
|
@@ -78,8 +79,12 @@ binding_alloc(VALUE klass)
|
|
|
78
79
|
return obj;
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
static bool ifunc_p(rb_control_frame_t * cfp) {
|
|
83
|
+
return (cfp->flag & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_IFUNC;
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
static bool valid_frame_p(rb_control_frame_t * cfp, rb_control_frame_t * limit_cfp) {
|
|
82
|
-
return cfp->iseq && !NIL_P(cfp->self);
|
|
87
|
+
return cfp->iseq && !ifunc_p(cfp) && !NIL_P(cfp->self);
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
static rb_control_frame_t * find_valid_frame(rb_control_frame_t * cfp, rb_control_frame_t * limit_cfp) {
|
|
@@ -105,7 +110,6 @@ frametype_name(VALUE flag)
|
|
|
105
110
|
case VM_FRAME_MAGIC_BLOCK: return string2sym("block");
|
|
106
111
|
case VM_FRAME_MAGIC_CLASS: return string2sym("class");
|
|
107
112
|
case VM_FRAME_MAGIC_TOP: return string2sym("top");
|
|
108
|
-
case VM_FRAME_MAGIC_FINISH: return string2sym("finish");
|
|
109
113
|
case VM_FRAME_MAGIC_CFUNC: return string2sym("cfunc");
|
|
110
114
|
case VM_FRAME_MAGIC_PROC: return string2sym("proc");
|
|
111
115
|
case VM_FRAME_MAGIC_IFUNC: return string2sym("ifunc");
|
|
@@ -144,10 +148,11 @@ static VALUE binding_of_caller(VALUE self, VALUE rb_level)
|
|
|
144
148
|
rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
|
|
145
149
|
|
|
146
150
|
GetBindingPtr(bindval, bind);
|
|
151
|
+
|
|
147
152
|
bind->env = rb_vm_make_env_object(th, cfp);
|
|
148
153
|
bind->filename = cfp->iseq->filename;
|
|
149
154
|
bind->line_no = rb_vm_get_sourceline(cfp);
|
|
150
|
-
|
|
155
|
+
|
|
151
156
|
rb_iv_set(bindval, "@frame_type", frametype_name(cfp->flag));
|
|
152
157
|
rb_iv_set(bindval, "@frame_description", cfp->iseq->name);
|
|
153
158
|
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
def fake_makefile
|
|
2
|
+
File.open(File.join(File.dirname(__FILE__), "Makefile"), "w") do |f|
|
|
3
|
+
f.puts %[install:\n\techo "Nada."]
|
|
4
|
+
end
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
when /1.9.3/
|
|
10
|
-
$CFLAGS += " -I./ruby_headers/193/ -DRUBY_193"
|
|
7
|
+
def mri_1_9?
|
|
8
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
9
|
+
RUBY_VERSION =~ /^1\.9/
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
if mri_1_9?
|
|
13
|
+
require 'mkmf'
|
|
14
|
+
|
|
15
|
+
$CFLAGS += " -O0"
|
|
16
|
+
$CFLAGS += " -std=c99"
|
|
17
|
+
|
|
18
|
+
case RUBY_VERSION
|
|
19
|
+
when /1.9.2/
|
|
20
|
+
$CFLAGS += " -I./ruby_headers/192/ -DRUBY_192"
|
|
21
|
+
when /1.9.3/
|
|
22
|
+
$CFLAGS += " -I./ruby_headers/193/ -DRUBY_193"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
create_makefile('binding_of_caller')
|
|
26
|
+
else
|
|
27
|
+
fake_makefile
|
|
28
|
+
end
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
#define RUBY_VERSION "1.9.2"
|
|
2
|
-
<<<<<<< HEAD
|
|
3
|
-
<<<<<<< HEAD
|
|
4
|
-
#define RUBY_PATCHLEVEL 34
|
|
5
|
-
=======
|
|
6
|
-
#define RUBY_PATCHLEVEL 27
|
|
7
|
-
>>>>>>> 7f5d559... merges r29155 from trunk into ruby_1_9_2. fixes #3777, #3772 and #3722.
|
|
8
|
-
=======
|
|
9
2
|
#define RUBY_PATCHLEVEL 30
|
|
10
|
-
>>>>>>> 13fdd22... merges r29188 from trunk into ruby_1_9_2.
|
|
11
3
|
#define RUBY_VERSION_MAJOR 1
|
|
12
4
|
#define RUBY_VERSION_MINOR 9
|
|
13
5
|
#define RUBY_VERSION_TEENY 1
|
|
@@ -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
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'debug_inspector'
|
|
2
|
+
|
|
3
|
+
module BindingOfCaller
|
|
4
|
+
module BindingExtensions
|
|
5
|
+
# Retrieve the binding of the nth caller of the current frame.
|
|
6
|
+
# @return [Binding]
|
|
7
|
+
def of_caller(n)
|
|
8
|
+
c = callers.drop(1)
|
|
9
|
+
if n > (c.size - 1)
|
|
10
|
+
raise "No such frame, gone beyond end of stack!"
|
|
11
|
+
else
|
|
12
|
+
c[n]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Return bindings for all caller frames.
|
|
17
|
+
# @return [Array<Binding>]
|
|
18
|
+
def callers
|
|
19
|
+
ary = []
|
|
20
|
+
|
|
21
|
+
RubyVM::DebugInspector.open do |i|
|
|
22
|
+
n = 0
|
|
23
|
+
loop do
|
|
24
|
+
begin
|
|
25
|
+
b = i.frame_binding(n)
|
|
26
|
+
rescue ArgumentError
|
|
27
|
+
break
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if b
|
|
31
|
+
b.instance_variable_set(:@iseq, i.frame_iseq(n))
|
|
32
|
+
ary << b
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
n += 1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
ary.drop(1)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Number of parent frames available at the point of call.
|
|
43
|
+
# @return [Fixnum]
|
|
44
|
+
def frame_count
|
|
45
|
+
callers.size - 1
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The type of the frame.
|
|
49
|
+
# @return [Symbol]
|
|
50
|
+
def frame_type
|
|
51
|
+
return nil if !@iseq
|
|
52
|
+
|
|
53
|
+
# apparently the 9th element of the iseq array holds the frame type
|
|
54
|
+
# ...not sure how reliable this is.
|
|
55
|
+
@frame_type ||= @iseq.to_a[9]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The description of the frame.
|
|
59
|
+
# @return [String]
|
|
60
|
+
def frame_description
|
|
61
|
+
return nil if !@iseq
|
|
62
|
+
@frame_description ||= @iseq.label
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class ::Binding
|
|
68
|
+
include BindingOfCaller::BindingExtensions
|
|
69
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module BindingOfCaller
|
|
2
|
+
module BindingExtensions
|
|
3
|
+
|
|
4
|
+
# Retrieve the binding of the nth caller of the current frame.
|
|
5
|
+
# @return [Binding]
|
|
6
|
+
def of_caller(n)
|
|
7
|
+
location = Rubinius::VM.backtrace(1 + n, true).first
|
|
8
|
+
|
|
9
|
+
raise RuntimeError, "Invalid frame, gone beyond end of stack!" if location.nil?
|
|
10
|
+
|
|
11
|
+
setup_binding_from_location(location)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# The description of the frame.
|
|
15
|
+
# @return [String]
|
|
16
|
+
def frame_description
|
|
17
|
+
@frame_description
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Return bindings for all caller frames.
|
|
21
|
+
# @return [Array<Binding>]
|
|
22
|
+
def callers
|
|
23
|
+
Rubinius::VM.backtrace(1, true).map &(method(:setup_binding_from_location).
|
|
24
|
+
to_proc)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Number of parent frames available at the point of call.
|
|
28
|
+
# @return [Fixnum]
|
|
29
|
+
def frame_count
|
|
30
|
+
Rubinius::VM.backtrace(1).count
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The type of the frame.
|
|
34
|
+
# @return [Symbol]
|
|
35
|
+
def frame_type
|
|
36
|
+
if compiled_code.for_module_body?
|
|
37
|
+
:class
|
|
38
|
+
elsif compiled_code.for_eval?
|
|
39
|
+
:eval
|
|
40
|
+
elsif compiled_code.is_block?
|
|
41
|
+
:block
|
|
42
|
+
else
|
|
43
|
+
:method
|
|
44
|
+
end
|
|
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
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class ::Binding
|
|
65
|
+
include BindingOfCaller::BindingExtensions
|
|
66
|
+
extend BindingOfCaller::BindingExtensions
|
|
67
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module BindingOfCaller
|
|
2
|
-
VERSION = "0.
|
|
3
|
-
end
|
|
1
|
+
module BindingOfCaller
|
|
2
|
+
VERSION = "0.7.3"
|
|
3
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
dlext = RbConfig::CONFIG['DLEXT']
|
|
2
|
+
|
|
3
|
+
mri_2 = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
|
4
|
+
RUBY_VERSION =~ /^2/
|
|
5
|
+
|
|
6
|
+
if mri_2
|
|
7
|
+
require 'binding_of_caller/mri2'
|
|
8
|
+
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
|
|
9
|
+
require "binding_of_caller.#{dlext}"
|
|
10
|
+
elsif defined?(Rubinius)
|
|
11
|
+
require 'binding_of_caller/rubinius'
|
|
12
|
+
elsif defined?(JRuby)
|
|
13
|
+
require 'binding_of_caller/jruby_interpreted'
|
|
14
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
unless Object.const_defined? :BindingOfCaller
|
|
2
|
+
$:.unshift File.expand_path '../../lib', __FILE__
|
|
3
|
+
require 'binding_of_caller'
|
|
4
|
+
require 'binding_of_caller/version'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class Module
|
|
8
|
+
public :remove_const
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
|
|
12
|
+
puts "Ruby version: #{RUBY_VERSION}"
|
|
13
|
+
|
|
14
|
+
describe BindingOfCaller do
|
|
15
|
+
describe "of_caller" do
|
|
16
|
+
it "should fetch immediate caller's binding when 0 is passed" do
|
|
17
|
+
o = Object.new
|
|
18
|
+
def o.a
|
|
19
|
+
var = 1
|
|
20
|
+
binding.of_caller(0).eval('var')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
o. a.should == 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should fetch parent of caller's binding when 1 is passed" do
|
|
27
|
+
o = Object.new
|
|
28
|
+
def o.a
|
|
29
|
+
var = 1
|
|
30
|
+
b
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def o.b
|
|
34
|
+
binding.of_caller(1).eval('var')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
o.a.should == 1
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should modify locals in parent of caller's binding" do
|
|
41
|
+
o = Object.new
|
|
42
|
+
def o.a
|
|
43
|
+
var = 1
|
|
44
|
+
b
|
|
45
|
+
var
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def o.b
|
|
49
|
+
binding.of_caller(1).eval('var = 20')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
o.a.should == 20
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should raise an exception when retrieving an out of band binding" do
|
|
56
|
+
o = Object.new
|
|
57
|
+
def o.a
|
|
58
|
+
binding.of_caller(100)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
lambda { o.a }.should.raise RuntimeError
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "callers" do
|
|
66
|
+
before do
|
|
67
|
+
@o = Object.new
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'should return the first non-internal binding when using callers.first' do
|
|
71
|
+
def @o.meth
|
|
72
|
+
x = :a_local
|
|
73
|
+
[binding.callers.first, binding.of_caller(0)]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
b1, b2 = @o.meth
|
|
77
|
+
b1.eval("x").should == :a_local
|
|
78
|
+
b2.eval("x").should == :a_local
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "frame_count" do
|
|
83
|
+
it 'frame_count should equal callers.count' do
|
|
84
|
+
binding.frame_count.should == binding.callers.count
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "frame_descripton" do
|
|
89
|
+
it 'can be called on ordinary binding without raising' do
|
|
90
|
+
lambda { binding.frame_description }.should.not.raise
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'describes a block frame' do
|
|
94
|
+
binding.of_caller(0).frame_description.should =~ /block/
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'describes a method frame' do
|
|
98
|
+
o = Object.new
|
|
99
|
+
def o.horsey_malone
|
|
100
|
+
binding.of_caller(0).frame_description.should =~ /horsey_malone/
|
|
101
|
+
end
|
|
102
|
+
o.horsey_malone
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'describes a class frame' do
|
|
106
|
+
class HorseyMalone
|
|
107
|
+
binding.of_caller(0).frame_description.should =~ /class/i
|
|
108
|
+
end
|
|
109
|
+
Object.remove_const(:HorseyMalone)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "frame_type" do
|
|
114
|
+
it 'can be called on ordinary binding without raising' do
|
|
115
|
+
lambda { binding.frame_type }.should.not.raise
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "when inside a class definition" do
|
|
119
|
+
before do
|
|
120
|
+
class HorseyMalone
|
|
121
|
+
@binding = binding.of_caller(0)
|
|
122
|
+
def self.binding; @binding; end
|
|
123
|
+
end
|
|
124
|
+
@binding = HorseyMalone.binding
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'returns :class' do
|
|
128
|
+
@binding.frame_type.should == :class
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "when evaluated" do
|
|
133
|
+
before { @binding = eval("binding.of_caller(0)") }
|
|
134
|
+
|
|
135
|
+
it 'returns :eval' do
|
|
136
|
+
@binding.frame_type.should == :eval
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe "when inside a block" do
|
|
141
|
+
before { @binding = proc { binding.of_caller(0) }.call }
|
|
142
|
+
|
|
143
|
+
it 'returns :block' do
|
|
144
|
+
@binding.frame_type.should == :block
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe "when inside an instance method" do
|
|
149
|
+
before do
|
|
150
|
+
o = Object.new
|
|
151
|
+
def o.a; binding.of_caller(0); end
|
|
152
|
+
@binding = o.a;
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'returns :method' do
|
|
156
|
+
@binding.frame_type.should == :method
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
metadata
CHANGED
|
@@ -1,29 +1,59 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: binding_of_caller
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.7.3
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- John Mair (banisterfiend)
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: debug_inspector
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ! '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.0.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ! '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.0.1
|
|
14
27
|
- !ruby/object:Gem::Dependency
|
|
15
28
|
name: bacon
|
|
16
|
-
requirement:
|
|
17
|
-
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ! '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
44
|
requirements:
|
|
19
|
-
- -
|
|
45
|
+
- - ! '>='
|
|
20
46
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
47
|
+
version: '0'
|
|
22
48
|
type: :development
|
|
23
49
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
25
55
|
description: Retrieve the binding of a method's caller. Can also retrieve bindings
|
|
26
|
-
even further up the stack.
|
|
56
|
+
even further up the stack.
|
|
27
57
|
email: jrmair@gmail.com
|
|
28
58
|
executables: []
|
|
29
59
|
extensions:
|
|
@@ -32,18 +62,21 @@ extra_rdoc_files: []
|
|
|
32
62
|
files:
|
|
33
63
|
- .gemtest
|
|
34
64
|
- .gitignore
|
|
65
|
+
- .travis.yml
|
|
35
66
|
- .yardopts
|
|
67
|
+
- Gemfile
|
|
36
68
|
- HISTORY
|
|
37
69
|
- LICENSE
|
|
38
70
|
- README.md
|
|
39
71
|
- Rakefile
|
|
72
|
+
- binding_of_caller.gemspec
|
|
73
|
+
- examples/benchmark.rb
|
|
40
74
|
- examples/example.rb
|
|
41
75
|
- ext/binding_of_caller/binding_of_caller.c
|
|
42
76
|
- ext/binding_of_caller/extconf.rb
|
|
43
77
|
- ext/binding_of_caller/ruby_headers/192/debug.h
|
|
44
78
|
- ext/binding_of_caller/ruby_headers/192/dln.h
|
|
45
79
|
- ext/binding_of_caller/ruby_headers/192/eval_intern.h
|
|
46
|
-
- ext/binding_of_caller/ruby_headers/192/gc.h
|
|
47
80
|
- ext/binding_of_caller/ruby_headers/192/id.h
|
|
48
81
|
- ext/binding_of_caller/ruby_headers/192/iseq.h
|
|
49
82
|
- ext/binding_of_caller/ruby_headers/192/method.h
|
|
@@ -51,6 +84,7 @@ files:
|
|
|
51
84
|
- ext/binding_of_caller/ruby_headers/192/regenc.h
|
|
52
85
|
- ext/binding_of_caller/ruby_headers/192/regint.h
|
|
53
86
|
- ext/binding_of_caller/ruby_headers/192/regparse.h
|
|
87
|
+
- ext/binding_of_caller/ruby_headers/192/rubys_gc.h
|
|
54
88
|
- ext/binding_of_caller/ruby_headers/192/thread_pthread.h
|
|
55
89
|
- ext/binding_of_caller/ruby_headers/192/thread_win32.h
|
|
56
90
|
- ext/binding_of_caller/ruby_headers/192/timev.h
|
|
@@ -67,7 +101,6 @@ files:
|
|
|
67
101
|
- ext/binding_of_caller/ruby_headers/193/dln.h
|
|
68
102
|
- ext/binding_of_caller/ruby_headers/193/encdb.h
|
|
69
103
|
- ext/binding_of_caller/ruby_headers/193/eval_intern.h
|
|
70
|
-
- ext/binding_of_caller/ruby_headers/193/gc.h
|
|
71
104
|
- ext/binding_of_caller/ruby_headers/193/id.h
|
|
72
105
|
- ext/binding_of_caller/ruby_headers/193/internal.h
|
|
73
106
|
- ext/binding_of_caller/ruby_headers/193/iseq.h
|
|
@@ -78,6 +111,7 @@ files:
|
|
|
78
111
|
- ext/binding_of_caller/ruby_headers/193/regint.h
|
|
79
112
|
- ext/binding_of_caller/ruby_headers/193/regparse.h
|
|
80
113
|
- ext/binding_of_caller/ruby_headers/193/revision.h
|
|
114
|
+
- ext/binding_of_caller/ruby_headers/193/rubys_gc.h
|
|
81
115
|
- ext/binding_of_caller/ruby_headers/193/thread_pthread.h
|
|
82
116
|
- ext/binding_of_caller/ruby_headers/193/thread_win32.h
|
|
83
117
|
- ext/binding_of_caller/ruby_headers/193/timev.h
|
|
@@ -88,32 +122,35 @@ files:
|
|
|
88
122
|
- ext/binding_of_caller/ruby_headers/193/vm_exec.h
|
|
89
123
|
- ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h
|
|
90
124
|
- ext/binding_of_caller/ruby_headers/193/vm_opts.h
|
|
125
|
+
- lib/binding_of_caller.rb
|
|
126
|
+
- lib/binding_of_caller/jruby_interpreted.rb
|
|
127
|
+
- lib/binding_of_caller/mri2.rb
|
|
128
|
+
- lib/binding_of_caller/rubinius.rb
|
|
91
129
|
- lib/binding_of_caller/version.rb
|
|
92
|
-
- test/
|
|
130
|
+
- test/test_binding_of_caller.rb
|
|
93
131
|
homepage: http://github.com/banister/binding_of_caller
|
|
94
132
|
licenses: []
|
|
133
|
+
metadata: {}
|
|
95
134
|
post_install_message:
|
|
96
135
|
rdoc_options: []
|
|
97
136
|
require_paths:
|
|
98
137
|
- lib
|
|
99
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
|
-
none: false
|
|
101
139
|
requirements:
|
|
102
140
|
- - ! '>='
|
|
103
141
|
- !ruby/object:Gem::Version
|
|
104
|
-
version:
|
|
142
|
+
version: '0'
|
|
105
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
|
-
none: false
|
|
107
144
|
requirements:
|
|
108
145
|
- - ! '>='
|
|
109
146
|
- !ruby/object:Gem::Version
|
|
110
147
|
version: '0'
|
|
111
148
|
requirements: []
|
|
112
149
|
rubyforge_project:
|
|
113
|
-
rubygems_version:
|
|
150
|
+
rubygems_version: 2.6.13
|
|
114
151
|
signing_key:
|
|
115
|
-
specification_version:
|
|
152
|
+
specification_version: 4
|
|
116
153
|
summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
|
|
117
|
-
further up the stack.
|
|
154
|
+
further up the stack.
|
|
118
155
|
test_files:
|
|
119
|
-
- test/
|
|
156
|
+
- test/test_binding_of_caller.rb
|
data/test/test.rb
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
unless Object.const_defined? :BindingOfCaller
|
|
2
|
-
$:.unshift File.expand_path '../../lib', __FILE__
|
|
3
|
-
require 'binding_of_caller'
|
|
4
|
-
require 'binding_of_caller/version'
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
|
|
8
|
-
puts "Ruby version: #{RUBY_VERSION}"
|
|
9
|
-
|
|
10
|
-
describe BindingOfCaller do
|
|
11
|
-
describe "of_caller" do
|
|
12
|
-
it "should fetch immediate caller's binding when 0 is passed" do
|
|
13
|
-
o = Object.new
|
|
14
|
-
def o.a
|
|
15
|
-
var = 1
|
|
16
|
-
binding.of_caller(0).eval('var')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
o. a.should == 1
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should fetch parent of caller's binding when 1 is passed" do
|
|
23
|
-
o = Object.new
|
|
24
|
-
def o.a
|
|
25
|
-
var = 1
|
|
26
|
-
b
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def o.b
|
|
30
|
-
binding.of_caller(1).eval('var')
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
o.a.should == 1
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "should modify locals in parent of caller's binding" do
|
|
37
|
-
o = Object.new
|
|
38
|
-
def o.a
|
|
39
|
-
var = 1
|
|
40
|
-
b
|
|
41
|
-
var
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def o.b
|
|
45
|
-
binding.of_caller(1).eval('var = 20')
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
o.a.should == 20
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should raise an exception when retrieving an out of band binding" do
|
|
52
|
-
o = Object.new
|
|
53
|
-
def o.a
|
|
54
|
-
binding.of_caller(100)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
lambda { o.a }.should.raise RuntimeError
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "frame_count" do
|
|
62
|
-
it 'frame_count should equal callers.count' do
|
|
63
|
-
binding.frame_count.should == binding.callers.count
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe "frame_type" do
|
|
68
|
-
it 'should return the correct frame types' do
|
|
69
|
-
o = Object.new
|
|
70
|
-
|
|
71
|
-
# method frame
|
|
72
|
-
def o.a
|
|
73
|
-
b
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# method frame
|
|
77
|
-
def o.b
|
|
78
|
-
# block frame
|
|
79
|
-
proc do
|
|
80
|
-
binding.callers
|
|
81
|
-
end.call
|
|
82
|
-
end
|
|
83
|
-
caller_bindings = o.a
|
|
84
|
-
caller_bindings[0].frame_type.should == :block
|
|
85
|
-
caller_bindings[1].frame_type.should == :method
|
|
86
|
-
caller_bindings[2].frame_type.should == :method
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
File without changes
|
|
File without changes
|