opal 1.6.1 → 1.7.0
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/.github/workflows/build.yml +17 -0
- data/CHANGELOG.md +35 -1
- data/Gemfile +1 -0
- data/HACKING.md +47 -26
- data/benchmark/benchmarks +415 -103
- data/benchmark/bm_call_overhead.yml +28 -0
- data/benchmark/run.rb +61 -40
- data/docs/cdp_common.json +3364 -0
- data/docs/cdp_common.md +18 -0
- data/docs/{headless_chrome.md → headless_browsers.md} +31 -12
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +6 -1
- data/lib/opal/builder_processors.rb +5 -3
- data/lib/opal/cache.rb +1 -7
- data/lib/opal/cli_options.rb +72 -58
- data/lib/opal/cli_runners/chrome.rb +47 -9
- data/lib/opal/cli_runners/chrome_cdp_interface.rb +238 -112
- data/lib/opal/cli_runners/compiler.rb +146 -13
- data/lib/opal/cli_runners/deno.rb +32 -0
- data/lib/opal/cli_runners/firefox.rb +350 -0
- data/lib/opal/cli_runners/firefox_cdp_interface.rb +212 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.cmd +17 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.ps1 +28 -0
- data/lib/opal/cli_runners/node_modules/.package-lock.json +41 -0
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/LICENSE +1 -1
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/README.md +322 -182
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/bin/client.js +99 -114
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/chrome-remote-interface.js +1 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/index.js +16 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/api.js +41 -33
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/chrome.js +224 -214
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/devtools.js +71 -191
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js +26 -6
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/protocol.json +20788 -9049
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +10 -3
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/package.json +59 -123
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/webpack.config.js +25 -32
- data/lib/opal/cli_runners/node_modules/commander/History.md +298 -0
- data/lib/opal/cli_runners/node_modules/commander/LICENSE +22 -0
- data/lib/opal/cli_runners/node_modules/commander/Readme.md +217 -61
- data/lib/opal/cli_runners/node_modules/commander/index.js +431 -145
- data/lib/opal/cli_runners/node_modules/commander/package.json +16 -79
- data/lib/opal/cli_runners/node_modules/ws/README.md +334 -98
- data/lib/opal/cli_runners/node_modules/ws/browser.js +8 -0
- data/lib/opal/cli_runners/node_modules/ws/index.js +5 -10
- data/lib/opal/cli_runners/node_modules/ws/lib/buffer-util.js +129 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/constants.js +10 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/event-target.js +184 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/extension.js +223 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/limiter.js +55 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/permessage-deflate.js +518 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/receiver.js +607 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/sender.js +409 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/stream.js +180 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/validation.js +104 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket-server.js +447 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket.js +1195 -0
- data/lib/opal/cli_runners/node_modules/ws/package.json +40 -106
- data/lib/opal/cli_runners/package-lock.json +62 -0
- data/lib/opal/cli_runners/package.json +1 -1
- data/lib/opal/cli_runners.rb +26 -4
- data/lib/opal/nodes/args/prepare_post_args.rb +2 -2
- data/lib/opal/nodes/def.rb +8 -8
- data/lib/opal/nodes/iter.rb +12 -12
- data/lib/opal/nodes/logic.rb +1 -1
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/paths.rb +14 -0
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/forward_args.rb +52 -4
- data/lib/opal/rewriters/targeted_patches.rb +94 -0
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/basic_object.rb +1 -1
- data/opal/corelib/boolean.rb +2 -2
- data/opal/corelib/class.rb +11 -0
- data/opal/corelib/constants.rb +3 -3
- data/opal/corelib/enumerable.rb +4 -0
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/hash.rb +2 -2
- data/opal/corelib/helpers.rb +1 -1
- data/opal/corelib/kernel.rb +3 -3
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +29 -8
- data/opal/corelib/proc.rb +7 -5
- data/opal/corelib/runtime.js +141 -78
- data/opal/corelib/set.rb +252 -0
- data/opal/corelib/string.rb +2 -1
- data/opal/corelib/time.rb +2 -2
- data/opal/opal.rb +1 -0
- data/opal.gemspec +1 -0
- data/spec/filters/bugs/array.rb +22 -13
- data/spec/filters/bugs/base64.rb +5 -5
- data/spec/filters/bugs/basicobject.rb +16 -8
- data/spec/filters/bugs/bigdecimal.rb +161 -160
- data/spec/filters/bugs/binding.rb +10 -10
- data/spec/filters/bugs/class.rb +8 -8
- data/spec/filters/bugs/complex.rb +2 -1
- data/spec/filters/bugs/date.rb +79 -81
- data/spec/filters/bugs/datetime.rb +29 -29
- data/spec/filters/bugs/delegate.rb +1 -3
- data/spec/filters/bugs/encoding.rb +69 -69
- data/spec/filters/bugs/enumerable.rb +22 -20
- data/spec/filters/bugs/enumerator.rb +88 -85
- data/spec/filters/bugs/exception.rb +46 -40
- data/spec/filters/bugs/file.rb +32 -32
- data/spec/filters/bugs/float.rb +26 -21
- data/spec/filters/bugs/freeze.rb +88 -0
- data/spec/filters/bugs/hash.rb +39 -38
- data/spec/filters/bugs/integer.rb +57 -44
- data/spec/filters/bugs/io.rb +1 -1
- data/spec/filters/bugs/kernel.rb +349 -269
- data/spec/filters/bugs/language.rb +220 -188
- data/spec/filters/bugs/main.rb +5 -3
- data/spec/filters/bugs/marshal.rb +38 -38
- data/spec/filters/bugs/math.rb +2 -1
- data/spec/filters/bugs/method.rb +73 -62
- data/spec/filters/bugs/module.rb +163 -143
- data/spec/filters/bugs/numeric.rb +6 -6
- data/spec/filters/bugs/objectspace.rb +16 -16
- data/spec/filters/bugs/openstruct.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +51 -51
- data/spec/filters/bugs/pathname.rb +7 -7
- data/spec/filters/bugs/proc.rb +63 -63
- data/spec/filters/bugs/random.rb +7 -6
- data/spec/filters/bugs/range.rb +12 -9
- data/spec/filters/bugs/rational.rb +8 -7
- data/spec/filters/bugs/regexp.rb +49 -48
- data/spec/filters/bugs/ruby-32.rb +56 -0
- data/spec/filters/bugs/set.rb +30 -30
- data/spec/filters/bugs/singleton.rb +4 -4
- data/spec/filters/bugs/string.rb +187 -99
- data/spec/filters/bugs/stringio.rb +7 -0
- data/spec/filters/bugs/stringscanner.rb +68 -68
- data/spec/filters/bugs/struct.rb +11 -9
- data/spec/filters/bugs/symbol.rb +1 -1
- data/spec/filters/bugs/time.rb +78 -63
- data/spec/filters/bugs/trace_point.rb +4 -4
- data/spec/filters/bugs/unboundmethod.rb +32 -17
- data/spec/filters/bugs/warnings.rb +8 -12
- data/spec/filters/unsupported/array.rb +24 -107
- data/spec/filters/unsupported/basicobject.rb +12 -12
- data/spec/filters/unsupported/bignum.rb +27 -52
- data/spec/filters/unsupported/class.rb +1 -2
- data/spec/filters/unsupported/delegator.rb +3 -3
- data/spec/filters/unsupported/enumerable.rb +2 -9
- data/spec/filters/unsupported/enumerator.rb +2 -11
- data/spec/filters/unsupported/file.rb +1 -1
- data/spec/filters/unsupported/float.rb +28 -47
- data/spec/filters/unsupported/hash.rb +8 -14
- data/spec/filters/unsupported/integer.rb +75 -91
- data/spec/filters/unsupported/kernel.rb +17 -35
- data/spec/filters/unsupported/language.rb +11 -19
- data/spec/filters/unsupported/marshal.rb +22 -41
- data/spec/filters/unsupported/matchdata.rb +28 -52
- data/spec/filters/unsupported/math.rb +1 -1
- data/spec/filters/unsupported/privacy.rb +229 -285
- data/spec/filters/unsupported/range.rb +1 -5
- data/spec/filters/unsupported/regexp.rb +40 -66
- data/spec/filters/unsupported/set.rb +2 -2
- data/spec/filters/unsupported/singleton.rb +4 -4
- data/spec/filters/unsupported/string.rb +305 -508
- data/spec/filters/unsupported/struct.rb +3 -4
- data/spec/filters/unsupported/symbol.rb +15 -18
- data/spec/filters/unsupported/thread.rb +1 -7
- data/spec/filters/unsupported/time.rb +159 -202
- data/spec/filters/unsupported/usage_of_files.rb +170 -259
- data/spec/lib/builder_spec.rb +4 -4
- data/spec/lib/rewriters/forward_args_spec.rb +32 -12
- data/spec/mspec-opal/runner.rb +2 -0
- data/spec/ruby_specs +4 -0
- data/stdlib/deno/base.rb +28 -0
- data/stdlib/deno/file.rb +340 -0
- data/stdlib/{headless_chrome.rb → headless_browser/base.rb} +1 -1
- data/stdlib/headless_browser/file.rb +15 -0
- data/stdlib/headless_browser.rb +4 -0
- data/stdlib/native.rb +1 -1
- data/stdlib/nodejs/file.rb +5 -0
- data/stdlib/opal/platform.rb +8 -6
- data/stdlib/opal-platform.rb +14 -8
- data/stdlib/set.rb +1 -258
- data/tasks/benchmarking.rake +62 -19
- data/tasks/performance.rake +1 -1
- data/tasks/testing.rake +5 -3
- data/test/nodejs/test_file.rb +29 -10
- data/test/opal/http_server.rb +28 -11
- data/test/opal/unsupported_and_bugs.rb +2 -1
- metadata +89 -50
- data/lib/opal/cli_runners/node_modules/ultron/LICENSE +0 -22
- data/lib/opal/cli_runners/node_modules/ultron/index.js +0 -138
- data/lib/opal/cli_runners/node_modules/ultron/package.json +0 -112
- data/lib/opal/cli_runners/node_modules/ws/SECURITY.md +0 -33
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.fallback.js +0 -56
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.js +0 -15
- data/lib/opal/cli_runners/node_modules/ws/lib/ErrorCodes.js +0 -28
- data/lib/opal/cli_runners/node_modules/ws/lib/EventTarget.js +0 -158
- data/lib/opal/cli_runners/node_modules/ws/lib/Extensions.js +0 -69
- data/lib/opal/cli_runners/node_modules/ws/lib/PerMessageDeflate.js +0 -339
- data/lib/opal/cli_runners/node_modules/ws/lib/Receiver.js +0 -520
- data/lib/opal/cli_runners/node_modules/ws/lib/Sender.js +0 -438
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.fallback.js +0 -9
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.js +0 -17
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocket.js +0 -705
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocketServer.js +0 -336
- data/spec/filters/bugs/boolean.rb +0 -3
- data/spec/filters/bugs/matrix.rb +0 -3
- data/spec/filters/unsupported/fixnum.rb +0 -15
- data/spec/filters/unsupported/freeze.rb +0 -102
- data/spec/filters/unsupported/pathname.rb +0 -4
- data/spec/filters/unsupported/proc.rb +0 -4
- data/spec/filters/unsupported/random.rb +0 -5
- data/spec/filters/unsupported/taint.rb +0 -162
data/stdlib/set.rb
CHANGED
@@ -1,258 +1 @@
|
|
1
|
-
#
|
2
|
-
# Portions Copyright (c) 2002-2013 Akinori MUSHA <knu@iDaemons.org>
|
3
|
-
class ::Set
|
4
|
-
include ::Enumerable
|
5
|
-
|
6
|
-
def self.[](*ary)
|
7
|
-
new(ary)
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(enum = nil, &block)
|
11
|
-
@hash = {}
|
12
|
-
|
13
|
-
return if enum.nil?
|
14
|
-
::Kernel.raise ::ArgumentError, 'value must be enumerable' unless ::Enumerable === enum
|
15
|
-
|
16
|
-
if block
|
17
|
-
enum.each { |item| add yield(item) }
|
18
|
-
else
|
19
|
-
merge(enum)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def dup
|
24
|
-
result = self.class.new
|
25
|
-
result.merge(self)
|
26
|
-
end
|
27
|
-
|
28
|
-
def -(enum)
|
29
|
-
unless enum.respond_to? :each
|
30
|
-
::Kernel.raise ::ArgumentError, 'value must be enumerable'
|
31
|
-
end
|
32
|
-
|
33
|
-
dup.subtract(enum)
|
34
|
-
end
|
35
|
-
|
36
|
-
def inspect
|
37
|
-
"#<Set: {#{to_a.join(',')}}>"
|
38
|
-
end
|
39
|
-
|
40
|
-
def ==(other)
|
41
|
-
if equal?(other)
|
42
|
-
true
|
43
|
-
elsif other.instance_of?(self.class)
|
44
|
-
@hash == other.instance_variable_get(:@hash)
|
45
|
-
elsif other.is_a?(::Set) && size == other.size
|
46
|
-
other.all? { |o| @hash.include?(o) }
|
47
|
-
else
|
48
|
-
false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def add(o)
|
53
|
-
@hash[o] = true
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
def classify(&block)
|
58
|
-
return enum_for(:classify) unless block_given?
|
59
|
-
|
60
|
-
result = ::Hash.new { |h, k| h[k] = self.class.new }
|
61
|
-
|
62
|
-
each { |item| result[yield(item)].add item }
|
63
|
-
|
64
|
-
result
|
65
|
-
end
|
66
|
-
|
67
|
-
def collect!(&block)
|
68
|
-
return enum_for(:collect!) unless block_given?
|
69
|
-
result = self.class.new
|
70
|
-
each { |item| result << yield(item) }
|
71
|
-
replace result
|
72
|
-
end
|
73
|
-
|
74
|
-
def compare_by_identity
|
75
|
-
if @hash.respond_to?(:compare_by_identity)
|
76
|
-
@hash.compare_by_identity
|
77
|
-
self
|
78
|
-
else
|
79
|
-
raise NotImplementedError, "#{self.class.name}\##{__method__} is not implemented"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def compare_by_identity?
|
84
|
-
@hash.respond_to?(:compare_by_identity?) && @hash.compare_by_identity?
|
85
|
-
end
|
86
|
-
|
87
|
-
def delete(o)
|
88
|
-
@hash.delete(o)
|
89
|
-
self
|
90
|
-
end
|
91
|
-
|
92
|
-
def delete?(o)
|
93
|
-
if include?(o)
|
94
|
-
delete(o)
|
95
|
-
self
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def delete_if
|
100
|
-
return enum_for(:delete_if) unless block_given?
|
101
|
-
# @hash.delete_if should be faster, but using it breaks the order
|
102
|
-
# of enumeration in subclasses.
|
103
|
-
select { |o| yield o }.each { |o| @hash.delete(o) }
|
104
|
-
self
|
105
|
-
end
|
106
|
-
|
107
|
-
def freeze
|
108
|
-
return self if frozen?
|
109
|
-
|
110
|
-
@hash.freeze
|
111
|
-
`$freeze(self)`
|
112
|
-
end
|
113
|
-
|
114
|
-
def keep_if
|
115
|
-
return enum_for(:keep_if) unless block_given?
|
116
|
-
reject { |o| yield o }.each { |o| @hash.delete(o) }
|
117
|
-
self
|
118
|
-
end
|
119
|
-
|
120
|
-
def reject!(&block)
|
121
|
-
return enum_for(:reject!) unless block_given?
|
122
|
-
before = size
|
123
|
-
delete_if(&block)
|
124
|
-
size == before ? nil : self
|
125
|
-
end
|
126
|
-
|
127
|
-
def select!(&block)
|
128
|
-
return enum_for(:select!) unless block_given?
|
129
|
-
before = size
|
130
|
-
keep_if(&block)
|
131
|
-
size == before ? nil : self
|
132
|
-
end
|
133
|
-
|
134
|
-
def add?(o)
|
135
|
-
if include?(o)
|
136
|
-
nil
|
137
|
-
else
|
138
|
-
add(o)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def each(&block)
|
143
|
-
return enum_for(:each) unless block_given?
|
144
|
-
@hash.each_key(&block)
|
145
|
-
self
|
146
|
-
end
|
147
|
-
|
148
|
-
def empty?
|
149
|
-
@hash.empty?
|
150
|
-
end
|
151
|
-
|
152
|
-
def eql?(other)
|
153
|
-
@hash.eql?(other.instance_eval { @hash })
|
154
|
-
end
|
155
|
-
|
156
|
-
def clear
|
157
|
-
@hash.clear
|
158
|
-
self
|
159
|
-
end
|
160
|
-
|
161
|
-
def include?(o)
|
162
|
-
@hash.include?(o)
|
163
|
-
end
|
164
|
-
|
165
|
-
def merge(enum)
|
166
|
-
enum.each { |item| add item }
|
167
|
-
self
|
168
|
-
end
|
169
|
-
|
170
|
-
def replace(enum)
|
171
|
-
clear
|
172
|
-
merge(enum)
|
173
|
-
|
174
|
-
self
|
175
|
-
end
|
176
|
-
|
177
|
-
def size
|
178
|
-
@hash.size
|
179
|
-
end
|
180
|
-
|
181
|
-
def subtract(enum)
|
182
|
-
enum.each { |item| delete item }
|
183
|
-
self
|
184
|
-
end
|
185
|
-
|
186
|
-
def |(enum)
|
187
|
-
unless enum.respond_to? :each
|
188
|
-
::Kernel.raise ::ArgumentError, 'value must be enumerable'
|
189
|
-
end
|
190
|
-
dup.merge(enum)
|
191
|
-
end
|
192
|
-
|
193
|
-
%x{
|
194
|
-
function is_set(set) {
|
195
|
-
#{`set`.is_a?(::Set) || ::Kernel.raise(::ArgumentError, 'value must be a set')}
|
196
|
-
}
|
197
|
-
}
|
198
|
-
|
199
|
-
def superset?(set)
|
200
|
-
`is_set(set)`
|
201
|
-
return false if size < set.size
|
202
|
-
set.all? { |o| include?(o) }
|
203
|
-
end
|
204
|
-
|
205
|
-
def proper_superset?(set)
|
206
|
-
`is_set(set)`
|
207
|
-
return false if size <= set.size
|
208
|
-
set.all? { |o| include?(o) }
|
209
|
-
end
|
210
|
-
|
211
|
-
def subset?(set)
|
212
|
-
`is_set(set)`
|
213
|
-
return false if set.size < size
|
214
|
-
all? { |o| set.include?(o) }
|
215
|
-
end
|
216
|
-
|
217
|
-
def proper_subset?(set)
|
218
|
-
`is_set(set)`
|
219
|
-
return false if set.size <= size
|
220
|
-
all? { |o| set.include?(o) }
|
221
|
-
end
|
222
|
-
|
223
|
-
def intersect?(set)
|
224
|
-
`is_set(set)`
|
225
|
-
if size < set.size
|
226
|
-
any? { |o| set.include?(o) }
|
227
|
-
else
|
228
|
-
set.any? { |o| include?(o) }
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def disjoint?(set)
|
233
|
-
!intersect?(set)
|
234
|
-
end
|
235
|
-
|
236
|
-
def to_a
|
237
|
-
@hash.keys
|
238
|
-
end
|
239
|
-
|
240
|
-
alias + |
|
241
|
-
alias < proper_subset?
|
242
|
-
alias << add
|
243
|
-
alias <= subset?
|
244
|
-
alias > proper_superset?
|
245
|
-
alias >= superset?
|
246
|
-
alias difference -
|
247
|
-
alias filter! select!
|
248
|
-
alias length size
|
249
|
-
alias map! collect!
|
250
|
-
alias member? include?
|
251
|
-
alias union |
|
252
|
-
end
|
253
|
-
|
254
|
-
module ::Enumerable
|
255
|
-
def to_set(klass = Set, *args, &block)
|
256
|
-
klass.new(self, *args, &block)
|
257
|
-
end
|
258
|
-
end
|
1
|
+
# Set has been moved to corelib
|
data/tasks/benchmarking.rake
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative '../lib/opal/version'
|
2
|
+
require_relative '../lib/opal/cli_runners'
|
3
|
+
|
1
4
|
namespace :bench do
|
2
5
|
directory "tmp/bench"
|
3
6
|
|
@@ -6,19 +9,37 @@ namespace :bench do
|
|
6
9
|
"tmp/bench/#{index}_#{name.gsub('.', '-')}.txt"
|
7
10
|
}
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
runners = Opal::CliRunners.registered_runners.sort.reject { |r| r == 'Compiler' }
|
13
|
+
runners.each do |runner|
|
14
|
+
desc "Benchmark Opal with #{runner}"
|
15
|
+
runner_dc = runner.downcase
|
16
|
+
task_name = "opal_#{runner_dc}".to_sym
|
17
|
+
task task_name => "tmp/bench" do |t, args|
|
18
|
+
files = Array(args[:files]) + args.extras
|
19
|
+
report = report_file_for["opal-#{runner_dc}-#{Opal::VERSION}"]
|
20
|
+
sh "bundle exec ruby benchmark/run.rb --#{runner_dc} #{files.join(" ")} | tee #{report}"
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
24
|
desc "Benchmark Ruby"
|
18
25
|
task :ruby => "tmp/bench" do |t, args|
|
19
26
|
files = Array(args[:files]) + args.extras
|
20
27
|
report = report_file_for["ruby-#{RUBY_VERSION}"]
|
21
|
-
sh "bundle exec ruby benchmark/run.rb #{files.join(" ")} | tee #{report}"
|
28
|
+
sh "bundle exec ruby benchmark/run.rb --ruby #{files.join(" ")} | tee #{report}"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Benchmark Ruby vs Opal Node"
|
32
|
+
task :ruby_vs_opal => "tmp/bench" do |t, args|
|
33
|
+
files = Array(args[:files]) + args.extras
|
34
|
+
report = report_file_for["ruby-#{RUBY_VERSION}-vs-opal-node-#{Opal::VERSION}"]
|
35
|
+
sh "bundle exec ruby benchmark/run.rb --ruby --node #{files.join(" ")} | tee #{report}"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Benchmark All Engines"
|
39
|
+
task :all => "tmp/bench" do |t, args|
|
40
|
+
files = Array(args[:files]) + args.extras
|
41
|
+
report = report_file_for["ruby-#{RUBY_VERSION}-vs-opal-all-#{Opal::VERSION}"]
|
42
|
+
sh "bundle exec ruby benchmark/run.rb --ruby --node --chrome --firefox #{files.join(" ")} | tee #{report}"
|
22
43
|
end
|
23
44
|
|
24
45
|
desc "Delete all benchmark results"
|
@@ -26,6 +47,21 @@ namespace :bench do
|
|
26
47
|
sh "rm tmp/bench/*"
|
27
48
|
end
|
28
49
|
|
50
|
+
def results_to_f(results)
|
51
|
+
ips = results.compact
|
52
|
+
ips.each_with_index do |i, idx|
|
53
|
+
factor = case i[-1]
|
54
|
+
when 'G' then 1_000_000_000
|
55
|
+
when 'M' then 1_000_000
|
56
|
+
when 'k' then 1_000
|
57
|
+
else
|
58
|
+
1
|
59
|
+
end
|
60
|
+
ips[idx] = (factor > 1 ? i[0..-2].to_f : i.to_f) * factor
|
61
|
+
end
|
62
|
+
ips
|
63
|
+
end
|
64
|
+
|
29
65
|
desc "Combined report of all benchmark results"
|
30
66
|
task :report do |t, args|
|
31
67
|
files = Array(args[:files]) + args.extras
|
@@ -41,8 +77,13 @@ namespace :bench do
|
|
41
77
|
report_name = File.basename(file, File.extname(file))
|
42
78
|
report_results = {}
|
43
79
|
File.read(file).each_line do |line|
|
44
|
-
benchmark_name,
|
45
|
-
|
80
|
+
benchmark_name, benchmark_result_a, benchmark_result_b, benchmark_result_c = line.split(" ")
|
81
|
+
if benchmark_result_b == "i/s"
|
82
|
+
benchmark_result_b = benchmark_result_c = nil
|
83
|
+
elsif benchmark_result_c == "i/s"
|
84
|
+
benchmark_result_c = nil
|
85
|
+
end
|
86
|
+
report_results[benchmark_name] = [benchmark_result_a, benchmark_result_b, benchmark_result_c]
|
46
87
|
benchmark_names << benchmark_name
|
47
88
|
end
|
48
89
|
reports << [report_name, report_results]
|
@@ -66,17 +107,19 @@ namespace :bench do
|
|
66
107
|
results_string = ""
|
67
108
|
|
68
109
|
if report_results[benchmark_name]
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
110
|
+
ips = results_to_f(report_results[benchmark_name])
|
111
|
+
base_ips = report_name != base_report_name && base_report_results[benchmark_name] ? results_to_f(base_report_results[benchmark_name]) : []
|
112
|
+
|
113
|
+
ips.each_with_index do |i, idx|
|
114
|
+
if base_ips[idx]
|
115
|
+
delta_percent = -((1 - i/base_ips[idx])*100)
|
116
|
+
results_string << format("%+0.2f%%", delta_percent).rjust(10).ljust(12)
|
117
|
+
else
|
118
|
+
results_string << (" "*14)
|
119
|
+
end
|
120
|
+
|
121
|
+
results_string << format("%0.3f i/s", i).rjust(9)
|
77
122
|
end
|
78
|
-
|
79
|
-
results_string << format("%0.3fms", sec).rjust(9)
|
80
123
|
end
|
81
124
|
results_string << ' | '
|
82
125
|
row << results_string
|
data/tasks/performance.rake
CHANGED
data/tasks/testing.rake
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require_relative "#{__dir__}/../lib/opal/os"
|
2
|
+
require_relative "#{__dir__}/../lib/opal/cli_runners"
|
3
|
+
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
|
4
|
-
OS = Opal::OS
|
6
|
+
OS = Opal::OS unless defined? OS
|
5
7
|
|
6
8
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
7
9
|
t.pattern = 'spec/lib/**/*_spec.rb'
|
@@ -283,8 +285,8 @@ Use PATTERN environment variable to manually set the glob for specs:
|
|
283
285
|
bundle exec rake mspec_nodejs PATTERN=spec/ruby/core/module/class_variable*_spec.rb
|
284
286
|
bundle exec rake mspec_nodejs PATTERN=spec/ruby/core/numeric/**_spec.rb
|
285
287
|
DESC
|
286
|
-
|
287
|
-
platforms = %w[
|
288
|
+
runners = Opal::CliRunners.to_h.keys.map(&:to_s).reject { |r| r == 'compiler' }
|
289
|
+
platforms = (%w[opalopal_nodejs] + runners).sort
|
288
290
|
node_platforms = %w[nodejs opalopal_nodejs]
|
289
291
|
mspec_suites = %w[ruby opal]
|
290
292
|
minitest_suites = %w[cruby]
|
data/test/nodejs/test_file.rb
CHANGED
@@ -130,10 +130,25 @@ class TestNodejsFile < Test::Unit::TestCase
|
|
130
130
|
refute(File.directory?('test/nodejs/fixtures/hello.rb'), 'test/nodejs/fixtures/hello.rb should not be a directory')
|
131
131
|
end
|
132
132
|
|
133
|
+
# Let's not ship our repo with symlinks, but create them on the go
|
134
|
+
def with_symlinks(&block)
|
135
|
+
dir_symlink = 'test/nodejs/fixtures/symlink-to-directory'
|
136
|
+
file_symlink = 'test/nodejs/fixtures/symlink-to-file'
|
137
|
+
|
138
|
+
File.symlink('.', dir_symlink)
|
139
|
+
File.symlink('hello.rb', file_symlink)
|
140
|
+
block.call(dir_symlink, file_symlink)
|
141
|
+
ensure
|
142
|
+
File.unlink(dir_symlink)
|
143
|
+
File.unlink(file_symlink)
|
144
|
+
end
|
145
|
+
|
133
146
|
def test_directory_check_with_symlinks
|
134
|
-
|
135
|
-
|
136
|
-
|
147
|
+
with_symlinks do |dir_symlink, file_symlink|
|
148
|
+
assert(File.directory?(dir_symlink), dir_symlink+' should be a directory')
|
149
|
+
assert(File.directory?(dir_symlink+'/'), dir_symlink+'/ should be a directory')
|
150
|
+
refute(File.directory?(file_symlink), file_symlink+' should not be a directory')
|
151
|
+
end
|
137
152
|
end unless windows_platform?
|
138
153
|
|
139
154
|
def test_file_check
|
@@ -144,16 +159,20 @@ class TestNodejsFile < Test::Unit::TestCase
|
|
144
159
|
end
|
145
160
|
|
146
161
|
def test_file_check_with_symlinks
|
147
|
-
|
148
|
-
|
149
|
-
|
162
|
+
with_symlinks do |dir_symlink, file_symlink|
|
163
|
+
refute(File.file?(dir_symlink), dir_symlink+' should not be a file')
|
164
|
+
refute(File.file?(dir_symlink+'/'), dir_symlink+'/ should not be a file')
|
165
|
+
assert(File.file?(file_symlink), file_symlink+' should be a file')
|
166
|
+
end
|
150
167
|
end unless windows_platform?
|
151
168
|
|
152
169
|
def test_file_symlink?
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
170
|
+
with_symlinks do |dir_symlink, file_symlink|
|
171
|
+
assert(File.symlink?(file_symlink))
|
172
|
+
assert(File.symlink?(dir_symlink))
|
173
|
+
refute(File.symlink?('test/nodejs/fixtures'))
|
174
|
+
refute(File.symlink?('test/nodejs/fixtures/hello.rb'))
|
175
|
+
end
|
157
176
|
end unless windows_platform?
|
158
177
|
|
159
178
|
def test_file_readable
|
data/test/opal/http_server.rb
CHANGED
@@ -3,50 +3,67 @@ require 'sinatra'
|
|
3
3
|
cat_image = File.open(File.join(File.dirname(__FILE__), 'cat.png'), 'rb').read
|
4
4
|
|
5
5
|
get '/' do
|
6
|
+
headers \
|
7
|
+
'Access-Control-Allow-Origin' => '*'
|
6
8
|
'Ready!'
|
7
9
|
end
|
8
10
|
|
9
11
|
get '/plain_text' do
|
10
12
|
status 200
|
11
|
-
headers
|
12
|
-
'Content-Type' => 'text/plain'
|
13
|
+
headers(
|
14
|
+
'Content-Type' => 'text/plain',
|
15
|
+
'Access-Control-Allow-Origin' => '*' )
|
13
16
|
body 'plain text'
|
14
17
|
end
|
15
18
|
|
16
19
|
|
17
20
|
get '/no_header' do
|
18
21
|
status 200
|
19
|
-
headers
|
20
|
-
'Content-Type' => ''
|
22
|
+
headers(
|
23
|
+
'Content-Type' => '',
|
24
|
+
'Access-Control-Allow-Origin' => '*')
|
21
25
|
body 'no header'
|
22
26
|
end
|
23
27
|
|
24
28
|
get '/html' do
|
25
29
|
status 200
|
26
|
-
headers
|
27
|
-
'Content-Type' => 'text/html; charset=utf-8'
|
30
|
+
headers(
|
31
|
+
'Content-Type' => 'text/html; charset=utf-8',
|
32
|
+
'Access-Control-Allow-Origin' => '*')
|
28
33
|
body '<body>'
|
29
34
|
end
|
30
35
|
|
31
36
|
get '/png' do
|
32
37
|
status 200
|
33
|
-
headers
|
34
|
-
'Content-Type' => 'image/png'
|
38
|
+
headers(
|
39
|
+
'Content-Type' => 'image/png',
|
40
|
+
'Access-Control-Allow-Origin' => '*')
|
35
41
|
body cat_image
|
36
42
|
end
|
37
43
|
|
38
44
|
get '/404' do
|
39
45
|
status 404
|
46
|
+
headers \
|
47
|
+
'Access-Control-Allow-Origin' => '*'
|
40
48
|
end
|
41
49
|
|
42
50
|
get '/500' do
|
43
51
|
status 500
|
52
|
+
headers \
|
53
|
+
'Access-Control-Allow-Origin' => '*'
|
44
54
|
end
|
45
55
|
|
46
56
|
get '/last_modified' do
|
47
57
|
status 200
|
48
|
-
headers
|
49
|
-
|
50
|
-
|
58
|
+
headers(
|
59
|
+
'Content-Type' => 'text/plain',
|
60
|
+
'Last-Modified' => 'Wed, 21 Oct 2015 07:28:00 GMT',
|
61
|
+
'Access-Control-Allow-Origin' => '*')
|
51
62
|
body 'Look Ma, I have a Last-Modified header'
|
52
63
|
end
|
64
|
+
|
65
|
+
get '/*' do
|
66
|
+
status 404
|
67
|
+
headers \
|
68
|
+
'Access-Control-Allow-Origin' => '*'
|
69
|
+
end
|