forked from gsamokovarov/web-console
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from gsamokovarov/revamped-integrations
Revamped integrations for CRuby and Rubinius
- Loading branch information
Showing
6 changed files
with
70 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'binding_of_caller' | ||
|
||
require 'active_support/lazy_load_hooks' | ||
require 'active_support/logger' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,23 @@ | ||
class Exception | ||
begin | ||
# We share the same exception binding extraction mechanism as better_errors, | ||
# so try to use it if it is already available. It also solves problems like | ||
# charliesome/better_errors#272, caused by an infinite recursion. | ||
require 'better_errors' | ||
require 'debug_inspector' | ||
|
||
# The bindings in which the exception originated in. | ||
def bindings | ||
@bindings || __better_errors_bindings_stack | ||
end | ||
rescue LoadError | ||
# The bindings in which the exception originated in. | ||
def bindings | ||
@bindings || [] | ||
end | ||
|
||
# CRuby calls #set_backtrace every time it raises an exception. Overriding | ||
# it to assign the #bindings. | ||
def set_backtrace_with_binding_of_caller(*args) | ||
# Thanks to @charliesome who wrote this bit for better_errors. | ||
unless Thread.current[:__web_console_exception_lock] | ||
Thread.current[:__web_console_exception_lock] = true | ||
begin | ||
# Raising an exception here will cause all of the rubies to go into a | ||
# stack overflow. Some rubies may even segfault. See | ||
# https://bugs.ruby-lang.org/issues/10164 for details. | ||
@bindings = binding.callers.drop(1) | ||
ensure | ||
Thread.current[:__web_console_exception_lock] = false | ||
end | ||
end | ||
def WebConsole.caller_bindings | ||
bindings = RubyVM::DebugInspector.open do |context| | ||
context.backtrace_locations.each_index.map { |i| context.frame_binding(i) } | ||
end | ||
|
||
set_backtrace_without_binding_of_caller(*args) | ||
end | ||
# For C functions, we can't extract a binding. In this case, | ||
# DebugInspector#frame_binding would have returned us nil. That's why we need | ||
# to compact the bindings. | ||
# | ||
# Dropping two bindings, removes the current Ruby one in this exact method, | ||
# and the one in the caller method. The caller method binding can be obtained | ||
# by Kernel#binding, if needed. | ||
bindings.compact.drop(2) | ||
end | ||
|
||
alias_method :set_backtrace_without_binding_of_caller, :set_backtrace | ||
alias_method :set_backtrace, :set_backtrace_with_binding_of_caller | ||
TracePoint.trace(:raise) do |context| | ||
exc = context.raised_exception | ||
if exc.bindings.empty? | ||
exc.instance_variable_set(:@bindings, WebConsole.caller_bindings) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters