hyper-trace 1.0.alpha1.5 → 1.0.alpha1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72e4c43e022951e041fd3ab3d39b7a754db0e851ad945d37ad55c80384067167
4
- data.tar.gz: b6d8cee0cd90619cd95edfb3edceb401a5f80c40ffe37836e3bedf7d3f87e50f
3
+ metadata.gz: c6d5ca551c3d53aed42d30e704e8693ac198334bf5541a6510b189f204a3cc12
4
+ data.tar.gz: e045dcd8a419ba9e668ff812bfb61894f870c7e8c6e293d0faee34a8ff9b3e91
5
5
  SHA512:
6
- metadata.gz: 82b0c168d127bea5330e362d5ed77c3ee5f0321a25d3e33980bc86a8d4fb36328258d7671fad6c9c3300cf7c2ceb9dad10eac846c61b47803ad403e6a95fa304
7
- data.tar.gz: 8d1053f7143d6df457c94e565921e8ec44f3a2a4f550c1c30523850fd71d2a383abe69097a747abd793557fc5ad7140b2f1ab0148a3f867eabfe68ae6d4e486a
6
+ metadata.gz: a3bfae4412a203c094f94dd9bec1fa0243bf3cebcb3d0a05b1d6268f783cccda446693bf5bfbe3b1cb9e0c24abb5fa0a5fcab69a9663606cf62a4b584ddbdce5
7
+ data.tar.gz: e3414d52e8c55e20d13ac59ca4253b6405b5e7653402ca9ae733bb0c81d7922f9a945413f5b5ce8905dd4e9d8f01883cefece8d91b267c12943ede8e088d0388
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
  gem 'hyperstack-config', path: '../hyperstack-config'
3
+ gem 'hyper-spec', path: '../hyper-spec'
3
4
  # Specify your gem's dependencies in hyper-trace.gemspec
4
5
  gemspec
data/hyper-trace.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'hyperstack-config', HyperTrace::VERSION
22
- spec.add_development_dependency "bundler", ['>= 1.17.3', '< 2.1']
22
+ spec.add_development_dependency 'hyper-spec', HyperTrace::VERSION
23
+ spec.add_development_dependency "bundler"
23
24
  spec.add_development_dependency 'chromedriver-helper'
24
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake"
25
26
  end
@@ -6,17 +6,7 @@ class Class
6
6
  alias hypertrace hyper_trace
7
7
  end
8
8
 
9
- class Method
10
- def parameters
11
- /.*function[^(]*\(([^)]*)\)/
12
- .match(`#{@method}.toString()`)[1]
13
- .split(',')
14
- .collect { |param| [:req, param.strip.to_sym] }
15
- end
16
- end
17
-
18
9
  module HyperTrace
19
-
20
10
  class Config
21
11
  def initialize(klass, instrument_class, opts, &block)
22
12
  @klass = klass
@@ -116,15 +106,11 @@ module HyperTrace
116
106
  def instrumentation_off(config)
117
107
  if config.instrument_class?
118
108
  config.klass.methods.grep(/^__hyper_trace_pre_.+$/).each do |method|
119
- config.klass.class_eval do
120
- class << self
121
- alias_method method.gsub(/^__hyper_trace_pre_/, ''), method
122
- end
123
- end
109
+ config.klass.singleton_class.alias_method method.gsub(/^__hyper_trace_pre_/, ''), method
124
110
  end
125
111
  else
126
112
  config.klass.instance_methods.grep(/^__hyper_trace_pre_.+$/).each do |method|
127
- config.klass.class_eval { alias_method method.gsub(/^__hyper_trace_pre_/, ''), method }
113
+ config.klass.alias_method method.gsub(/^__hyper_trace_pre_/, ''), method
128
114
  end
129
115
  end
130
116
  end
@@ -145,17 +131,12 @@ module HyperTrace
145
131
 
146
132
  def instrument_method(method, config)
147
133
  if config.instrument_class?
148
- config.klass.class_eval do
149
- class << self
150
- alias_method "__hyper_trace_pre_#{method}", method unless method_defined? "__pre_hyper_trace_#{method}"
151
- end
134
+ unless config.klass.singleton_class.method_defined? "__pre_hyper_trace_#{method}" # is this right?
135
+ config.klass.singleton_class.alias_method "__hyper_trace_pre_#{method}", method
152
136
  end
153
- add_hyper_trace_method(method, config)
154
137
  else
155
138
  unless config.klass.method_defined? "__pre_hyper_trace_#{method}"
156
- config.klass.class_eval do
157
- alias_method "__hyper_trace_pre_#{method}", method
158
- end
139
+ config.klass.alias_method "__hyper_trace_pre_#{method}", method
159
140
  end
160
141
  end
161
142
  add_hyper_trace_method(method, config)
@@ -194,28 +175,77 @@ module HyperTrace
194
175
  end
195
176
  end
196
177
 
178
+ def required(arity, actual_length)
179
+ if arity.negative?
180
+ req_count = - arity - 1
181
+ raise ArgumentError, "missing required arguments: #{actual_length} for #{req_count}" if req_count > actual_length
182
+ else
183
+ req_count = arity
184
+ raise ArgumentError, "incorrect number of arguments, expected #{req_count} got #{actual_length}" if req_count != actual_length
185
+ end
186
+ req_count
187
+ end
188
+
189
+ # [["req", "x"], ["opt", "y"], ["rest"], ["keyreq", "z"], ["key", "opt"], ["block", "flop"]]
190
+
191
+ def map_parameters(instance, name, actual, format = true)
192
+ method = instance.method("__hyper_trace_pre_#{name}")
193
+ map_with_specs(method, actual.dup, format) || map_without_specs(actual, format)
194
+ end
195
+
196
+ def key?(actual, key)
197
+ actual&.last&.respond_to?(:key?) && actual.last.key?(key)
198
+ end
199
+
200
+ def map_with_specs(method, actual, show_blank_rest)
201
+ specs = method.parameters
202
+ req_count = required(method.arity, actual.length)
203
+ args = {}
204
+
205
+ specs.each do |type, key|
206
+ case type
207
+ when :req
208
+ args[key] = actual.shift
209
+ req_count -= 1
210
+ when :opt
211
+ args[key] = actual.shift if actual.length > req_count
212
+ when (key || show_blank_rest) && :rest
213
+ args[key || '*'] = [*actual[0..-req_count - 1]]
214
+ when :keyreq
215
+ raise ArgumentError, "missing keyword argument: #{key}" unless key?(actual, key)
216
+
217
+ args[key] = actual.last[key]
218
+ when key?(actual, key) && :key
219
+ args[key] = actual.last[key]
220
+ end
221
+ end
222
+ args
223
+ rescue ArgumentError, Interrupt, SignalException => e
224
+ raise e
225
+ rescue Exception => e
226
+ nil
227
+ end
228
+
229
+ def map_without_specs(actual, format)
230
+ args = {}
231
+ prefix = 'p' unless format
232
+ actual.each_with_index { |value, i| args["#{prefix}#{i + 1}"] = value }
233
+ args
234
+ end
235
+
197
236
  def format_head(instance, name, args, &block)
198
237
  @formatting = true
199
- method = instance.method("__hyper_trace_pre_#{name}")
200
238
  if args.any?
201
239
  group(" #{name}(...)#{instance_tag(instance)}") do
202
- params = method.parameters
203
- group("args:", collapsed: true) do
204
- params.each_with_index do |param_spec, i|
205
- arg_name = param_spec[1]
206
- if arg_name == '$a_rest'
207
- arg_name = '*'
208
- arg = args[i..-1]
209
- else
210
- arg = args[i]
211
- end
212
- if safe_i(arg).length > 30 || show_js_object(arg)
213
- group "#{arg_name}: #{safe_s(arg)}"[0..29], collapsed: true do
214
- puts safe_i(arg)
215
- log arg if show_js_object(arg)
240
+ group("args: (#{args.length})", collapsed: true) do
241
+ map_parameters(instance, name, args).each do |arg, value|
242
+ if safe_i(value).length > 30 || show_js_object(value)
243
+ group "#{arg}: #{safe_s(value)}"[0..29], collapsed: true do
244
+ puts safe_i(value)
245
+ log value if show_js_object(value)
216
246
  end
217
247
  else
218
- group "#{arg_name}: #{safe_i(arg)}"
248
+ group "#{arg}: #{safe_i(value)}"
219
249
  end
220
250
  end
221
251
  end
@@ -286,7 +316,10 @@ module HyperTrace
286
316
  @formatting = true
287
317
  if safe_i(result).length > 40
288
318
  group "raised: #{safe_s(result)}"[0..40], collapsed: true do
289
- puts safe_i(result)
319
+ puts result.backtrace[0]
320
+ result.backtrace[1..-1].each do |line|
321
+ log line
322
+ end
290
323
  end
291
324
  else
292
325
  group "raised: #{safe_i(result)}"
@@ -305,24 +338,23 @@ module HyperTrace
305
338
 
306
339
  def breakpoint(location, config, name, args, instance, result = nil)
307
340
  if should_break? location, config, name, args, instance, result
308
- method = instance.method("__hyper_trace_pre_#{name}")
341
+ params = map_parameters(instance, name, args, false)
309
342
  fn_def = ['RESULT']
310
- fn_def += method.parameters.collect { |p| p[1] }
343
+ fn_def += params.keys
311
344
  fn_def += ["//break on #{location} of #{name}\nvar self = this;\ndebugger;\n;"]
312
345
  puts "break on #{location} of #{name}"
313
346
  fn = `Function.apply(#{self}, #{fn_def}).bind(#{instance})`
314
- fn.call(result, *args)
347
+ fn.call(result, *params.values)
315
348
  end
316
349
  end
317
350
 
318
- def call_original(instance, method, *args, &block)
351
+ def call_original(instance, method, args, &block)
319
352
  @formatting = false
320
353
  instance.send "__hyper_trace_pre_#{method}", *args, &block
321
354
  ensure
322
355
  @formatting = true
323
356
  end
324
357
 
325
-
326
358
  def add_hyper_trace_method(method, config)
327
359
  def_method = config.instrument_class? ? :define_singleton_method : :define_method
328
360
  config.klass.send(def_method, method) do |*args, &block|
@@ -330,7 +362,7 @@ module HyperTrace
330
362
  if HyperTrace.formatting?
331
363
  begin
332
364
  send "__hyper_trace_pre_#{method}", *args, &block
333
- rescue Exception
365
+ rescue StandardError
334
366
  "???"
335
367
  end
336
368
  else
@@ -338,11 +370,13 @@ module HyperTrace
338
370
  HyperTrace.format_head(self, method, args) do
339
371
  HyperTrace.format_instance_internal(self)
340
372
  HyperTrace.breakpoint(:enter, config, method, args, self)
341
- result = HyperTrace.call_original self, method, *args, &block
373
+ result = HyperTrace.call_original self, method, args, &block
342
374
  HyperTrace.format_result(result)
343
375
  HyperTrace.breakpoint(:exit, config, method, args, self, result)
344
376
  result
345
377
  end
378
+ rescue Interrupt, SignalException => e
379
+ raise e
346
380
  rescue Exception => e
347
381
  HyperTrace.format_exception(e)
348
382
  debugger unless HyperTrace.exclusions[self.class][:rescue].include? :method
@@ -1,3 +1,3 @@
1
1
  module HyperTrace
2
- VERSION = '1.0.alpha1.5'
2
+ VERSION = '1.0.alpha1.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.alpha1.5
4
+ version: 1.0.alpha1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - catmando
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyperstack-config
@@ -16,34 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.alpha1.5
19
+ version: 1.0.alpha1.6
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
- version: 1.0.alpha1.5
26
+ version: 1.0.alpha1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: hyper-spec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.alpha1.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.alpha1.6
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 1.17.3
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '2.1'
47
+ version: '0'
37
48
  type: :development
38
49
  prerelease: false
39
50
  version_requirements: !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - ">="
42
53
  - !ruby/object:Gem::Version
43
- version: 1.17.3
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '2.1'
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: chromedriver-helper
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -62,16 +70,16 @@ dependencies:
62
70
  name: rake
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - "~>"
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
- version: '10.0'
75
+ version: '0'
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
71
79
  requirements:
72
- - - "~>"
80
+ - - ">="
73
81
  - !ruby/object:Gem::Version
74
- version: '10.0'
82
+ version: '0'
75
83
  description:
76
84
  email:
77
85
  - mitch@catprint.com
@@ -108,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
116
  - !ruby/object:Gem::Version
109
117
  version: 1.3.1
110
118
  requirements: []
111
- rubygems_version: 3.0.4
119
+ rubygems_version: 3.0.8
112
120
  signing_key:
113
121
  specification_version: 4
114
122
  summary: Method tracing and conditional breakpoints for Opal Ruby