rustwright 0.2.0-arm64-darwin → 0.3.1-arm64-darwin
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 +4 -4
- data/README.md +4 -4
- data/lib/rustwright/native/arm64-darwin/librustwright_capi.dylib +0 -0
- data/lib/rustwright/native.rb +66 -0
- data/lib/rustwright/wire.rb +210 -51
- data/lib/rustwright.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d1d9c75ae682106197075399dbeafb2ff039b0ff672ad9e6225617f326ad72eb
|
|
4
|
+
data.tar.gz: ce88c29b1a2b175667668f31625ab8ebf426d8cddbf791f71ba90cb8b18adf1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b127ef8994b3b89e304375c65547af9f888b5892b16c128d2cc96a56a757414a168701362e8b2233e00fce07b70d0bb388844aa6a9701a060acd6bc24fb1ccb
|
|
7
|
+
data.tar.gz: 6c5325892cbbf70acc8456fe872f27d45807602fa413ccdea976220c78b2a86c1cf797a934367f9baafbadb2a0aa38b4dd087af2884aba4d5bc65c282a7acdd6
|
data/README.md
CHANGED
|
@@ -6,15 +6,15 @@ JSON is handled by the stdlib `json` package.
|
|
|
6
6
|
|
|
7
7
|
## Install (RubyGems)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Install the gem:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
gem install rustwright
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
Rust build. Supported gem platforms are
|
|
17
|
-
`aarch64-linux`, and `x86_64-linux`. Windows is not currently shipped because
|
|
15
|
+
Then load it with `require 'rustwright'`. The published gems include the native
|
|
16
|
+
C API library and require no separate Rust build. Supported gem platforms are
|
|
17
|
+
`arm64-darwin`, `x86_64-darwin`, `aarch64-linux`, and `x86_64-linux`. Windows is not currently shipped because
|
|
18
18
|
the Rust target, Ruby runtime, and RubyGems platform combinations have not yet
|
|
19
19
|
been validated together.
|
|
20
20
|
|
|
Binary file
|
data/lib/rustwright/native.rb
CHANGED
|
@@ -15,6 +15,24 @@ module Rustwright
|
|
|
15
15
|
rw_last_error: [[], VOIDP],
|
|
16
16
|
rw_string_free: [[VOIDP], VOID],
|
|
17
17
|
rw_bytes_free: [[VOIDP, SIZE_T], VOID],
|
|
18
|
+
rw_wire_graph_parse: [[VOIDP, VOIDP], INT],
|
|
19
|
+
rw_wire_graph_free: [[VOIDP], VOID],
|
|
20
|
+
rw_wire_graph_node_count: [[VOIDP, VOIDP], INT],
|
|
21
|
+
rw_wire_graph_root: [[VOIDP, VOIDP], INT],
|
|
22
|
+
rw_wire_graph_node_kind: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
23
|
+
rw_wire_graph_get_bool: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
24
|
+
rw_wire_graph_get_signed: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
25
|
+
rw_wire_graph_get_unsigned: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
26
|
+
rw_wire_graph_get_float: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
27
|
+
rw_wire_graph_get_string: [[VOIDP, SIZE_T, VOIDP, VOIDP], INT],
|
|
28
|
+
rw_wire_graph_array_length: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
29
|
+
rw_wire_graph_array_child: [[VOIDP, SIZE_T, SIZE_T, VOIDP], INT],
|
|
30
|
+
rw_wire_graph_object_length: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
31
|
+
rw_wire_graph_object_key: [[VOIDP, SIZE_T, SIZE_T, VOIDP, VOIDP], INT],
|
|
32
|
+
rw_wire_graph_object_child: [[VOIDP, SIZE_T, SIZE_T, VOIDP], INT],
|
|
33
|
+
rw_wire_graph_leaf_kind: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
34
|
+
rw_wire_graph_leaf_field_count: [[VOIDP, SIZE_T, VOIDP], INT],
|
|
35
|
+
rw_wire_graph_leaf_field: [[VOIDP, SIZE_T, SIZE_T, VOIDP, VOIDP], INT],
|
|
18
36
|
rw_chromium_executable_path: [[VOIDP], INT],
|
|
19
37
|
rw_chromium_launch: [[VOIDP, VOIDP], INT],
|
|
20
38
|
rw_browser_new_page: [[VOIDP, VOIDP], INT],
|
|
@@ -78,6 +96,54 @@ module Rustwright
|
|
|
78
96
|
slot
|
|
79
97
|
end
|
|
80
98
|
|
|
99
|
+
def int32_slot
|
|
100
|
+
scalar_slot('l')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def int64_slot
|
|
104
|
+
scalar_slot('q')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def uint64_slot
|
|
108
|
+
scalar_slot('Q')
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def double_slot
|
|
112
|
+
scalar_slot('d')
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def int32_value(slot)
|
|
116
|
+
slot[0, 4].unpack1('l')
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def int64_value(slot)
|
|
120
|
+
slot[0, 8].unpack1('q')
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def uint64_value(slot)
|
|
124
|
+
slot[0, 8].unpack1('Q')
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def double_value(slot)
|
|
128
|
+
slot[0, 8].unpack1('d')
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def copy_borrowed_bytes(pointer, length)
|
|
132
|
+
return ''.b if length.zero?
|
|
133
|
+
|
|
134
|
+
address = pointer.to_i
|
|
135
|
+
raise Rustwright::Error, "Rustwright returned NULL bytes with length #{length}" if address.zero?
|
|
136
|
+
|
|
137
|
+
Fiddle::Pointer.new(address).to_str(length).dup.force_encoding(Encoding::BINARY)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def scalar_slot(format)
|
|
141
|
+
bytes = [0].pack(format).bytesize
|
|
142
|
+
slot = Fiddle::Pointer.malloc(bytes)
|
|
143
|
+
slot[0, bytes] = [0].pack(format)
|
|
144
|
+
slot
|
|
145
|
+
end
|
|
146
|
+
|
|
81
147
|
def pointer_address(slot)
|
|
82
148
|
slot[0, Fiddle::SIZEOF_VOIDP].unpack('J').first
|
|
83
149
|
end
|
data/lib/rustwright/wire.rb
CHANGED
|
@@ -17,75 +17,175 @@ module Rustwright
|
|
|
17
17
|
module Wire
|
|
18
18
|
module_function
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
NODE_NULL = 0
|
|
21
|
+
NODE_BOOL = 1
|
|
22
|
+
NODE_SIGNED = 2
|
|
23
|
+
NODE_UNSIGNED = 3
|
|
24
|
+
NODE_FLOAT = 4
|
|
25
|
+
NODE_STRING = 5
|
|
26
|
+
NODE_ARRAY = 6
|
|
27
|
+
NODE_OBJECT = 7
|
|
28
|
+
NODE_LEAF = 8
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
LEAF_UNSERIALIZABLE = 0
|
|
31
|
+
LEAF_BIGINT = 1
|
|
32
|
+
LEAF_DATE = 2
|
|
33
|
+
LEAF_REGEXP = 3
|
|
34
|
+
LEAF_URL = 4
|
|
35
|
+
LEAF_ERROR = 5
|
|
36
|
+
LEAF_UNDEFINED = 6
|
|
37
|
+
LEAF_SYMBOL = 7
|
|
38
|
+
LEAF_FUNCTION = 8
|
|
25
39
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
value.map { |item| decode_value(item, references) }
|
|
30
|
-
when Hash
|
|
31
|
-
decode_hash(value, references)
|
|
32
|
-
else
|
|
33
|
-
value
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
private_class_method :decode_value
|
|
37
|
-
|
|
38
|
-
def decode_hash(value, references)
|
|
39
|
-
if value.key?('__rustwright_cdp_array__')
|
|
40
|
-
target = []
|
|
41
|
-
references[value['__rustwright_cdp_array__']] = target
|
|
42
|
-
target.concat(Array(value['items']).map { |item| decode_value(item, references) })
|
|
43
|
-
return target
|
|
40
|
+
def decode(native, wire_json)
|
|
41
|
+
unless wire_json.is_a?(String)
|
|
42
|
+
raise ArgumentError, 'wire JSON must be a String'
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
return target
|
|
53
|
-
end
|
|
45
|
+
graph_slot = native.pointer_slot
|
|
46
|
+
status = native.call(:rw_wire_graph_parse, wire_json, graph_slot)
|
|
47
|
+
native.check_status!(status, 'rw_wire_graph_parse')
|
|
48
|
+
graph = native.pointer_address(graph_slot)
|
|
49
|
+
raise Rustwright::Error, 'rw_wire_graph_parse succeeded without returning a graph' if graph.zero?
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
begin
|
|
52
|
+
materialize(native, graph)
|
|
53
|
+
ensure
|
|
54
|
+
native.call(:rw_wire_graph_free, graph)
|
|
57
55
|
end
|
|
56
|
+
end
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
def materialize(native, graph)
|
|
59
|
+
count = read_size(native, :rw_wire_graph_node_count, [graph], 'rw_wire_graph_node_count')
|
|
60
|
+
values = Array.new(count)
|
|
61
|
+
kinds = Array.new(count)
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
count.times do |node|
|
|
64
|
+
kind = read_int32(
|
|
65
|
+
native,
|
|
66
|
+
:rw_wire_graph_node_kind,
|
|
67
|
+
[graph, node],
|
|
68
|
+
'rw_wire_graph_node_kind'
|
|
69
|
+
)
|
|
70
|
+
kinds[node] = kind
|
|
71
|
+
values[node] = allocate_node(native, graph, node, kind)
|
|
65
72
|
end
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
count.times do |node|
|
|
75
|
+
case kinds[node]
|
|
76
|
+
when NODE_ARRAY
|
|
77
|
+
length = read_size(
|
|
78
|
+
native,
|
|
79
|
+
:rw_wire_graph_array_length,
|
|
80
|
+
[graph, node],
|
|
81
|
+
'rw_wire_graph_array_length'
|
|
82
|
+
)
|
|
83
|
+
length.times do |index|
|
|
84
|
+
child = read_size(
|
|
85
|
+
native,
|
|
86
|
+
:rw_wire_graph_array_child,
|
|
87
|
+
[graph, node, index],
|
|
88
|
+
'rw_wire_graph_array_child'
|
|
89
|
+
)
|
|
90
|
+
values[node] << values.fetch(child)
|
|
91
|
+
end
|
|
92
|
+
when NODE_OBJECT
|
|
93
|
+
length = read_size(
|
|
94
|
+
native,
|
|
95
|
+
:rw_wire_graph_object_length,
|
|
96
|
+
[graph, node],
|
|
97
|
+
'rw_wire_graph_object_length'
|
|
98
|
+
)
|
|
99
|
+
length.times do |index|
|
|
100
|
+
key = read_text(
|
|
101
|
+
native,
|
|
102
|
+
:rw_wire_graph_object_key,
|
|
103
|
+
[graph, node, index],
|
|
104
|
+
'rw_wire_graph_object_key'
|
|
105
|
+
)
|
|
106
|
+
child = read_size(
|
|
107
|
+
native,
|
|
108
|
+
:rw_wire_graph_object_child,
|
|
109
|
+
[graph, node, index],
|
|
110
|
+
'rw_wire_graph_object_child'
|
|
111
|
+
)
|
|
112
|
+
values[node][key] = values.fetch(child)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
69
115
|
end
|
|
70
116
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
117
|
+
root = read_size(native, :rw_wire_graph_root, [graph], 'rw_wire_graph_root')
|
|
118
|
+
values.fetch(root)
|
|
119
|
+
end
|
|
120
|
+
private_class_method :materialize
|
|
75
121
|
|
|
76
|
-
|
|
77
|
-
|
|
122
|
+
def allocate_node(native, graph, node, kind)
|
|
123
|
+
case kind
|
|
124
|
+
when NODE_NULL
|
|
125
|
+
nil
|
|
126
|
+
when NODE_BOOL
|
|
127
|
+
read_int32(native, :rw_wire_graph_get_bool, [graph, node], 'rw_wire_graph_get_bool') != 0
|
|
128
|
+
when NODE_SIGNED
|
|
129
|
+
read_int64(native, :rw_wire_graph_get_signed, [graph, node], 'rw_wire_graph_get_signed')
|
|
130
|
+
when NODE_UNSIGNED
|
|
131
|
+
read_uint64(native, :rw_wire_graph_get_unsigned, [graph, node], 'rw_wire_graph_get_unsigned')
|
|
132
|
+
when NODE_FLOAT
|
|
133
|
+
read_double(native, :rw_wire_graph_get_float, [graph, node], 'rw_wire_graph_get_float')
|
|
134
|
+
when NODE_STRING
|
|
135
|
+
read_text(native, :rw_wire_graph_get_string, [graph, node], 'rw_wire_graph_get_string')
|
|
136
|
+
when NODE_ARRAY
|
|
137
|
+
[]
|
|
138
|
+
when NODE_OBJECT
|
|
139
|
+
{}
|
|
140
|
+
when NODE_LEAF
|
|
141
|
+
decode_leaf(native, graph, node)
|
|
142
|
+
else
|
|
143
|
+
raise Rustwright::Error, "unknown wire node kind #{kind}"
|
|
78
144
|
end
|
|
145
|
+
end
|
|
146
|
+
private_class_method :allocate_node
|
|
79
147
|
|
|
80
|
-
|
|
81
|
-
|
|
148
|
+
def decode_leaf(native, graph, node)
|
|
149
|
+
kind = read_int32(native, :rw_wire_graph_leaf_kind, [graph, node], 'rw_wire_graph_leaf_kind')
|
|
150
|
+
fields_count = read_size(
|
|
151
|
+
native,
|
|
152
|
+
:rw_wire_graph_leaf_field_count,
|
|
153
|
+
[graph, node],
|
|
154
|
+
'rw_wire_graph_leaf_field_count'
|
|
155
|
+
)
|
|
156
|
+
fields = fields_count.times.map do |index|
|
|
157
|
+
read_text(
|
|
158
|
+
native,
|
|
159
|
+
:rw_wire_graph_leaf_field,
|
|
160
|
+
[graph, node, index],
|
|
161
|
+
'rw_wire_graph_leaf_field'
|
|
162
|
+
)
|
|
82
163
|
end
|
|
83
164
|
|
|
84
|
-
|
|
85
|
-
|
|
165
|
+
case kind
|
|
166
|
+
when LEAF_UNSERIALIZABLE
|
|
167
|
+
decode_unserializable(fields.fetch(0))
|
|
168
|
+
when LEAF_BIGINT
|
|
169
|
+
decode_bigint(fields.fetch(0))
|
|
170
|
+
when LEAF_DATE
|
|
171
|
+
Time.iso8601(fields.fetch(0))
|
|
172
|
+
when LEAF_REGEXP
|
|
173
|
+
Regexp.new(fields.fetch(0), regexp_options(fields.fetch(1)))
|
|
174
|
+
when LEAF_URL
|
|
175
|
+
URI.parse(fields.fetch(0))
|
|
176
|
+
when LEAF_ERROR
|
|
177
|
+
JavaScriptError.new(
|
|
178
|
+
'name' => fields.fetch(0),
|
|
179
|
+
'message' => fields.fetch(1),
|
|
180
|
+
'stack' => fields.fetch(2)
|
|
181
|
+
)
|
|
182
|
+
when LEAF_UNDEFINED, LEAF_SYMBOL, LEAF_FUNCTION
|
|
183
|
+
nil
|
|
184
|
+
else
|
|
185
|
+
raise Rustwright::Error, "unknown wire leaf kind #{kind}"
|
|
86
186
|
end
|
|
87
187
|
end
|
|
88
|
-
private_class_method :
|
|
188
|
+
private_class_method :decode_leaf
|
|
89
189
|
|
|
90
190
|
def decode_unserializable(value)
|
|
91
191
|
case value
|
|
@@ -94,11 +194,18 @@ module Rustwright
|
|
|
94
194
|
when '-Infinity' then -Float::INFINITY
|
|
95
195
|
when '-0' then -0.0
|
|
96
196
|
else
|
|
97
|
-
value
|
|
197
|
+
value
|
|
98
198
|
end
|
|
99
199
|
end
|
|
100
200
|
private_class_method :decode_unserializable
|
|
101
201
|
|
|
202
|
+
def decode_bigint(value)
|
|
203
|
+
Integer(value, 10)
|
|
204
|
+
rescue ArgumentError
|
|
205
|
+
value
|
|
206
|
+
end
|
|
207
|
+
private_class_method :decode_bigint
|
|
208
|
+
|
|
102
209
|
def regexp_options(flags)
|
|
103
210
|
options = 0
|
|
104
211
|
options |= Regexp::IGNORECASE if flags.include?('i')
|
|
@@ -107,5 +214,57 @@ module Rustwright
|
|
|
107
214
|
options
|
|
108
215
|
end
|
|
109
216
|
private_class_method :regexp_options
|
|
217
|
+
|
|
218
|
+
def read_size(native, name, arguments, operation)
|
|
219
|
+
slot = native.size_slot
|
|
220
|
+
status = native.call(name, *arguments, slot)
|
|
221
|
+
native.check_status!(status, operation)
|
|
222
|
+
native.size_value(slot)
|
|
223
|
+
end
|
|
224
|
+
private_class_method :read_size
|
|
225
|
+
|
|
226
|
+
def read_int32(native, name, arguments, operation)
|
|
227
|
+
slot = native.int32_slot
|
|
228
|
+
status = native.call(name, *arguments, slot)
|
|
229
|
+
native.check_status!(status, operation)
|
|
230
|
+
native.int32_value(slot)
|
|
231
|
+
end
|
|
232
|
+
private_class_method :read_int32
|
|
233
|
+
|
|
234
|
+
def read_int64(native, name, arguments, operation)
|
|
235
|
+
slot = native.int64_slot
|
|
236
|
+
status = native.call(name, *arguments, slot)
|
|
237
|
+
native.check_status!(status, operation)
|
|
238
|
+
native.int64_value(slot)
|
|
239
|
+
end
|
|
240
|
+
private_class_method :read_int64
|
|
241
|
+
|
|
242
|
+
def read_uint64(native, name, arguments, operation)
|
|
243
|
+
slot = native.uint64_slot
|
|
244
|
+
status = native.call(name, *arguments, slot)
|
|
245
|
+
native.check_status!(status, operation)
|
|
246
|
+
native.uint64_value(slot)
|
|
247
|
+
end
|
|
248
|
+
private_class_method :read_uint64
|
|
249
|
+
|
|
250
|
+
def read_double(native, name, arguments, operation)
|
|
251
|
+
slot = native.double_slot
|
|
252
|
+
status = native.call(name, *arguments, slot)
|
|
253
|
+
native.check_status!(status, operation)
|
|
254
|
+
native.double_value(slot)
|
|
255
|
+
end
|
|
256
|
+
private_class_method :read_double
|
|
257
|
+
|
|
258
|
+
def read_text(native, name, arguments, operation)
|
|
259
|
+
pointer_slot = native.pointer_slot
|
|
260
|
+
length_slot = native.size_slot
|
|
261
|
+
status = native.call(name, *arguments, pointer_slot, length_slot)
|
|
262
|
+
native.check_status!(status, operation)
|
|
263
|
+
native.copy_borrowed_bytes(
|
|
264
|
+
native.pointer_address(pointer_slot),
|
|
265
|
+
native.size_value(length_slot)
|
|
266
|
+
).force_encoding(Encoding::UTF_8)
|
|
267
|
+
end
|
|
268
|
+
private_class_method :read_text
|
|
110
269
|
end
|
|
111
270
|
end
|
data/lib/rustwright.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'monitor'
|
|
|
5
5
|
require 'rbconfig'
|
|
6
6
|
|
|
7
7
|
module Rustwright
|
|
8
|
-
VERSION = '0.
|
|
8
|
+
VERSION = '0.3.1'
|
|
9
9
|
UNSET = Object.new.freeze
|
|
10
10
|
|
|
11
11
|
class Error < StandardError; end
|
|
@@ -386,8 +386,8 @@ module Rustwright
|
|
|
386
386
|
out
|
|
387
387
|
)
|
|
388
388
|
@native.check_status!(status, 'rw_page_evaluate')
|
|
389
|
-
|
|
390
|
-
Wire.decode(
|
|
389
|
+
wire_json = @native.copy_owned_string(@native.pointer_address(out))
|
|
390
|
+
Wire.decode(@native, wire_json)
|
|
391
391
|
end
|
|
392
392
|
end
|
|
393
393
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rustwright
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: arm64-darwin
|
|
6
6
|
authors:
|
|
7
7
|
- Rustwright contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|