isomorfeus-puppetmaster 0.8.7 → 0.9.0

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: 016c90cdca1516240ceedbc87ec0d0e20a0e69e03f45e269a658bb5122cc1352
4
- data.tar.gz: 289cedf184ca3dac83b894a6e21ea5ff627b1ad791b9e2915b695ec1dff4ec45
3
+ metadata.gz: 15e9e4489049aa4200345e6d13ad409cbc2ef7c7972ef2cd5db102b64f3dec1c
4
+ data.tar.gz: 40fe9fb73dcb739e21c49eb2e9c28c72926d151b1e588b6155bb3f999ff88592
5
5
  SHA512:
6
- metadata.gz: b9ae0a91cd8419f61577133cf5eb63d9b8a34164bf13e3ccb21250c4e35f16f06d683a3e66ebd49b74f72fa0db798c0a111b499e93302408d82b18bfe1ee8b7d
7
- data.tar.gz: '009fc4d978d95cb80b356893f2cac092a1923afe2a67e87854e7890892ce2a5b0f7fef9901ec449ac47515f37b6944598d65eb38b166e4f975018476d2cf50a0'
6
+ metadata.gz: 323ace6f65009c749f0de5180475c00f29c8637331fff5bd6cf9ac99ffd80582b22830fc8594780a02021bea50014f5bf541adef8bee6b7024a645a0ae4958ab
7
+ data.tar.gz: '09369cf80cef929cbea6734ef3464ea4df59ad582636fedb3c28354ad0e4eb1452af4434d6746972203cb01763a74f2d2d06559abcc616ea077cb910f00b9f88'
@@ -1,7 +1,7 @@
1
1
  class Puppeteer::ExecutionContext
2
- def eval_ruby(ruby_source = '', &block)
3
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
4
- compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source)
2
+ def eval_ruby(ruby_source = '', file = nil, _line = nil, &block)
3
+ ruby_source, file = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
4
+ compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source, file)
5
5
  res = evaluate <<~JAVASCRIPT
6
6
  function(){
7
7
  let fun = function() {
@@ -9,8 +9,20 @@ class Puppeteer::ExecutionContext
9
9
  catch (e) { return { error: e.name, message: e.message, stack: e.stack }; }
10
10
  }
11
11
  let res = fun();
12
- if (res && res.$to_n) { res = res.$to_n(); }
13
- return ((res === Opal.nil) ? null : res);
12
+ if (res && res.$to_n) res = res.$to_n();
13
+ let conv = function(o) {
14
+ if (o === Opal.nil) o = null;
15
+ if (o && typeof(o) === 'object') {
16
+ if (o.constructor && o.constructor.name === 'Map') o = Object.fromEntries(o);
17
+ if (Array.isArray(o)) {
18
+ for (let i = 0; i < o.length; i++) o[i] = conv(o[i]);
19
+ } else {
20
+ for (let i in o) o[i] = conv(o[i]);
21
+ }
22
+ }
23
+ return o;
24
+ }
25
+ return conv(res);
14
26
  }
15
27
  JAVASCRIPT
16
28
  if res.is_a?(Hash) && res.key?('error') && res.key?('message') && res.key?('stack')
@@ -21,9 +33,9 @@ class Puppeteer::ExecutionContext
21
33
  res
22
34
  end
23
35
 
24
- def eval_with_opal(ruby_source = '', &block)
25
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
26
- compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source)
36
+ def eval_with_opal(ruby_source = '', file = nil, _line = nil, &block)
37
+ ruby_source, file = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
38
+ compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source, file)
27
39
  res = evaluate <<~JAVASCRIPT
28
40
  function(){
29
41
  let fun = function(){
@@ -34,8 +46,20 @@ class Puppeteer::ExecutionContext
34
46
  catch (e) { return { error: e.name, message: e.message, stack: e.stack }; }
35
47
  }
36
48
  let res = fun();
37
- if (res && res.$to_n) { res = res.$to_n(); }
38
- return (res === Opal.nil) ? null : res;
49
+ if (res && res.$to_n) res = res.$to_n();
50
+ let conv = function(o) {
51
+ if (o === Opal.nil) o = null;
52
+ if (o && typeof(o) === 'object') {
53
+ if (o.constructor && o.constructor.name === 'Map') o = Object.fromEntries(o);
54
+ if (Array.isArray(o)) {
55
+ for (let i = 0; i < o.length; i++) o[i] = conv(o[i]);
56
+ } else {
57
+ for (let i in o) o[i] = conv(o[i]);
58
+ }
59
+ }
60
+ return o;
61
+ }
62
+ return conv(res);
39
63
  }
40
64
  JAVASCRIPT
41
65
  if res.is_a?(Hash) && res.key?('error') && res.key?('message') && res.key?('stack')
@@ -46,10 +70,10 @@ class Puppeteer::ExecutionContext
46
70
  res
47
71
  end
48
72
 
49
- def await_ruby(ruby_source = '', &block)
50
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
73
+ def await_ruby(ruby_source = '', file = nil, line = nil, &block)
74
+ ruby_source, file = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
51
75
  ruby_source = "#{ruby_source}.always { |result| $promise_result = result; $promise_resolved = true }"
52
- compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source)
76
+ compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source, file)
53
77
  evaluate <<~JAVASCRIPT
54
78
  function(){
55
79
  fun = function() {
@@ -76,7 +100,7 @@ class Puppeteer::ExecutionContext
76
100
  have_result = evaluate 'function() { return Opal ? Opal.gvars.promise_resolved : null; }'
77
101
  sleep 0.1 unless have_result
78
102
  end
79
- result, exception = evaluate <<~JAVASCRIPT
103
+ res, exception = evaluate <<~JAVASCRIPT
80
104
  function () {
81
105
  var res;
82
106
  var exception = false;
@@ -91,9 +115,20 @@ class Puppeteer::ExecutionContext
91
115
  } else { res = Opal.gvars.promise_result };
92
116
  delete Opal.gvars.promise_result;
93
117
  delete Opal.gvars.promise_resolved;
94
- if (res && res.$to_n) { res = res.$to_n(); }
95
- res = ((res === Opal.nil) ? null : res);
96
- return [res, exception];
118
+ if (res && res.$to_n) res = res.$to_n();
119
+ let conv = function(o) {
120
+ if (o === Opal.nil) o = null;
121
+ if (o && typeof(o) === 'object') {
122
+ if (o.constructor && o.constructor.name === 'Map') o = Object.fromEntries(o);
123
+ if (Array.isArray(o)) {
124
+ for (let i = 0; i < o.length; i++) o[i] = conv(o[i]);
125
+ } else {
126
+ for (let i in o) o[i] = conv(o[i]);
127
+ }
128
+ }
129
+ return o;
130
+ }
131
+ return [conv(res), exception];
97
132
  }
98
133
  JAVASCRIPT
99
134
  if exception
@@ -101,6 +136,6 @@ class Puppeteer::ExecutionContext
101
136
  e.set_backtrace(exception['stack'])
102
137
  raise e
103
138
  end
104
- result
139
+ res
105
140
  end
106
141
  end
@@ -3,16 +3,16 @@ class Puppeteer::Frame
3
3
  self.Sx(x).first
4
4
  end
5
5
 
6
- def eval_ruby(ruby_source = '', &block)
7
- @main_world.eval_ruby(ruby_source, &block)
6
+ def eval_ruby(ruby_source = '', file = nil, line = nil, &block)
7
+ @main_world.eval_ruby(ruby_source, file, line, &block)
8
8
  end
9
9
 
10
- def eval_with_opal(ruby_source = '', &block)
11
- @main_world.eval_with_opal(ruby_source, &block)
10
+ def eval_with_opal(ruby_source = '', file = nil, line = nil, &block)
11
+ @main_world.eval_with_opal(ruby_source, file, line, &block)
12
12
  end
13
13
 
14
- def await_ruby(ruby_source = '', &block)
15
- @main_world.await_ruby(ruby_source, &block)
14
+ def await_ruby(ruby_source = '', file = nil, line = nil, &block)
15
+ @main_world.await_ruby(ruby_source, file, line, &block)
16
16
  end
17
17
 
18
18
  alias_method :find, :query_selector
@@ -1,13 +1,13 @@
1
1
  class Puppeteer::IsolaatedWorld
2
- def eval_ruby(ruby_source = '', &block)
3
- execution_context.eval_ruby(ruby_source, &block)
2
+ def eval_ruby(ruby_source = '', file = nil, line = nil, &block)
3
+ execution_context.eval_ruby(ruby_source, file, line, &block)
4
4
  end
5
5
 
6
- def eval_with_opal(ruby_source = '', &block)
7
- execution_context.eval_with_opal(ruby_source, &block)
6
+ def eval_with_opal(ruby_source = '', file = nil, line = nil, &block)
7
+ execution_context.eval_with_opal(ruby_source, file, line, &block)
8
8
  end
9
9
 
10
- def await_ruby(ruby_source = '', &block)
11
- execution_context.await_ruby(ruby_source, &block)
10
+ def await_ruby(ruby_source = '', file = nil, line = nil, &block)
11
+ execution_context.await_ruby(ruby_source, file, line, &block)
12
12
  end
13
13
  end
@@ -1,13 +1,13 @@
1
1
  class Puppeteer::JSHandle
2
- def eval_ruby(ruby_source = '', &block)
3
- execution_context.eval_ruby(ruby_source, &block)
2
+ def eval_ruby(ruby_source = '', file = nil, line = nil, &block)
3
+ execution_context.eval_ruby(ruby_source, file, line, &block)
4
4
  end
5
5
 
6
- def eval_with_opal(ruby_source = '', &block)
7
- execution_context.eval_with_opal(ruby_source, &block)
6
+ def eval_with_opal(ruby_source = '', file = nil, line = nil, &block)
7
+ execution_context.eval_with_opal(ruby_source, file, line, &block)
8
8
  end
9
9
 
10
- def await_ruby(ruby_source = '', &block)
11
- execution_context.await_ruby(ruby_source, &block)
10
+ def await_ruby(ruby_source = '', file = nil, line = nil, &block)
11
+ execution_context.await_ruby(ruby_source, file, line, &block)
12
12
  end
13
13
  end
@@ -43,16 +43,16 @@ class Puppeteer::Page
43
43
  click_el(selector, button: button, click_count: 2, delay: delay)
44
44
  end
45
45
 
46
- def eval_ruby(ruby_source = '', &block)
47
- main_frame.eval_ruby(ruby_source, &block)
46
+ def eval_ruby(ruby_source = '', file = nil, line = nil, &block)
47
+ main_frame.eval_ruby(ruby_source, file, line, &block)
48
48
  end
49
49
 
50
- def eval_with_opal(ruby_source = '', &block)
51
- main_frame.eval_with_opal(ruby_source, &block)
50
+ def eval_with_opal(ruby_source = '', file = nil, line = nil, &block)
51
+ main_frame.eval_with_opal(ruby_source, file, line, &block)
52
52
  end
53
53
 
54
- def await_ruby(ruby_source = '', &block)
55
- main_frame.await_ruby(ruby_source, &block)
54
+ def await_ruby(ruby_source = '', file = nil, line = nil, &block)
55
+ main_frame.await_ruby(ruby_source, file, line, &block)
56
56
  end
57
57
 
58
58
  def exec(j, *args)
@@ -102,15 +102,15 @@ class Puppeteer::Page
102
102
  alias_method :text, :inner_text
103
103
 
104
104
  def isomorphic(ruby_source = '', &block)
105
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
106
- Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
107
- eval_ruby(ruby_source)
105
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
106
+ Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, file, line)
107
+ eval_ruby(ruby_source, file, line)
108
108
  end
109
109
 
110
110
  def isomorphic_with_opal(ruby_source = '', &block)
111
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
112
- Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
113
- eval_with_opal(ruby_source)
111
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
112
+ Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, file, line)
113
+ eval_with_opal(ruby_source, file, line)
114
114
  end
115
115
 
116
116
  def path
@@ -42,16 +42,16 @@ module Isomorfeus
42
42
  end
43
43
  alias_method :goto, :visit
44
44
 
45
- def isomorphic(ruby_source = '', &block)
46
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
47
- on_server(ruby_source)
48
- default_page.eval_ruby(ruby_source)
45
+ def isomorphic(ruby_source = '', file = nil, line = nil, &block)
46
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
47
+ on_server(ruby_source, file, line)
48
+ default_page.eval_ruby(ruby_source, file, line)
49
49
  end
50
50
 
51
- def isomorphic_with_opal(ruby_source = '', &block)
52
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
53
- on_server(ruby_source)
54
- default_page.eval_with_opal(ruby_source)
51
+ def isomorphic_with_opal(ruby_source = '', file = nil, line = nil, &block)
52
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
53
+ on_server(ruby_source, file, line)
54
+ default_page.eval_with_opal(ruby_source, file, line)
55
55
  end
56
56
 
57
57
  def on_server(ruby_source = '', &block)
@@ -106,10 +106,10 @@ module Isomorfeus
106
106
  nil
107
107
  end
108
108
 
109
- def on_server(ruby_source = '', &block)
109
+ def on_server(ruby_source = '', file = nil, line = nil, &block)
110
110
  session # ensure served_app booted
111
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
112
- Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
111
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
112
+ Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, file, line)
113
113
  end
114
114
 
115
115
  def session(headless: true, devtools: false)
@@ -27,7 +27,7 @@ module Isomorfeus
27
27
  Isomorfeus.init_store
28
28
  Isomorfeus.store.clear! if Isomorfeus.store.respond_to?(:clear!)
29
29
  end
30
- result = TOPLEVEL_BINDING.eval(request_hash['code']) if request_hash['code']
30
+ result = TOPLEVEL_BINDING.eval(request_hash['code'], request_hash['file'], request_hash['line']) if request_hash['code']
31
31
  result = result.value if result.is_a?(Promise)
32
32
  response = Rack::Response.new(Oj.dump({ 'result' => result }, circular: true),
33
33
  200,
@@ -75,9 +75,9 @@ module Isomorfeus
75
75
  middleware.error
76
76
  end
77
77
 
78
- def on_server(ruby_source = '', &block)
79
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
80
- request_hash = { 'key' => @request_key, 'code' => ruby_source }
78
+ def on_server(ruby_source = '', file = nil, line = nil, &block)
79
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
80
+ request_hash = { 'key' => @request_key, 'code' => ruby_source, 'file' => file, 'line' => line }
81
81
  response = if using_ssl?
82
82
  http = Net::HTTP.start(@host, @port, { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE })
83
83
  http.post('/__executor__', Oj.dump(request_hash, mode: :strict))
@@ -98,50 +98,24 @@ module Isomorfeus
98
98
  r&.json_value
99
99
  end
100
100
 
101
- def eval_ruby(ruby_source = '', &block)
102
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
103
- compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source)
104
- res = self.evaluate "function(){ try { return #{compiled_ruby} } catch (e) { return { error: e.name, message: e.message, stack: e.stack }; }}"
105
- if res.is_a?(Hash) && res.key?('error') && res.key?('message') && res.key?('stack')
106
- e = RuntimeError.new("#{res['error']}: #{res['message']}")
107
- e.set_backtrace(res['stack'].lines)
108
- raise e
109
- end
110
- res
111
- end
112
-
113
- def eval_with_opal(ruby_source = '', &block)
114
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
115
- compiled_ruby = Isomorfeus::Puppetmaster.compile_ruby_source(ruby_source)
116
- res = self.evaluate <<~JAVASCRIPT
117
- function(){
118
- if (typeof Opal === "undefined") {
119
- #{Isomorfeus::Puppetmaster.opal_prelude}
120
- }
121
- try { return #{compiled_ruby} }
122
- catch (e) { return { error: e.name, message: e.message, stack: e.stack }; }
123
- }
124
- JAVASCRIPT
125
- if res.is_a?(Hash) && res.key?('error') && res.key?('message') && res.key?('stack')
126
- e = RuntimeError.new("#{res['error']}: #{res['message']}")
127
- e.set_backtrace(res['stack'].lines)
128
- raise e
129
- end
130
- res
131
- rescue Puppeteer::ExecutionContext::EvaluationError => e
132
- raise Isomorfeus::Puppetmaster::JavaScriptError.new(e.message)
101
+ def eval_ruby(ruby_source = '', file = nil, line = nil, &block)
102
+ @default_page.eval_ruby(ruby_source, file, line, &block)
103
+ end
104
+
105
+ def eval_with_opal(ruby_source = '', file = nil, line = nil, &block)
106
+ @default_page.eval_with_opal(ruby_source, file, line, &block)
133
107
  end
134
108
 
135
- def isomorphic(ruby_source = '', &block)
136
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
137
- Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
138
- eval_ruby(ruby_source)
109
+ def isomorphic(ruby_source = '', file = nil, line = nil, &block)
110
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
111
+ Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, file, line)
112
+ eval_ruby(ruby_source, file, line)
139
113
  end
140
114
 
141
- def isomorphic_with_opal(ruby_source = '', &block)
142
- ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
143
- Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
144
- eval_with_opal(ruby_source)
115
+ def isomorphic_with_opal(ruby_source = '', file = nil, line = nil, &block)
116
+ ruby_source, file, line = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
117
+ Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, file, line)
118
+ eval_with_opal(ruby_source, file, line)
145
119
  end
146
120
 
147
121
  private
@@ -1,3 +1,3 @@
1
1
  module Isomorfeus
2
- PUPPETMASTER_VERSION = '0.8.7'
2
+ PUPPETMASTER_VERSION = '0.9.0'
3
3
  end
@@ -14,11 +14,11 @@ module Isomorfeus
14
14
  source_block = source_block.children[source_block.children.index { |c| c.respond_to?(:type) && c.type == :block }]
15
15
  end
16
16
  source_block = source_block.children[2]
17
- Unparser.unparse(source_block)
17
+ [ Unparser.unparse(source_block), block.source_location[0], block.source_location[1]]
18
18
  end
19
19
 
20
- def compile_ruby_source(source_code)
21
- Opal.compile(source_code)
20
+ def compile_ruby_source(source_code, file)
21
+ Opal.compile(source_code, { file: file, backtick_javascript: true })
22
22
  end
23
23
 
24
24
  def opal_prelude
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-puppetmaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-18 00:00:00.000000000 Z
11
+ date: 2023-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport