opal 1.5.1 → 1.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.github/workflows/build.yml +17 -3
  4. data/HACKING.md +23 -0
  5. data/README.md +3 -3
  6. data/UNRELEASED.md +47 -0
  7. data/benchmark/run.rb +1 -0
  8. data/docs/compiled_ruby.md +8 -0
  9. data/docs/compiler.md +1 -1
  10. data/docs/compiler_directives.md +1 -1
  11. data/docs/getting_started.md +17 -0
  12. data/docs/headless_chrome.md +1 -1
  13. data/docs/index.md +123 -0
  14. data/docs/jquery.md +5 -5
  15. data/docs/templates.md +37 -37
  16. data/docs/unsupported_features.md +0 -4
  17. data/lib/opal/builder.rb +59 -39
  18. data/lib/opal/builder_processors.rb +24 -0
  19. data/lib/opal/builder_scheduler/prefork.rb +262 -0
  20. data/lib/opal/builder_scheduler/sequential.rb +13 -0
  21. data/lib/opal/builder_scheduler.rb +29 -0
  22. data/lib/opal/cache/file_cache.rb +13 -2
  23. data/lib/opal/cli.rb +36 -19
  24. data/lib/opal/cli_options.rb +4 -0
  25. data/lib/opal/cli_runners/chrome.rb +17 -13
  26. data/lib/opal/cli_runners/chrome_cdp_interface.rb +19 -2
  27. data/lib/opal/cli_runners/compiler.rb +1 -1
  28. data/lib/opal/cli_runners/gjs.rb +3 -1
  29. data/lib/opal/cli_runners/mini_racer.rb +5 -3
  30. data/lib/opal/cli_runners/nodejs.rb +3 -3
  31. data/lib/opal/cli_runners/server.rb +13 -28
  32. data/lib/opal/cli_runners/system_runner.rb +5 -3
  33. data/lib/opal/cli_runners.rb +7 -6
  34. data/lib/opal/compiler.rb +25 -2
  35. data/lib/opal/config.rb +10 -0
  36. data/lib/opal/eof_content.rb +5 -2
  37. data/lib/opal/nodes/args/ensure_kwargs_are_kwargs.rb +2 -6
  38. data/lib/opal/nodes/args/extract_kwarg.rb +3 -4
  39. data/lib/opal/nodes/args/extract_kwargs.rb +3 -1
  40. data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -1
  41. data/lib/opal/nodes/args/extract_kwrestarg.rb +4 -1
  42. data/lib/opal/nodes/args/extract_optarg.rb +1 -1
  43. data/lib/opal/nodes/args/extract_post_arg.rb +1 -1
  44. data/lib/opal/nodes/args/extract_post_optarg.rb +1 -1
  45. data/lib/opal/nodes/args/extract_restarg.rb +2 -2
  46. data/lib/opal/nodes/args/initialize_iterarg.rb +1 -1
  47. data/lib/opal/nodes/args/initialize_shadowarg.rb +1 -1
  48. data/lib/opal/nodes/args/prepare_post_args.rb +4 -2
  49. data/lib/opal/nodes/base.rb +14 -3
  50. data/lib/opal/nodes/call.rb +13 -16
  51. data/lib/opal/nodes/class.rb +3 -1
  52. data/lib/opal/nodes/closure.rb +250 -0
  53. data/lib/opal/nodes/def.rb +7 -11
  54. data/lib/opal/nodes/definitions.rb +4 -2
  55. data/lib/opal/nodes/if.rb +12 -2
  56. data/lib/opal/nodes/iter.rb +11 -17
  57. data/lib/opal/nodes/logic.rb +15 -63
  58. data/lib/opal/nodes/module.rb +3 -1
  59. data/lib/opal/nodes/rescue.rb +23 -15
  60. data/lib/opal/nodes/scope.rb +7 -1
  61. data/lib/opal/nodes/top.rb +27 -4
  62. data/lib/opal/nodes/while.rb +42 -26
  63. data/lib/opal/nodes.rb +1 -0
  64. data/lib/opal/os.rb +59 -0
  65. data/lib/opal/rewriter.rb +2 -0
  66. data/lib/opal/rewriters/returnable_logic.rb +14 -0
  67. data/lib/opal/rewriters/thrower_finder.rb +90 -0
  68. data/lib/opal/simple_server.rb +12 -6
  69. data/lib/opal/source_map/file.rb +4 -3
  70. data/lib/opal/source_map/map.rb +9 -1
  71. data/lib/opal/util.rb +1 -1
  72. data/lib/opal/version.rb +1 -1
  73. data/opal/corelib/array.rb +68 -3
  74. data/opal/corelib/basic_object.rb +1 -0
  75. data/opal/corelib/comparable.rb +1 -1
  76. data/opal/corelib/complex.rb +1 -0
  77. data/opal/corelib/constants.rb +2 -2
  78. data/opal/corelib/enumerable.rb +4 -2
  79. data/opal/corelib/enumerator/chain.rb +4 -0
  80. data/opal/corelib/enumerator/generator.rb +5 -3
  81. data/opal/corelib/enumerator/lazy.rb +3 -1
  82. data/opal/corelib/enumerator/yielder.rb +2 -4
  83. data/opal/corelib/enumerator.rb +3 -1
  84. data/opal/corelib/error/errno.rb +3 -1
  85. data/opal/corelib/error.rb +13 -2
  86. data/opal/corelib/hash.rb +39 -1
  87. data/opal/corelib/io.rb +1 -1
  88. data/opal/corelib/kernel.rb +56 -5
  89. data/opal/corelib/module.rb +60 -4
  90. data/opal/corelib/proc.rb +8 -5
  91. data/opal/corelib/rational.rb +1 -0
  92. data/opal/corelib/regexp.rb +15 -1
  93. data/opal/corelib/runtime.js +307 -238
  94. data/opal/corelib/string/encoding.rb +0 -6
  95. data/opal/corelib/string.rb +28 -7
  96. data/opal/corelib/time.rb +5 -2
  97. data/opal/corelib/unsupported.rb +2 -14
  98. data/opal.gemspec +2 -2
  99. data/spec/filters/bugs/delegate.rb +11 -0
  100. data/spec/filters/bugs/kernel.rb +1 -3
  101. data/spec/filters/bugs/language.rb +3 -23
  102. data/spec/filters/bugs/method.rb +0 -1
  103. data/spec/filters/bugs/module.rb +0 -3
  104. data/spec/filters/bugs/proc.rb +0 -3
  105. data/spec/filters/bugs/set.rb +4 -16
  106. data/spec/filters/bugs/unboundmethod.rb +0 -2
  107. data/spec/filters/unsupported/array.rb +0 -58
  108. data/spec/filters/unsupported/freeze.rb +8 -192
  109. data/spec/filters/unsupported/hash.rb +0 -25
  110. data/spec/filters/unsupported/kernel.rb +0 -1
  111. data/spec/filters/unsupported/privacy.rb +17 -0
  112. data/spec/lib/builder_spec.rb +14 -0
  113. data/spec/lib/cli_runners/server_spec.rb +2 -3
  114. data/spec/lib/cli_spec.rb +15 -1
  115. data/spec/lib/compiler_spec.rb +1 -1
  116. data/spec/opal/core/language/DATA/characters_support_crlf_spec.rb +9 -0
  117. data/spec/opal/core/language/DATA/multiple___END___crlf_spec.rb +10 -0
  118. data/spec/opal/core/language/if_spec.rb +13 -0
  119. data/spec/opal/core/language/safe_navigator_spec.rb +10 -0
  120. data/spec/opal/core/module_spec.rb +8 -0
  121. data/spec/ruby_specs +2 -1
  122. data/stdlib/await.rb +44 -7
  123. data/stdlib/delegate.rb +427 -6
  124. data/stdlib/headless_chrome.rb +6 -2
  125. data/stdlib/nodejs/file.rb +2 -1
  126. data/stdlib/opal-parser.rb +1 -1
  127. data/stdlib/opal-platform.rb +1 -1
  128. data/stdlib/opal-replutils.rb +5 -3
  129. data/stdlib/promise.rb +3 -0
  130. data/stdlib/rbconfig.rb +4 -1
  131. data/stdlib/ruby2_keywords.rb +60 -0
  132. data/stdlib/set.rb +21 -0
  133. data/tasks/performance.rake +41 -35
  134. data/tasks/releasing.rake +1 -0
  135. data/tasks/testing/mspec_special_calls.rb +1 -0
  136. data/tasks/testing.rake +13 -12
  137. data/test/nodejs/test_await.rb +39 -1
  138. data/test/nodejs/test_file.rb +3 -2
  139. metadata +37 -22
  140. data/docs/faq.md +0 -17
  141. data/lib/opal/rewriters/break_finder.rb +0 -36
  142. data/spec/opal/core/kernel/freeze_spec.rb +0 -15
@@ -0,0 +1,60 @@
1
+ # This file ended up in Opal as a port of:
2
+ # https://github.com/ruby/ruby2_keywords/blob/master/lib/ruby2_keywords.rb
3
+
4
+ class Module
5
+ unless private_method_defined?(:ruby2_keywords)
6
+ private
7
+ # call-seq:
8
+ # ruby2_keywords(method_name, ...)
9
+ #
10
+ # Does nothing.
11
+ def ruby2_keywords(name, *)
12
+ # nil
13
+ end
14
+ end
15
+ end
16
+
17
+ main = TOPLEVEL_BINDING.eval('self')
18
+ unless main.respond_to?(:ruby2_keywords, true)
19
+ # call-seq:
20
+ # ruby2_keywords(method_name, ...)
21
+ #
22
+ # Does nothing.
23
+ def main.ruby2_keywords(name, *)
24
+ # nil
25
+ end
26
+ end
27
+
28
+ class Proc
29
+ unless method_defined?(:ruby2_keywords)
30
+ # call-seq:
31
+ # proc.ruby2_keywords -> proc
32
+ #
33
+ # Does nothing and just returns the receiver.
34
+ def ruby2_keywords
35
+ self
36
+ end
37
+ end
38
+ end
39
+
40
+ class << Hash
41
+ unless method_defined?(:ruby2_keywords_hash?)
42
+ # call-seq:
43
+ # Hash.ruby2_keywords_hash?(hash) -> false
44
+ #
45
+ # Returns false.
46
+ def ruby2_keywords_hash?(hash)
47
+ false
48
+ end
49
+ end
50
+
51
+ unless method_defined?(:ruby2_keywords_hash)
52
+ # call-seq:
53
+ # Hash.ruby2_keywords_hash(hash) -> new_hash
54
+ #
55
+ # Duplicates a given hash and returns the new hash.
56
+ def ruby2_keywords_hash(hash)
57
+ hash.dup
58
+ end
59
+ end
60
+ end
data/stdlib/set.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # helpers: freeze
1
2
  # Portions Copyright (c) 2002-2013 Akinori MUSHA <knu@iDaemons.org>
2
3
  class ::Set
3
4
  include ::Enumerable
@@ -70,6 +71,19 @@ class ::Set
70
71
  replace result
71
72
  end
72
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
+
73
87
  def delete(o)
74
88
  @hash.delete(o)
75
89
  self
@@ -90,6 +104,13 @@ class ::Set
90
104
  self
91
105
  end
92
106
 
107
+ def freeze
108
+ return self if frozen?
109
+
110
+ @hash.freeze
111
+ `$freeze(self)`
112
+ end
113
+
93
114
  def keep_if
94
115
  return enum_for(:keep_if) unless block_given?
95
116
  reject { |o| yield o }.each { |o| @hash.delete(o) }
@@ -1,6 +1,9 @@
1
1
  # A set of tasks to track performance regressions by the CI
2
2
 
3
- require 'opal/util'
3
+ require_relative "#{__dir__}/../lib/opal/util"
4
+ require_relative "#{__dir__}/../lib/opal/os"
5
+
6
+ OS = Opal::OS
4
7
 
5
8
  class Timing
6
9
  def initialize(tries: 31, &block)
@@ -18,25 +21,28 @@ class Timing
18
21
 
19
22
  attr_reader :times, :tries
20
23
 
21
- # Runs a block N times and returns a mean number of seconds it took to run it.
24
+ # Runs a block N times and returns the best number of seconds it took to run it.
22
25
  def mean_time
23
26
  @times.sort[tries/2.0.floor + 1]
24
27
  end
25
28
 
29
+ def best_time
30
+ @times.min
31
+ end
32
+
26
33
  def error
27
- m = mean_time
28
- @times.minmax.map { |t| (m - t).abs }.max
34
+ @times.max - @times.min
29
35
  end
30
36
 
31
37
  def compare_to(previous, name)
32
38
  current = self
33
39
  percent = ->(a, b) { (a / b) * 100 }
34
- change = percent[(current.mean_time - previous.mean_time), previous.mean_time]
40
+ change = percent[(current.best_time - previous.best_time), previous.best_time]
35
41
 
36
- puts ("%30s: %.3f (±%.2f%%) -> %.3f (±%.2f%%) (change: %+.2f%%)" % [
42
+ puts ("%30s: %.3f (+%.2f%%) -> %.3f (+%.2f%%) (change: %+.2f%%)" % [
37
43
  name,
38
- previous.mean_time / 1_000_000.0, percent[previous.error, previous.mean_time],
39
- current.mean_time / 1_000_000.0, percent[current.error, current.mean_time],
44
+ previous.best_time / 1_000_000.0, percent[previous.error, previous.best_time],
45
+ current.best_time / 1_000_000.0, percent[current.error, current.best_time],
40
46
  change
41
47
  ]).gsub('.000','')
42
48
 
@@ -52,7 +58,7 @@ class Size
52
58
  attr_reader :size
53
59
 
54
60
  def compare_to(previous, name)
55
- change = 100 * (previous.size - size) / previous.size
61
+ change = 100.0 * (size - previous.size) / previous.size
56
62
  puts ("%30s: %5.2f kB -> %5.2f kB (change: %+.2f%%)" % [
57
63
  name,
58
64
  previous.size / 1_000.0,
@@ -67,35 +73,34 @@ end
67
73
  $failures = []
68
74
 
69
75
  ASCIIDOCTOR_REPO_BASE = ENV['ASCIIDOCTOR_REPO_BASE'] || 'https://github.com/asciidoctor'
70
-
76
+ ASCIIDOCTOR_COMMIT = '869e8236'
77
+ ASCIIDOCTOR_JS_COMMIT = '053fa0d3'
71
78
  # Selected asciidoctor versions were working on Aug 19 2021, feel free to update.
72
- ASCIIDOCTOR_PREPARE = [
73
- "bundle",
74
- "exec",
75
- "bash",
76
- "-c",
77
- <<~BASH
78
- mkdir -p tmp/performance
79
- pushd tmp/performance
80
- git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor >/dev/null 2>&1
81
- pushd asciidoctor; git checkout 869e8236 >/dev/null 2>&1; popd
82
- git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor.js >/dev/null 2>&1
83
- pushd asciidoctor.js; git checkout 053fa0d3 >/dev/null 2>&1; popd
84
- erb ../../tasks/performance/asciidoctor_test.rb.erb > asciidoctor_test.rb
85
- popd
86
- BASH
87
- ]
88
-
89
- ASCIIDOCTOR_BUILD_OPAL = "bin/opal --no-cache -c " \
90
- "-Itmp/performance/asciidoctor/lib " \
91
- "-Itmp/performance/asciidoctor.js/packages/core/lib " \
92
- "-sconcurrent/map -sslim/include " \
93
- "tmp/performance/asciidoctor_test.rb > tmp/performance/asciidoctor_test.js"
79
+ S = OS.path_sep
80
+ ASCIIDOCTOR_PREPARE = OS.bash_c(
81
+ "pushd tmp#{S}performance",
82
+ "git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor >#{OS.dev_null} 2>&1",
83
+ "pushd asciidoctor", "git checkout #{ASCIIDOCTOR_COMMIT} >#{OS.dev_null} 2>&1", "popd",
84
+ "git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor.js >#{OS.dev_null} 2>&1",
85
+ "pushd asciidoctor.js", "git checkout #{ASCIIDOCTOR_JS_COMMIT} >#{OS.dev_null} 2>&1", "popd",
86
+ "erb ../../tasks/performance/asciidoctor_test.rb.erb > asciidoctor_test.rb",
87
+ "popd"
88
+ )
89
+
90
+ ASCIIDOCTOR_BUILD_OPAL = "#{'ruby ' if Gem.win_platform?}bin/opal --no-cache -c " \
91
+ "-Itmp/performance/asciidoctor/lib " \
92
+ "-Itmp/performance/asciidoctor.js/packages/core/lib " \
93
+ "-sconcurrent/map -sslim/include " \
94
+ "tmp/performance/asciidoctor_test.rb > tmp/performance/asciidoctor_test.js"
94
95
  ASCIIDOCTOR_RUN_RUBY = "bundle exec ruby -Itmp/performance/asciidoctor/lib tmp/performance/asciidoctor_test.rb"
95
96
  ASCIIDOCTOR_RUN_OPAL = "node tmp/performance/asciidoctor_test.js"
96
97
 
97
98
  # Generate V8 function optimization status report for corelib methods
98
- NODE_OPTSTATUS = "env NODE_OPTS=--allow-natives-syntax bin/opal tasks/performance/optimization_status.rb"
99
+ NODE_OPTSTATUS = if Gem.win_platform?
100
+ "set NODE_OPTS=--allow-natives-syntax && ruby bin/opal tasks/performance/optimization_status.rb"
101
+ else
102
+ "env NODE_OPTS=--allow-natives-syntax bin/opal tasks/performance/optimization_status.rb"
103
+ end
99
104
 
100
105
  performance_stat = ->(name) {
101
106
  stat = {}
@@ -128,6 +133,7 @@ namespace :performance do
128
133
 
129
134
  # Prepare
130
135
  puts "\n* Preparing asciidoctor..."
136
+ FileUtils.mkdir_p("tmp/performance") unless Dir.exist?("tmp/performance")
131
137
  sh(*ASCIIDOCTOR_PREPARE)
132
138
 
133
139
  puts "\n* Running AsciiDoctor with CRuby..."
@@ -136,12 +142,12 @@ namespace :performance do
136
142
  current = performance_stat.(:current)
137
143
 
138
144
  # Prepare previous
139
- sh("git checkout --recurse-submodules #{ref} && bundle install >/dev/null 2>&1")
145
+ sh("git checkout --recurse-submodules #{ref} && bundle install >#{OS.dev_null} 2>&1")
140
146
 
141
147
  previous = performance_stat.(:previous)
142
148
 
143
149
  # Restore current
144
- sh("git checkout --recurse-submodules - && bundle install >/dev/null 2>&1")
150
+ sh("git checkout --recurse-submodules - && bundle install >#{OS.dev_null} 2>&1")
145
151
 
146
152
  # Summary
147
153
  puts "\n=== Summary ==="
data/tasks/releasing.rake CHANGED
@@ -47,6 +47,7 @@ CHANGELOG_HEADING = <<~MARKDOWN
47
47
  - **Removed** for deprecated features removed in this release.
48
48
  - **Fixed** for any bug fixes.
49
49
  - **Security** to invite users to upgrade in case of vulnerabilities.
50
+ - **Performance** changes related to speed and efficiency.
50
51
  MARKDOWN
51
52
 
52
53
  desc "Update CHANGELOG.md using info from published GitHub releases (the first unreleased section is preserved)"
@@ -35,6 +35,7 @@ class Opal::Nodes::CallNode
35
35
  end
36
36
  end
37
37
 
38
+ require 'opal/rewriter'
38
39
  require 'opal/rewriters/rubyspec/filters_rewriter'
39
40
 
40
41
  Opal::Rewriter.use Opal::Rubyspec::FiltersRewriter
data/tasks/testing.rake CHANGED
@@ -1,4 +1,8 @@
1
+ require_relative "#{__dir__}/../lib/opal/os"
1
2
  require 'rspec/core/rake_task'
3
+
4
+ OS = Opal::OS
5
+
2
6
  RSpec::Core::RakeTask.new(:rspec) do |t|
3
7
  t.pattern = 'spec/lib/**/*_spec.rb'
4
8
  end
@@ -249,7 +253,7 @@ module Testing
249
253
  puts 'Server ready.'
250
254
  yield self
251
255
  ensure
252
- if windows?
256
+ if OS.windows?
253
257
  # https://blog.simplificator.com/2016/01/18/how-to-kill-processes-on-windows-using-ruby/
254
258
  # system("taskkill /f /pid #{pid}")
255
259
  Process.kill("KILL", server)
@@ -260,10 +264,6 @@ module Testing
260
264
  end
261
265
  end
262
266
 
263
- def windows?
264
- (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
265
- end
266
-
267
267
  def sinatra_server_running?
268
268
  puts "Connecting to localhost:4567..."
269
269
  TCPSocket.new('localhost', '4567').close
@@ -427,14 +427,15 @@ task :smoke_test do
427
427
  extend RSpec::Matchers
428
428
  expect(actual_output.lines[0]).to eq("..\n")
429
429
  expect(actual_output.lines[1]).to eq("\n")
430
- expect(actual_output.lines[2]).to match(%r{^Finished in \d+\.\d+ seconds \(files took \d+\.\d+ seconds to load\)\n$})
431
- expect(actual_output.lines[3]).to eq("2 examples, 0 failures\n")
432
- expect(actual_output.lines[4]).to eq("\n")
433
- expect(actual_output.lines[5]).to match(%r{Top 2 slowest examples \(\d+\.\d+ seconds, \d+\.\d+% of total time\):\n})
434
- expect(actual_output.lines[7]).to match(%r{ \[1m\d+\.\d+\[0m \[1mseconds\[0m \n})
430
+ expect(actual_output.lines[2]).to match(%r{Top 2 slowest examples \(\d+\.\d+ seconds, \d+\.\d+% of total time\):\n})
431
+ expect(actual_output.lines[4]).to match(%r{ \[1m\d+\.\d+\[0m \[1mseconds\[0m .*deprecations_spec\.rb:7\n})
432
+ expect(actual_output.lines[6]).to match(%r{ \[1m\d+\.\d+\[0m \[1mseconds\[0m .*deprecations_spec\.rb:12\n})
433
+ expect(actual_output.lines[7]).to eq("\n")
434
+ expect(actual_output.lines[8]).to match(%r{^Finished in \d+\.\d+ seconds \(files took \d+\.\d+ seconds to load\)\n$})
435
+ expect(actual_output.lines[9]).to eq("2 examples, 0 failures\n")
435
436
  expect([
436
- actual_output.lines[6],
437
- actual_output.lines[8],
437
+ actual_output.lines[3],
438
+ actual_output.lines[5],
438
439
  ]).to contain_exactly(
439
440
  " Opal::Deprecations defaults to warn\n",
440
441
  " Opal::Deprecations can be set to raise\n",
@@ -9,6 +9,11 @@ class TestAwait < Test::Unit::TestCase
9
9
  require "await"
10
10
  RUBY
11
11
 
12
+ autoawaitheader = <<~RUBY
13
+ # await: *await*
14
+ require "await"
15
+ RUBY
16
+
12
17
  tests = {
13
18
  test_await_in_top: [<<~RUBY, 6],
14
19
  #{stdheader}
@@ -158,6 +163,39 @@ class TestAwait < Test::Unit::TestCase
158
163
  $taval = 5
159
164
  $taval = PromiseV2.value(5).__await__ + 10
160
165
  RUBY
166
+ # Bug before Opal 1.6: compiled autoawait expressions had wrong parentheses rules
167
+ test_autoawait_awaiting: [<<~RUBY, "very correct"],
168
+ #{autoawaitheader}
169
+ $taval = "incorrect"
170
+ $taval = PromiseV2.value("also incorrect").await.sub("also in", "")
171
+ $taval = PromiseV2.value("very ").await + $taval
172
+ RUBY
173
+ test_autoawait_instance_exec_await: [<<~RUBY, 2*3*5*7*11*13],
174
+ #{autoawaitheader}
175
+ # await: *await*
176
+ $taval = 1
177
+ module AutoawaitTemporary1
178
+ $block_with_module_self = proc do
179
+ # Ensure that block.$$s is generated:
180
+ self
181
+ # AutoawaitTemporary2.$$eval should be true, block.$$s should be unset
182
+ `\#{AutoawaitTemporary2}.$$eval` && ($taval *= PromiseV2.value(2).await)
183
+ `block.$$s === null` && ($taval *= PromiseV2.value(3).await)
184
+ end
185
+ block = $block_with_module_self
186
+ end
187
+ block = $block_with_module_self
188
+ module AutoawaitTemporary2; end
189
+ # AutoawaitTemporary2.$$eval should be false, block.$$s should refer to AutoawaitTemporary1
190
+ `\#{AutoawaitTemporary2}.$$eval` || ($taval *= PromiseV2.value(5).await)
191
+ `block.$$s === \#{AutoawaitTemporary1}` && ($taval *= PromiseV2.value(7).await)
192
+ module AutoawaitTemporary2
193
+ instance_exec_await(&$block_with_module_self)
194
+ end
195
+ # both should get their values back after instance_exec_await is finished
196
+ `\#{AutoawaitTemporary2}.$$eval` || ($taval *= PromiseV2.value(11).await)
197
+ `block.$$s === \#{AutoawaitTemporary1}` && ($taval *= PromiseV2.value(13).await)
198
+ RUBY
161
199
  }
162
200
 
163
201
  tests.each do |name,(code,expect)|
@@ -166,4 +204,4 @@ class TestAwait < Test::Unit::TestCase
166
204
  assert_equal(expect, $taval)
167
205
  end
168
206
  end
169
- end
207
+ end
@@ -175,6 +175,7 @@ class TestNodejsFile < Test::Unit::TestCase
175
175
  end if windows_platform?
176
176
 
177
177
  def test_windows_file_expand_path
178
+ # do not use d: because its a symlink in github actions fs, leading to unexpected results
178
179
  drive_letter = Dir.pwd.slice(0, 2)
179
180
  assert_equal(Dir.pwd + '/foo/bar.js', File.expand_path('./foo/bar.js'))
180
181
  assert_equal(drive_letter + '/foo/bar.js', File.expand_path('/foo/bar.js'))
@@ -186,8 +187,8 @@ class TestNodejsFile < Test::Unit::TestCase
186
187
  assert_equal('c:/bar.js', File.expand_path('\\..\\bar.js', 'c:\\foo\\baz\\'))
187
188
  assert_equal('c:/foo/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo'))
188
189
  assert_equal('c:/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo\\..'))
189
- assert_equal('d:/', File.expand_path('d:'), 'should add a trailing slash when the path is d:')
190
- assert_equal('d:/', File.expand_path('d:/'), 'should preserve the trailing slash when the path d:/')
190
+ assert_equal('f:/', File.expand_path('f:'), 'should add a trailing slash when the path is d:')
191
+ assert_equal('g:/', File.expand_path('g:/'), 'should preserve the trailing slash when the path d:/')
191
192
  assert_equal(Dir.pwd, File.expand_path(drive_letter), 'should expand to the current directory when the path is c: (and the current directory is located in the c drive)')
192
193
  assert_equal(drive_letter + '/', drive_letter + '/', 'should return c:/ when the path is c:/ because the path is absolute')
193
194
  end if windows_platform?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.6.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-07-20 00:00:00.000000000 Z
13
+ date: 2022-11-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ast
@@ -162,16 +162,16 @@ dependencies:
162
162
  name: sinatra
163
163
  requirement: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - ">="
165
+ - - "~>"
166
166
  - !ruby/object:Gem::Version
167
- version: '0'
167
+ version: '3.0'
168
168
  type: :development
169
169
  prerelease: false
170
170
  version_requirements: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - ">="
172
+ - - "~>"
173
173
  - !ruby/object:Gem::Version
174
- version: '0'
174
+ version: '3.0'
175
175
  - !ruby/object:Gem::Dependency
176
176
  name: rubocop
177
177
  requirement: !ruby/object:Gem::Requirement
@@ -204,16 +204,16 @@ dependencies:
204
204
  name: rack
205
205
  requirement: !ruby/object:Gem::Requirement
206
206
  requirements:
207
- - - ">="
207
+ - - "~>"
208
208
  - !ruby/object:Gem::Version
209
- version: '0'
209
+ version: '2.2'
210
210
  type: :development
211
211
  prerelease: false
212
212
  version_requirements: !ruby/object:Gem::Requirement
213
213
  requirements:
214
- - - ">="
214
+ - - "~>"
215
215
  - !ruby/object:Gem::Version
216
- version: '0'
216
+ version: '2.2'
217
217
  - !ruby/object:Gem::Dependency
218
218
  name: webrick
219
219
  requirement: !ruby/object:Gem::Requirement
@@ -396,9 +396,9 @@ files:
396
396
  - docs/compiler_directives.md
397
397
  - docs/configuring_gems.md
398
398
  - docs/encoding.md
399
- - docs/faq.md
400
399
  - docs/getting_started.md
401
400
  - docs/headless_chrome.md
401
+ - docs/index.md
402
402
  - docs/jquery.md
403
403
  - docs/opal_parser.md
404
404
  - docs/promises.md
@@ -439,6 +439,9 @@ files:
439
439
  - lib/opal/ast/node.rb
440
440
  - lib/opal/builder.rb
441
441
  - lib/opal/builder_processors.rb
442
+ - lib/opal/builder_scheduler.rb
443
+ - lib/opal/builder_scheduler/prefork.rb
444
+ - lib/opal/builder_scheduler/sequential.rb
442
445
  - lib/opal/cache.rb
443
446
  - lib/opal/cache/file_cache.rb
444
447
  - lib/opal/cli.rb
@@ -530,6 +533,7 @@ files:
530
533
  - lib/opal/nodes/call.rb
531
534
  - lib/opal/nodes/call_special.rb
532
535
  - lib/opal/nodes/class.rb
536
+ - lib/opal/nodes/closure.rb
533
537
  - lib/opal/nodes/constants.rb
534
538
  - lib/opal/nodes/def.rb
535
539
  - lib/opal/nodes/defined.rb
@@ -555,6 +559,7 @@ files:
555
559
  - lib/opal/nodes/while.rb
556
560
  - lib/opal/nodes/x_string.rb
557
561
  - lib/opal/nodes/yield.rb
562
+ - lib/opal/os.rb
558
563
  - lib/opal/parser.rb
559
564
  - lib/opal/parser/default_config.rb
560
565
  - lib/opal/parser/patch.rb
@@ -570,7 +575,6 @@ files:
570
575
  - lib/opal/rewriters/base.rb
571
576
  - lib/opal/rewriters/binary_operator_assignment.rb
572
577
  - lib/opal/rewriters/block_to_iter.rb
573
- - lib/opal/rewriters/break_finder.rb
574
578
  - lib/opal/rewriters/dot_js_syntax.rb
575
579
  - lib/opal/rewriters/dump_args.rb
576
580
  - lib/opal/rewriters/for_rewriter.rb
@@ -585,6 +589,7 @@ files:
585
589
  - lib/opal/rewriters/pattern_matching.rb
586
590
  - lib/opal/rewriters/returnable_logic.rb
587
591
  - lib/opal/rewriters/rubyspec/filters_rewriter.rb
592
+ - lib/opal/rewriters/thrower_finder.rb
588
593
  - lib/opal/server.rb
589
594
  - lib/opal/simple_server.rb
590
595
  - lib/opal/source_map.rb
@@ -677,6 +682,7 @@ files:
677
682
  - spec/filters/bugs/complex.rb
678
683
  - spec/filters/bugs/date.rb
679
684
  - spec/filters/bugs/datetime.rb
685
+ - spec/filters/bugs/delegate.rb
680
686
  - spec/filters/bugs/encoding.rb
681
687
  - spec/filters/bugs/enumerable.rb
682
688
  - spec/filters/bugs/enumerator.rb
@@ -844,18 +850,20 @@ files:
844
850
  - spec/opal/core/io/read_spec.rb
845
851
  - spec/opal/core/iterable_props_spec.rb
846
852
  - spec/opal/core/kernel/at_exit_spec.rb
847
- - spec/opal/core/kernel/freeze_spec.rb
848
853
  - spec/opal/core/kernel/instance_variables_spec.rb
849
854
  - spec/opal/core/kernel/methods_spec.rb
850
855
  - spec/opal/core/kernel/public_methods_spec.rb
851
856
  - spec/opal/core/kernel/puts_spec.rb
852
857
  - spec/opal/core/kernel/require_tree_spec.rb
853
858
  - spec/opal/core/kernel/respond_to_spec.rb
859
+ - spec/opal/core/language/DATA/characters_support_crlf_spec.rb
854
860
  - spec/opal/core/language/DATA/characters_support_spec.rb
855
861
  - spec/opal/core/language/DATA/empty___END___spec.rb
862
+ - spec/opal/core/language/DATA/multiple___END___crlf_spec.rb
856
863
  - spec/opal/core/language/DATA/multiple___END___spec.rb
857
864
  - spec/opal/core/language/arguments/mlhs_arg_spec.rb
858
865
  - spec/opal/core/language/forward_args_spec.rb
866
+ - spec/opal/core/language/if_spec.rb
859
867
  - spec/opal/core/language/infinite_range_spec.rb
860
868
  - spec/opal/core/language/keyword_arguments_spec.rb
861
869
  - spec/opal/core/language/memoization_spec.rb
@@ -1091,6 +1099,7 @@ files:
1091
1099
  - stdlib/racc/parser.rb
1092
1100
  - stdlib/rbconfig.rb
1093
1101
  - stdlib/rbconfig/sizeof.rb
1102
+ - stdlib/ruby2_keywords.rb
1094
1103
  - stdlib/securerandom.rb
1095
1104
  - stdlib/set.rb
1096
1105
  - stdlib/shellwords.rb
@@ -1160,10 +1169,10 @@ licenses:
1160
1169
  metadata:
1161
1170
  homepage_uri: https://opalrb.com/
1162
1171
  bug_tracker_uri: https://github.com/opal/opal/issues
1163
- changelog_uri: https://github.com/opal/opal/blob/v1.5.1/CHANGELOG.md
1164
- readme_uri: https://github.com/opal/opal/blob/v1.5.1/README.md
1165
- api_documentation_uri: http://opalrb.com/docs/api/v1.5.1/index.html
1166
- guides_uri: http://opalrb.com/docs/guides/v1.5.1/index.html
1172
+ changelog_uri: https://github.com/opal/opal/blob/v1.6.0.rc1/CHANGELOG.md
1173
+ readme_uri: https://github.com/opal/opal/blob/v1.6.0.rc1/README.md
1174
+ api_documentation_uri: http://opalrb.com/docs/api/v1.6.0.rc1/index.html
1175
+ guides_uri: http://opalrb.com/docs/guides/v1.6.0.rc1/index.html
1167
1176
  chat_uri: https://gitter.im/opal/opal
1168
1177
  source_code_uri: https://github.com/opal/opal
1169
1178
  post_install_message:
@@ -1177,11 +1186,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
1177
1186
  version: '2.3'
1178
1187
  required_rubygems_version: !ruby/object:Gem::Requirement
1179
1188
  requirements:
1180
- - - ">="
1189
+ - - ">"
1181
1190
  - !ruby/object:Gem::Version
1182
- version: '0'
1191
+ version: 1.3.1
1183
1192
  requirements: []
1184
- rubygems_version: 3.3.13
1193
+ rubygems_version: 3.3.22
1185
1194
  signing_key:
1186
1195
  specification_version: 4
1187
1196
  summary: Ruby runtime and core library for JavaScript
@@ -1341,9 +1350,9 @@ test_files:
1341
1350
  - docs/compiler_directives.md
1342
1351
  - docs/configuring_gems.md
1343
1352
  - docs/encoding.md
1344
- - docs/faq.md
1345
1353
  - docs/getting_started.md
1346
1354
  - docs/headless_chrome.md
1355
+ - docs/index.md
1347
1356
  - docs/jquery.md
1348
1357
  - docs/opal_parser.md
1349
1358
  - docs/promises.md
@@ -1384,6 +1393,9 @@ test_files:
1384
1393
  - lib/opal/ast/node.rb
1385
1394
  - lib/opal/builder.rb
1386
1395
  - lib/opal/builder_processors.rb
1396
+ - lib/opal/builder_scheduler.rb
1397
+ - lib/opal/builder_scheduler/prefork.rb
1398
+ - lib/opal/builder_scheduler/sequential.rb
1387
1399
  - lib/opal/cache.rb
1388
1400
  - lib/opal/cache/file_cache.rb
1389
1401
  - lib/opal/cli.rb
@@ -1475,6 +1487,7 @@ test_files:
1475
1487
  - lib/opal/nodes/call.rb
1476
1488
  - lib/opal/nodes/call_special.rb
1477
1489
  - lib/opal/nodes/class.rb
1490
+ - lib/opal/nodes/closure.rb
1478
1491
  - lib/opal/nodes/constants.rb
1479
1492
  - lib/opal/nodes/def.rb
1480
1493
  - lib/opal/nodes/defined.rb
@@ -1500,6 +1513,7 @@ test_files:
1500
1513
  - lib/opal/nodes/while.rb
1501
1514
  - lib/opal/nodes/x_string.rb
1502
1515
  - lib/opal/nodes/yield.rb
1516
+ - lib/opal/os.rb
1503
1517
  - lib/opal/parser.rb
1504
1518
  - lib/opal/parser/default_config.rb
1505
1519
  - lib/opal/parser/patch.rb
@@ -1515,7 +1529,6 @@ test_files:
1515
1529
  - lib/opal/rewriters/base.rb
1516
1530
  - lib/opal/rewriters/binary_operator_assignment.rb
1517
1531
  - lib/opal/rewriters/block_to_iter.rb
1518
- - lib/opal/rewriters/break_finder.rb
1519
1532
  - lib/opal/rewriters/dot_js_syntax.rb
1520
1533
  - lib/opal/rewriters/dump_args.rb
1521
1534
  - lib/opal/rewriters/for_rewriter.rb
@@ -1530,6 +1543,7 @@ test_files:
1530
1543
  - lib/opal/rewriters/pattern_matching.rb
1531
1544
  - lib/opal/rewriters/returnable_logic.rb
1532
1545
  - lib/opal/rewriters/rubyspec/filters_rewriter.rb
1546
+ - lib/opal/rewriters/thrower_finder.rb
1533
1547
  - lib/opal/server.rb
1534
1548
  - lib/opal/simple_server.rb
1535
1549
  - lib/opal/source_map.rb
@@ -1758,6 +1772,7 @@ test_files:
1758
1772
  - stdlib/racc/parser.rb
1759
1773
  - stdlib/rbconfig.rb
1760
1774
  - stdlib/rbconfig/sizeof.rb
1775
+ - stdlib/ruby2_keywords.rb
1761
1776
  - stdlib/securerandom.rb
1762
1777
  - stdlib/set.rb
1763
1778
  - stdlib/shellwords.rb
data/docs/faq.md DELETED
@@ -1,17 +0,0 @@
1
- # FAQ
2
-
3
- ### Why does Opal exist?
4
-
5
- To try and keep ruby relevant in a world where client-side applications are making javascript the primary development platform.
6
-
7
- ### How compatible is Opal?
8
-
9
- We run opal against the [ruby spec](https://github.com/ruby/spec) as our primary testing setup. We try to make Opal as compatible as possible, whilst also taking into account restrictions of JavaScript when applicable. Opal supports the majority of ruby syntax features, as well as a very large part of the corelib implementation. We support method\_missing, modules, classes, instance\_exec, blocks, procs and lots lots more. Opal can compile and run RSpec unmodified, as well as self hosting the compiler at runtime.
10
-
11
- ### What version of ruby does Opal target?
12
-
13
- We are running tests under ruby 3.0.0 conditions, but are mostly compatible with 2.6 level features.
14
-
15
- ### Why doesn't Opal support mutable strings?
16
-
17
- All strings in Opal are immutable because ruby strings just get compiled directly into javascript strings, which are immutable. Wrapping ruby strings as a custom JavaScript object would add a lot of overhead as well as making interaction between ruby and javascript libraries more difficult.
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'opal/rewriter'
4
-
5
- module Opal
6
- module Rewriters
7
- class BreakFinder < Opal::Rewriters::Base
8
- def initialize
9
- @found_break = false
10
- end
11
-
12
- def found_break?
13
- @found_break
14
- end
15
-
16
- def on_break(node)
17
- @found_break = true
18
- node
19
- end
20
-
21
- def stop_lookup(node)
22
- # noop
23
- end
24
-
25
- # regular loops
26
- alias on_for stop_lookup
27
- alias on_while stop_lookup
28
- alias on_while_post stop_lookup
29
- alias on_until stop_lookup
30
- alias on_until_post stop_lookup
31
-
32
- # nested block
33
- alias on_block stop_lookup
34
- end
35
- end
36
- end