opal 1.3.0.alpha1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +3 -1
  3. data/CHANGELOG.md +139 -1
  4. data/UNRELEASED.md +2 -71
  5. data/docs/compiled_ruby.md +27 -16
  6. data/docs/faq.md +1 -1
  7. data/docs/headless_chrome.md +11 -21
  8. data/docs/jquery.md +1 -6
  9. data/docs/opal_parser.md +3 -1
  10. data/docs/promises.md +2 -0
  11. data/docs/releasing.md +20 -1
  12. data/docs/roda-sprockets.md +0 -1
  13. data/docs/source_maps.md +10 -11
  14. data/docs/static_applications.md +2 -2
  15. data/docs/unsupported_features.md +4 -0
  16. data/examples/rack/Gemfile +1 -0
  17. data/examples/rack/Gemfile.lock +11 -7
  18. data/examples/rack-esm/.gitignore +1 -0
  19. data/examples/rack-esm/Gemfile +5 -0
  20. data/examples/rack-esm/app/application.rb +27 -0
  21. data/examples/rack-esm/app/user.rb +24 -0
  22. data/examples/rack-esm/config.ru +25 -0
  23. data/examples/rack-esm/index.html.erb +11 -0
  24. data/examples/sinatra/Gemfile.lock +21 -19
  25. data/lib/opal/builder.rb +39 -23
  26. data/lib/opal/builder_processors.rb +6 -1
  27. data/lib/opal/cache/file_cache.rb +7 -6
  28. data/lib/opal/cli_runners/chrome.rb +23 -18
  29. data/lib/opal/cli_runners/chrome_cdp_interface.rb +1 -1
  30. data/lib/opal/cli_runners/nodejs.rb +3 -2
  31. data/lib/opal/cli_runners/quickjs.rb +28 -0
  32. data/lib/opal/cli_runners.rb +1 -0
  33. data/lib/opal/compiler.rb +8 -2
  34. data/lib/opal/config.rb +5 -0
  35. data/lib/opal/nodes/call.rb +49 -28
  36. data/lib/opal/nodes/helpers.rb +1 -1
  37. data/lib/opal/nodes/top.rb +5 -8
  38. data/lib/opal/repl.rb +2 -1
  39. data/lib/opal/rewriters/rubyspec/filters_rewriter.rb +16 -0
  40. data/lib/opal/simple_server.rb +7 -2
  41. data/lib/opal/util.rb +1 -1
  42. data/lib/opal/version.rb +1 -1
  43. data/opal/corelib/array.rb +1 -1
  44. data/opal/corelib/basic_object.rb +5 -1
  45. data/opal/corelib/binding.rb +5 -1
  46. data/opal/corelib/complex/base.rb +15 -0
  47. data/opal/corelib/complex.rb +3 -15
  48. data/opal/corelib/constants.rb +2 -2
  49. data/opal/corelib/error.rb +1 -1
  50. data/opal/corelib/helpers.rb +10 -0
  51. data/opal/corelib/io.rb +5 -1
  52. data/opal/corelib/kernel.rb +21 -5
  53. data/opal/corelib/main.rb +4 -0
  54. data/opal/corelib/method.rb +4 -0
  55. data/opal/corelib/module.rb +39 -16
  56. data/opal/corelib/pattern_matching/base.rb +35 -0
  57. data/opal/corelib/pattern_matching.rb +2 -36
  58. data/opal/corelib/proc.rb +4 -1
  59. data/opal/corelib/process/base.rb +9 -0
  60. data/opal/corelib/process.rb +1 -11
  61. data/opal/corelib/random.rb +4 -0
  62. data/opal/corelib/rational/base.rb +11 -0
  63. data/opal/corelib/rational.rb +3 -10
  64. data/opal/corelib/regexp.rb +8 -8
  65. data/opal/corelib/runtime.js +38 -3
  66. data/opal/corelib/string.rb +3 -3
  67. data/opal/opal/full.rb +5 -4
  68. data/opal/opal.rb +12 -11
  69. data/package.json +1 -1
  70. data/spec/filters/bugs/basicobject.rb +0 -1
  71. data/spec/filters/bugs/bigdecimal.rb +0 -1
  72. data/spec/filters/bugs/enumerator.rb +5 -0
  73. data/spec/filters/bugs/float.rb +3 -0
  74. data/spec/filters/bugs/kernel.rb +4 -9
  75. data/spec/filters/bugs/language.rb +0 -1
  76. data/spec/filters/bugs/marshal.rb +3 -0
  77. data/spec/filters/bugs/method.rb +1 -2
  78. data/spec/filters/bugs/module.rb +0 -6
  79. data/spec/filters/bugs/rational.rb +1 -0
  80. data/spec/filters/bugs/regexp.rb +0 -1
  81. data/spec/lib/compiler_spec.rb +2 -2
  82. data/spec/mspec-opal/runner.rb +1 -0
  83. data/spec/opal/core/array/zip_spec.rb +12 -0
  84. data/spec/opal/core/io/read_spec.rb +69 -0
  85. data/spec/opal/core/language_spec.rb +14 -0
  86. data/spec/opal/core/string/gsub_spec.rb +8 -0
  87. data/spec/opal/core/string/scan_spec.rb +8 -0
  88. data/stdlib/benchmark.rb +14 -0
  89. data/stdlib/buffer.rb +4 -0
  90. data/stdlib/nashorn/file.rb +2 -0
  91. data/stdlib/native.rb +63 -58
  92. data/stdlib/nodejs/argf.rb +110 -0
  93. data/stdlib/nodejs/env.rb +12 -0
  94. data/stdlib/nodejs/file.rb +10 -0
  95. data/stdlib/nodejs/kernel.rb +56 -0
  96. data/stdlib/nodejs.rb +1 -0
  97. data/stdlib/opal/platform.rb +2 -0
  98. data/stdlib/opal-platform.rb +5 -2
  99. data/stdlib/pathname.rb +4 -0
  100. data/stdlib/quickjs/io.rb +20 -0
  101. data/stdlib/quickjs/kernel.rb +3 -0
  102. data/stdlib/quickjs.rb +4 -0
  103. data/stdlib/securerandom.rb +2 -0
  104. data/tasks/linting-parse-eslint-results.js +1 -0
  105. data/tasks/linting.rake +0 -10
  106. data/tasks/performance.rake +2 -1
  107. data/tasks/testing.rake +1 -1
  108. metadata +41 -10
  109. data/lib/opal/cli_runners/chrome_cdp_interface.js +0 -30285
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf895e8ef63c69f90e6e099aa2f4c671649411893b980bdb03b55268da2e0a34
4
- data.tar.gz: 5fc847637cea4a857bcc78ad1a491d5c898fdc051d779644f39e282e6c2aba66
3
+ metadata.gz: 2b87866d518e2345b4aa120b4f8d457dad6f86ed9f365974161efad2e2f0dde9
4
+ data.tar.gz: a3dac2be866ce053470b56377131f7615f0ff6bc3dc7a1d567ce77a8efff5278
5
5
  SHA512:
6
- metadata.gz: 0eb66e6cb09d52075f7afd1ab8d10b67fdab302a503269f95b152440991b8d1f9bc3fc759e0265503350e6c4cd3c1453afca9d7d971bbdae46a367f15f5f8230
7
- data.tar.gz: e0ce987c98345a13101dc3d9311ce1bb41435777edf41ab14aac96cf5821c1e6076236de25216c443fa806567af6f1a32de2f8d7d9e1e67e4ba165547c938e95
6
+ metadata.gz: 161e91aa69fc166adf4719b56724251e97239de73dba172916a3de5c744e4d7166a33b0fdc97f9fb68079c0627815a5ae00aba0cbedb137b35a6fc34191979ac
7
+ data.tar.gz: ec37e385c55325552d2b7a82fc4c9ec4cd2a98aa3be966a6f9c193e483d0278f58ac8241eec65e12d9e965ea4eda17454430ae284352526ce408e7bc69729ad3
@@ -54,6 +54,7 @@ jobs:
54
54
  permissive: true
55
55
  fetchdepth: '0'
56
56
  command: bin/rake performance:compare
57
+ os: ryzen
57
58
 
58
59
  # Currently failing:
59
60
  # - ruby: truffleruby
@@ -66,7 +67,8 @@ jobs:
66
67
  - uses: actions/checkout@v2
67
68
  with:
68
69
  fetch-depth: ${{ fromJSON(matrix.combo.fetchdepth || '1') }}
69
- - uses: ruby/setup-ruby@v1
70
+ - if: ${{ matrix.combo.os != 'ryzen' }}
71
+ uses: ruby/setup-ruby@v1
70
72
  with:
71
73
  ruby-version: ${{ matrix.combo.ruby }}
72
74
  # NOTE: Bundler 2.2.0 fails to install libv8
data/CHANGELOG.md CHANGED
@@ -15,7 +15,145 @@ Changes are grouped as follows:
15
15
 
16
16
 
17
17
 
18
- ## [1.2.0](https://github.com/opal/opal/compare/v1.1.1...1.2.0) - 2021-07-28
18
+ ## [1.3.2](https://github.com/opal/opal/compare/v1.3.1...v1.3.2) - 2021-11-10
19
+
20
+
21
+ ### Fixed
22
+
23
+ - Update documentation ([#2350](https://github.com/opal/opal/pull/2350))
24
+ - Fix `IO#gets` getting an extra char under some circumstances ([#2349](https://github.com/opal/opal/pull/2349))
25
+ - Raise a `TypeError` instead of `UndefinedMethod` if not a string is passed to `__send__` ([#2346](https://github.com/opal/opal/pull/2346))
26
+ - Do not modify `$~` when calling `String#scan` from internal methods ([#2353](https://github.com/opal/opal/pull/2353))
27
+ - Stop interpreting falsey values as a missing constant in `Module#const_get` ([#2354](https://github.com/opal/opal/pull/2354))
28
+
29
+ <!--
30
+ ### Changed
31
+ ### Deprecated
32
+ ### Removed
33
+ ### Internal
34
+ -->
35
+
36
+
37
+
38
+
39
+ ## [1.3.1](https://github.com/opal/opal/compare/v1.3.0...v1.3.1) - 2021-11-03
40
+
41
+
42
+ ### Fixed
43
+
44
+ - Fix REPL if bundler environment isn't set ([#2338](https://github.com/opal/opal/pull/2338))
45
+ - Fix Chrome runner if bundler environment isn't set and make it work on other Unixes ([#2339](https://github.com/opal/opal/pull/2339))
46
+ - `Proc#binding` to return a binding if `Binding` is defined (#2341, #2340)
47
+ - `Array#zip` to correctly `yield` (#2342, #1611)
48
+ - `String#scan` to correctly `yield` (#2342, #1660)
49
+
50
+
51
+
52
+
53
+ ## [1.3.0](https://github.com/opal/opal/compare/v1.2.0...v1.3.0) - 2021-10-27
54
+
55
+
56
+ ### Added
57
+
58
+ - Add support for `retry` ([#2264](https://github.com/opal/opal/pull/2264))
59
+ - Modernize Exceptions ([#2264](https://github.com/opal/opal/pull/2264))
60
+ - Add `#cause`, `#backtrace_locations`, `#full_message` to `Exception`
61
+ - Normalize backtraces across platforms
62
+ - Add `Thread::Backtrace::Location`
63
+ - Output Exception#full_message on uncaught exceptions ([#2269](https://github.com/opal/opal/pull/2269))
64
+ - TracePoint `:class` support ([#2049](https://github.com/opal/opal/pull/2049))
65
+ - Implement the Flip-Flop operators ([#2261](https://github.com/opal/opal/pull/2261))
66
+ - Add `JS[]` to access properties on the global object ([#2259](https://github.com/opal/opal/pull/2259))
67
+ - Add `ENV.fetch` to the Nodejs implementation of `ENV` ([#2259](https://github.com/opal/opal/pull/2259))
68
+ - Opal::Cache, an optional compiler cache (enabled by default) (#2242, #2278, #2329)
69
+ - Alias for gvars, alias on main ([#2270](https://github.com/opal/opal/pull/2270))
70
+ - Support for GJS (GNOME's JavaScript runtime) runner ([#2280](https://github.com/opal/opal/pull/2280))
71
+ - Scope variables support for `eval()` ([#2256](https://github.com/opal/opal/pull/2256))
72
+ - Add support for `Kernel#binding` ([#2256](https://github.com/opal/opal/pull/2256))
73
+ - A (mostly) correct support for refinements ([#2256](https://github.com/opal/opal/pull/2256))
74
+ - Add support for ECMAScript modules with an `--esm` CLI option ([#2286](https://github.com/opal/opal/pull/2286))
75
+ - Implement `Regexp#names` and add named captures support ([#2272](https://github.com/opal/opal/pull/2272))
76
+ - REPL improvements: ([#2285](https://github.com/opal/opal/pull/2285))
77
+ - Colored output & history support
78
+ - `ls` to show available constants and variable
79
+ - Add `Method#===` as an alias to `Method#call`, works the same as `Proc#===` ([#2305](https://github.com/opal/opal/pull/2305))
80
+ - Add `IO#gets` and `IO#read_proc` along with other supporting methods ([#2309](https://github.com/opal/opal/pull/2309))
81
+ - Support `#gets` on most platforms, including browsers (via `prompt`)
82
+ - Move the REPL to a `--repl` CLI option of the main executable
83
+ - Completely refactor IO, now supporting methods like `#each_line` throughout the entire IO chain
84
+ - Add a runner for MiniRacer (as `miniracer`)
85
+ - Support Windows on the Chrome runner
86
+ - Support Windows on the REPL
87
+ - Platforms an IO implementations should either set `IO#read_proc` or overwrite `IO#sysread`
88
+ - [experimental] Add support for JavaScript async/await ([#2221](https://github.com/opal/opal/pull/2221))
89
+ - Enable the feature by adding a magic comment: `# await: true`
90
+ - The magic comment can be also used to mark specific method patterns to be awaited
91
+ (e.g. `# await: *_await, sleep` will make any method ending in `_await` or named `sleep` to be awaited)
92
+ - Add `Kernel#__await__` as a bridge to the `await` keyword (inspired by CoffeeScript await support)
93
+ - Require `opal/await` to get additional support
94
+ - Read more on the newly added documentation page
95
+ - Better interoperability between legacy Promise (v1) and native Promise (v2) ([#2221](https://github.com/opal/opal/pull/2221))
96
+ - Add `PromiseV1` as an alias to the original (legacy) Promise class
97
+ - Add `#to_v1` and `#to_v2` to both classes
98
+ - `Promise#to_n` will convert it to a native Promise (v2)
99
+ - Add `Opal::Config.esm` to enable/disable ES modules ([#2316](https://github.com/opal/opal/pull/2316))
100
+ - If Config.esm is enabled, SimpleServer does type="module"
101
+ - Add new rack-esm example
102
+ - Add a QuickJS (https://bellard.org/quickjs/) runner ([#2331](https://github.com/opal/opal/pull/2331))
103
+ - Add `IO#fileno`, `Method#curry`, `Buffer#to_s`, `Pathname.pwd` ([#2332](https://github.com/opal/opal/pull/2332))
104
+ - Add NodeJS support for `ARGF`, `ENV.{inspect,to_h,to_hash,merge}`, `File.{delete,unlink}`, `Kernel#system`, <code>Kernel#\`</code>, `Process::Status` ([#2332](https://github.com/opal/opal/pull/2332))
105
+ - Introduce `__dir__` support ([#2323](https://github.com/opal/opal/pull/2323))
106
+ - Full autoload support ([#2323](https://github.com/opal/opal/pull/2323))
107
+ - Now compatible with `opal-zeitwerk` and `isomorfeus`
108
+ - Allow toplevel autoloads
109
+ - Allow dynamic autoloads (e.g. can be hooked to fetch a URL upon autoload with a custom loader)
110
+ - Allow overwriting `require` (e.g. like rubygems does)
111
+ - Allow autoloading trees with `require_tree "./foo", autoload: true`
112
+ - Add Module#autoload?
113
+ - Autoload parts of the corelib ([#2323](https://github.com/opal/opal/pull/2323))
114
+
115
+ ### Fixed
116
+
117
+ - Fixed multiple line `Regexp` literal to not generate invalid syntax as JavaScript ([#1616](https://github.com/opal/opal/pull/1616))
118
+ - Fix `Kernel#{throw,catch}` along with `UncaughtThrowError` ([#2264](https://github.com/opal/opal/pull/2264))
119
+ - Update source-map-support to fix an off-by-one error ([#2264](https://github.com/opal/opal/pull/2264))
120
+ - Source map: lines should start from 1, not 0 ([#2273](https://github.com/opal/opal/pull/2273))
121
+ - Allow for multiple underscored args with the same name in strict mode ([#2292](https://github.com/opal/opal/pull/2292))
122
+ - Show instance variables in `Kernel#inspect` ([#2285](https://github.com/opal/opal/pull/2285))
123
+ - `0.digits` was returning an empty array in strict mode ([#2301](https://github.com/opal/opal/pull/2301))
124
+ - Non Integer numbers were responding to `#digits` ([#2301](https://github.com/opal/opal/pull/2301))
125
+ - Correctly delete hash members when dealing with boxed strings ([#2306](https://github.com/opal/opal/pull/2306))
126
+ - Escape string components in interpolated strings (`dstrs`) correctly ([#2308](https://github.com/opal/opal/pull/2308))
127
+ - Don't try to return the JS `debugger` statement, just return `nil` ([#2307](https://github.com/opal/opal/pull/2307))
128
+ - Retain the `-` while stringifying `-0.0` ([#2304](https://github.com/opal/opal/pull/2304))
129
+ - Fix super support for rest args and re-assignments with implicit arguments ([#2315](https://github.com/opal/opal/pull/2315))
130
+ - Fix calling `Regexp#last_match` when `$~` is nil ([#2328](https://github.com/opal/opal/pull/2328))
131
+ - Windows support for chrome runner ([#2324](https://github.com/opal/opal/pull/2324))
132
+ - Use correct node separator for NODE_PATH on Windows
133
+ - Pass dir and emulate exec a bit on Windows
134
+ - Use Gem.win_platform?, match supported platform to ruby, simplify run
135
+ - NodeJS: Drop the first `--` argument in `ARGV` ([#2332](https://github.com/opal/opal/pull/2332))
136
+ - Fix `Object#require` not pointing to `Kernel#require` ([#2323](https://github.com/opal/opal/pull/2323))
137
+
138
+ ### Changed
139
+
140
+ - Fast-track bad constant names passed to `Struct.new` ([#2259](https://github.com/opal/opal/pull/2259))
141
+ - Renamed internal `super` related helpers,
142
+ `find_super_dispatcher` is now `find_super`, `find_iter_super_dispatcher` is now `find_block_super` ([#2090](https://github.com/opal/opal/pull/2090))
143
+ - The `opal-repl` CLI now requires files to be passed with `--require` (or `-r`) instead of the bare filename ([#2309](https://github.com/opal/opal/pull/2309))
144
+ - `Process` is now a Module, not a Class - just like in MRI ([#2332](https://github.com/opal/opal/pull/2332))
145
+ - `s = StringIO.new("a"); s << "b"; s.string` now returns "b", like MRI, but Opal used to return "ab" ([#2309](https://github.com/opal/opal/pull/2309))
146
+
147
+ ### Internal
148
+
149
+ - Switch from jshint to ESLint ([#2289](https://github.com/opal/opal/pull/2289))
150
+ - Switch from UglifyJS to Terser ([#2318](https://github.com/opal/opal/pull/2318))
151
+ - [CI] Performance regression check (#2276, #2282)
152
+
153
+
154
+
155
+
156
+ ## [1.2.0](https://github.com/opal/opal/compare/v1.1.1...v1.2.0) - 2021-07-28
19
157
 
20
158
 
21
159
  ### Added
data/UNRELEASED.md CHANGED
@@ -1,76 +1,7 @@
1
- ### Added
2
-
3
- - Add support for `retry` (#2264)
4
- - Modernize Exceptions (#2264)
5
- - Add `#cause`, `#backtrace_locations`, `#full_message` to `Exception`
6
- - Normalize backtraces across platforms
7
- - Add `Thread::Backtrace::Location`
8
- - Output Exception#full_message on uncaught exceptions (#2269)
9
- - TracePoint `:class` support (#2049)
10
- - Implement the Flip-Flop operators (#2261)
11
- - Add `JS[]` to access properties on the global object (#2259)
12
- - Add `ENV.fetch` to the Nodejs implementation of `ENV` (#2259)
13
- - Opal::Cache, an optional compiler cache (enabled by default) (#2242, #2278)
14
- - Alias for gvars, alias on main (#2270)
15
- - Support for GJS (GNOME's JavaScript runtime) runner (#2280)
16
- - Scope variables support for `eval()` (#2256)
17
- - Add support for `Kernel#binding` (#2256)
18
- - A (mostly) correct support for refinements (#2256)
19
- - [CI] Performance regression check (#2276, #2282)
20
- - Add support for ECMAScript modules with an `--esm` CLI option (#2286)
21
- - Implement `Regexp#names` and add named captures support (#2272)
22
- - REPL improvements: (#2285)
23
- - Colored output & history support
24
- - `ls` to show available constants and variable
25
- - Add `Method#===` as an alias to `Method#call`, works the same as `Proc#===` (#2305)
26
- - Add `IO#gets` and `IO#read_proc` along with other supporting methods (#2309)
27
- - Support `#gets` on most platforms, including browsers (via `prompt`)
28
- - Move the REPL to a `--repl` CLI option of the main executable
29
- - Completely refactor IO, now supporting
30
- - Add a runner for MiniRacer (as `miniracer`)
31
- - Support Windows on the Chrome runner
32
- - Support Windows on the REPL
33
- - Platforms an IO implementations should either set `IO#read_proc` or overwrite `IO#sysread`
34
- - [experimental] Add support for JavaScript async/await (#2221)
35
- - Enable the feature by adding a magic comment: `# await: true`
36
- - The magic comment can be also used to mark specific method patterns to be awaited
37
- (e.g. `# await: *_await, sleep` will make any method ending in `_await` or named `sleep` to be awaited)
38
- - Add `Kernel#__await__` as a bridge to the `await` keyword (inspired by CoffeeScript await support)
39
- - Require `opal/await` to get additional support
40
- - Read more on the newly added documentation page
41
- - Better interoperability between legacy Promise (v1) and native Promise (v2) (#2221)
42
- - Add `PromiseV1` as an alias to the original (legacy) Promise class
43
- - Add `#to_v1` and `#to_v2` to both classes
44
- - `Promise#to_n` will convert it to a native Promise (v2)
45
-
1
+ <!--
46
2
  ### Fixed
47
-
48
- - Fixed multiple line `Regexp` literal to not generate invalid syntax as JavaScript (#1616)
49
- - Fix `Kernel#{try,catch}` along with `UncaughtThrowError` (#2264)
50
- - Update source-map-support to fix an off-by-one error (#2264)
51
- - Source map: lines should start from 1, not 0 (#2273)
52
- - Allow for multiple underscored args with the same name in strict mode (#2292)
53
- - Show instance variables in `Kernel#inspect` (#2285)
54
- - `0.digits` was returning an empty array in strict mode (#2301)
55
- - Non Integer numbers were responding to `#digits` (#2301)
56
- - Correctly delete hash members when dealing with boxed strings (#2306)
57
- - Escape string components in interpolated strings (`dstrs`) correctly (#2308)
58
- - Don't try to return the JS `debugger` statement, just return `nil` (#2307)
59
- - Retain the `-` while stringifying `-0.0` (#2304)
60
- - Fix super support for rest args and re-assignments with implicit arguments (#2315)
61
-
62
3
  ### Changed
63
-
64
- - Fast-track bad constant names passed to `Struct.new` (#2259)
65
- - Renamed internal `super` related helpers,
66
- `find_super_dispatcher` is now `find_super`, `find_iter_super_dispatcher` is now `find_block_super` (#2090)
67
- - The `opal-repl` CLI now requires files to be passed with `--require` (or `-r`) instead of the bare filename (#2309)
68
-
69
-
70
4
  ### Deprecated
71
-
72
5
  ### Removed
73
-
74
6
  ### Internal
75
-
76
- - Switch from jshint to ESLint (#2289)
7
+ -->
@@ -30,8 +30,8 @@ to convert values to opal specific values.
30
30
 
31
31
  NOTE: Because `true` and `false` compile to their native
32
32
  javascript equivalents, they must share the same class: `Boolean`.
33
- For this reason, they do not belong to their respective `TrueClass`
34
- and `FalseClass` classes from ruby.
33
+ Thru some level of hackery, we make them pseudo-members of the appropriate
34
+ `TrueClass` and `FalseClass`.
35
35
 
36
36
  #### Strings & Symbols
37
37
 
@@ -55,11 +55,11 @@ class. Symbols and Strings can therefore be used interchangeably.
55
55
 
56
56
  #### Numbers
57
57
 
58
- In Opal there is a single class for numbers; `Numeric`. To keep Opal
58
+ In Opal there is a single class for numbers; `Number`. To keep Opal
59
59
  as performant as possible, Ruby numbers are mapped to native numbers.
60
60
  This has the side effect that all numbers must be of the same class.
61
- Most relevant methods from `Integer`, `Float` and `Numeric` are
62
- implemented on this class.
61
+ Most relevant methods from `Integer` and `Float` are implemented on
62
+ this class.
63
63
 
64
64
  ```ruby
65
65
  42 # => 42
@@ -104,7 +104,7 @@ else is a truthy value including `""`, `0` and `[]`. This differs from
104
104
  JavaScript as these values are also treated as false.
105
105
 
106
106
  For this reason, most truthy tests must check if values are `false` or
107
- `nil`.
107
+ `nil` (we also check for `null` and `undefined`).
108
108
 
109
109
  Taking the following test:
110
110
 
@@ -204,16 +204,16 @@ obvious what went wrong.
204
204
 
205
205
  As Opal just generates JavaScript, it is useful to use a native
206
206
  debugger to work through JavaScript code. To use a debugger, simply
207
- add an x-string similar to the following at the place you wish to
208
- debug:
207
+ add a `debugger` statement:
209
208
 
210
209
  ```ruby
211
210
  # .. code
212
- `debugger`
211
+ debugger
213
212
  # .. more code
214
213
  ```
215
- The x-strings just pass the debugger statement straight through to the
216
- JavaScript output.
214
+
215
+ The `debugger` statement is compiled to become a JavaScript `debugger`
216
+ statement. This statement breaks the code if you have your Inspector open.
217
217
 
218
218
  NOTE: All local variables and method/block arguments also keep their Ruby
219
219
  names except in the rare cases when the name is reserved in JavaScript.
@@ -246,7 +246,7 @@ in the browser.
246
246
  }
247
247
 
248
248
  # => opal version is:
249
- # => 0.6.0
249
+ # => 1.3.1
250
250
  ```
251
251
 
252
252
  Even interpolations are supported, as seen here.
@@ -280,6 +280,9 @@ require 'native'
280
280
  win = Native(`window`) # equivalent to Native::Object.new(`window`)
281
281
  ```
282
282
 
283
+ To access a Native-wrapped global JavaScript object, we can also use `$$`, after
284
+ we have the `native` module required.
285
+
283
286
  Now what if we want to access one of its properties?
284
287
 
285
288
  ```ruby
@@ -514,10 +517,10 @@ Opal.BAZ; // => 789
514
517
  To reach nested constants the safest way is to call `#const_get` on `Object`:
515
518
 
516
519
  ```javascript
517
- Opal.Object.$$const_get('Bar::BAR'); // => 123
518
- Opal.Object.$$const_get('Foo::BAR'); // => 123
519
- Opal.Object.$$const_get('Foo::FOO'); // => 456
520
- Opal.Object.$$const_get('BAZ'); // => 789
520
+ Opal.Object.$const_get('Bar::BAR'); // => 123
521
+ Opal.Object.$const_get('Foo::BAR'); // => 123
522
+ Opal.Object.$const_get('Foo::FOO'); // => 456
523
+ Opal.Object.$const_get('BAZ'); // => 789
521
524
  ```
522
525
 
523
526
  Constants can also be navigated using the `$$` property, although this is limited to constants defined directly under the current object:
@@ -528,6 +531,14 @@ Opal.Foo.$$.FOO // => 456
528
531
  Opal.Foo.$$.BAR // => undefined
529
532
  ```
530
533
 
534
+ A later feature also allows you to skip the `$$` property:
535
+
536
+ ```javascript
537
+ Opal.Bar.BAR // => 123
538
+ Opal.Foo.FOO // => 456
539
+ Opal.Foo.BAR // => undefined
540
+ ```
541
+
531
542
 
532
543
  ### Calling methods
533
544
 
data/docs/faq.md CHANGED
@@ -10,7 +10,7 @@ We run opal against the [ruby spec](https://github.com/ruby/spec) as our primary
10
10
 
11
11
  ### What version of ruby does Opal target?
12
12
 
13
- We are running tests under ruby 2.0.0 conditions, but are mostly compatible with 1.9 level features.
13
+ We are running tests under ruby 3.0.0 conditions, but are mostly compatible with 2.6 level features.
14
14
 
15
15
  ### Why doesn't Opal support mutable strings?
16
16
 
@@ -3,7 +3,6 @@
3
3
  ## Requirements
4
4
 
5
5
  First of all, make sure that you have Chrome at least 59.0 installed.
6
- Also for now it's supported only on Mac and Linux. (version 60 may get support on Windows)
7
6
 
8
7
  ## Using the runner
9
8
 
@@ -22,11 +21,9 @@ The runner also listens for any exceptions and prints formatted stracktraces bac
22
21
  raising_method
23
22
  "
24
23
 
25
- RuntimeError : test error
26
- at $$raise (file:///tmp/chrome-opal.js:4996:6)
27
- at $$raising_method (file:///tmp/chrome-opal.js:21144:16)
28
- at (file:///tmp/chrome-opal.js:21146:14)
29
- at (file:///tmp/chrome-opal.js:21147:2)
24
+ RuntimeError: test error
25
+ from <internal:corelib/…>:2693:7:in `<main>'
26
+ from -e:1:1:in `undefined'
30
27
 
31
28
  ## Using exit codes
32
29
 
@@ -36,10 +33,9 @@ By default headless chrome runner explicitly sets exit code to 1 when there was
36
33
  0
37
34
 
38
35
  $ opal -Rchrome -e "raise 'error'"; echo $?
39
- RuntimeError : error
40
- at $$raise (file:///tmp/chrome-opal.js:4996:6)
41
- at (file:///tmp/chrome-opal.js:21139:14)
42
- at (file:///tmp/chrome-opal.js:21140:2)
36
+ RuntimeError: error
37
+ from <internal:corelib/kerne…>:2693:7:in `<main>'
38
+ from -e:1:1:in `undefined'
43
39
  1
44
40
 
45
41
  You can change final exit code by using `Kernel#exit`, but make sure to require `opal/platform` in your code.
@@ -69,20 +65,12 @@ or runs the server on its own. It detects your platform and uses a default path
69
65
  (`Opal::CliRunners::Chrome#chrome_executable`) but you can override it by specifying `GOOGLE_CHROME_BINARY` environment
70
66
  variable.
71
67
 
72
- When the server is up and running it passes compiled js code to `node lib/opal/cli_runners/chrome.js`
68
+ When the server is up and running it passes compiled js code to `lib/opal/cli_runners/chrome_cdp_interface.rb`
73
69
  as a plain input using stdin (basically, it's a second part of the runner).
74
- `chrome.js` is a node js script that does the main job. It runs any provided code on the running chrome server,
70
+ `chrome_cdp_interface.rb` is a node js + Opal script that does the main job. It runs any provided code on the running chrome server,
75
71
  catches errors and forwards console messages.
76
72
 
77
73
 
78
- Moreover, you can actually call any js using headless chrome by running
79
-
80
- $ echo "console.log('Hello, Opal')" | node lib/opal/cli_runners/chrome.js
81
-
82
- NOTE: to run it you need to have a chrome server running on `localhost:9222` (usually `chrome.rb` does it for you)
83
-
84
- $ chrome --disable-gpu --headless --remote-debugging-port=9222
85
-
86
74
  ## Using a remote chrome server
87
75
 
88
76
  If you want to change a default chrome port or your chrome server is running on a different host:port
@@ -99,7 +87,9 @@ NOTE: `CHROME_HOST` requires a chrome server to be started. You can't start remo
99
87
 
100
88
  If you need to pass additional CLI options to the Chrome executable you can do so by setting the `CHROME_OPTS` environment variable:
101
89
 
102
- $ CHROME_OPS="--window-size=412,732" opal -Rchrome -e "puts 42"
90
+ $ CHROME_OPTS="--window-size=412,732" opal -Rchrome -e "puts 42"
103
91
  42
104
92
 
93
+ Docker users may need `CHROME_OPTS="--no-sandbox"` due to the user namespaces limitations.
94
+
105
95
  _For a list of additional options see https://developers.google.com/web/updates/2017/04/headless-chrome_
data/docs/jquery.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # JQuery
2
2
 
3
- `opal-jquery` offers a nicer ruby-like syntax for JQuery (and Zepto). It is
4
- useful for projects which cannot use `opal-browser` due to a reliance on jquery
5
- for plugins or other libraries.
3
+ `opal-jquery` offers a nicer ruby-like syntax for JQuery. It is useful for projects which cannot use `opal-browser` due to a reliance on jquery for plugins or other libraries.
6
4
 
7
5
  ```ruby
8
6
  foos = Element.find('.foo')
@@ -91,9 +89,6 @@ bridged instances of jquery objects. Just like ruby arrays are just javascript
91
89
  arrays, `Element` instances are just jquery objects. This makes interaction
92
90
  with jquery plugins much easier.
93
91
 
94
- Also, `Element` will try to bridge with Zepto if it cannot find jQuery loaded,
95
- making it ideal for mobile applications as well.
96
-
97
92
  ### Interacting with the DOM
98
93
 
99
94
  #### Finding Elements
data/docs/opal_parser.md CHANGED
@@ -8,12 +8,14 @@ Opal is able to compile its – pure Ruby – compiler to JavaScript (how cool i
8
8
  require 'opal-parser'
9
9
  ```
10
10
 
11
+ _Note: For the best performance and application load times, it is strongly recommended to design your application so that it won't need the parser. A lot of methods described in this document are more fun hacks than robust solutions. But if you really want or need to use them, for example so that you can implement a Ruby REPL or an interactive Ruby playground - we have you covered, but for all other cases, we strongly discourage you to take an advice from this guide._
12
+
11
13
 
12
14
  ## Features
13
15
 
14
16
  ### `Kernel#eval`
15
17
 
16
- `opal-parser` provides a partial implementation of `Kernel#eval` that only support the first parameter (String) and refuse any passed `binding`, `lineno` or `filename`.
18
+ `opal-parser` provides a partial implementation of `Kernel#eval`.
17
19
 
18
20
  Example:
19
21
 
data/docs/promises.md CHANGED
@@ -8,6 +8,8 @@ It can be required inside any Opal applicaton:
8
8
  require 'promise'
9
9
  ```
10
10
 
11
+ _Please also take a look at the Asynchronous code guide - we are in the process of modernizing the Promises, along with supporting async/await_
12
+
11
13
  ## Usage
12
14
 
13
15
  This example shows how to use a `HTTP` request from `opal-jquery` from a callback style, into a promise style handler.
data/docs/releasing.md CHANGED
@@ -14,5 +14,24 @@ _This guide is a work-in-progress._
14
14
 
15
15
  ## The commit
16
16
 
17
- - Commit the updated changelog along with the version bump using this commmit message:
17
+ - Commit the updated changelog along with the version bump using this commit message:
18
18
  "Release v1.2.3"
19
+ - Push the commit and run `bin/rake release` to release the new version to Rubygems
20
+ - Go to GitHub releases and create a new release from the latest tag pasting the contents of UNRELEASED.md
21
+ - Empty UNRELEASED.md and run `bin/rake changelog`
22
+ - Push the updated changelog
23
+
24
+ ## Opal docs
25
+
26
+ - Open `opal-docs` and run `bin/build v1.2.3`
27
+ - Then run `bin/deploy`
28
+
29
+ ## Opal site
30
+
31
+ - Open `opal.github.io` and update the opal version in the `Gemfile`
32
+ - run `bin/build`
33
+ - `git push` the latest changes
34
+
35
+ ## Opal CDN
36
+
37
+ - Run `bin/release v1.2.3`
@@ -23,7 +23,6 @@ class App < Roda
23
23
  plugin :sprockets, precompile: %w(application.js),
24
24
  prefix: %w(app/),
25
25
  opal: true,
26
- debug: ENV['RACK_ENV'] != 'production'
27
26
  plugin :public
28
27
 
29
28
  route do |r|
data/docs/source_maps.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # Source maps
2
2
 
3
- Source maps are available (on current stable release, v0.6.x) even without explicit support from Sprockets in a sort of hackish way.
4
-
5
- _As such even if they generally work fine there are some limitations and edge case issues._
6
-
7
- NOTE: Currently on `master` branch sourcemaps are work-in-progress and probably will integrate with the upcoming Sprockets 4 that has integrated support for them.
3
+ Source maps are available on most environments we support.
8
4
 
9
5
  #### Processor `source_map_enabled` flag
10
6
  To enable sourcemaps in the Sprockets processor you need to turn on the relative flag:
@@ -16,8 +12,7 @@ Opal::Config.source_map_enabled = true # default
16
12
 
17
13
  #### Sprockets debug mode
18
14
 
19
- The sourcemaps only work with Sprockets in debug mode because they are generated just for single files.
20
-
15
+ The source maps only work with Sprockets in debug mode - this is a limitation of Sprockets.
21
16
 
22
17
  ## Enable source maps
23
18
 
@@ -37,13 +32,17 @@ config.assets.debug = true
37
32
 
38
33
  ### Sinatra
39
34
 
40
- You can add `Opal::Server` as in the official example: [sinatra/config.ru](https://github.com/opal/opal/blob/0-6-stable/examples/sinatra/config.ru).
35
+ You can add `Opal::Server` as in the official example: [sinatra/config.ru](https://github.com/opal/opal/blob/master/examples/sinatra/config.ru).
41
36
 
42
37
  ### Opal::Server
43
38
 
44
- `Opal::Server` implements sourcemaps and can be used alone or with `Rack::Cascade` in conjunction with other apps.
39
+ `Opal::Server` (which is based on Sprockets) implements sourcemaps and can be used alone or with `Rack::Cascade` in conjunction with other apps.
40
+
41
+ ### Opal::SimpleServer
42
+
43
+ Like `Opal::Server`, `Opal::SimpleServer` (which isn't based on Sprockets) implements sourcemaps properly.
45
44
 
46
- ### Opal::Environment
45
+ ### Opal::Builder
47
46
 
48
- `Opal::Environment` is a bit lower level and doesn't support source maps by itself.
47
+ `Opal::Builder` is a bit lower level and doesn't support source maps by itself. It requires you to call in a specific method to generate them yourself.
49
48
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  `opal` makes it easy to build static opal applications. Opal uses internal load
4
4
  paths to make it easy to handle resolving requirements during building. `opal`
5
- forms the basis of rails support, so anything you can do there, you can do
5
+ forms the basis of Rails support, so anything you can do there, you can do
6
6
  standalone as well.
7
7
 
8
8
  ## Overview
@@ -11,7 +11,7 @@ First, install `opal` adding them to a `Gemfile`:
11
11
 
12
12
  ```ruby
13
13
  # Gemfile
14
- gem "opal", "~> 0.7.0"
14
+ gem "opal"
15
15
  ```
16
16
 
17
17
  Next, we want to add our main app code. Keep all opal code inside `app/`
@@ -6,6 +6,10 @@ Opal does not support some language/runtime features of ruby. These are document
6
6
 
7
7
  For performance and ease of runtime features, all strings in Opal are immutable, i.e. `#<<`, `#gsub!`, etc. do not exist. Also, symbols are just strings. There is no class, runtime or feature difference between Symbols and Strings. Their syntaxes can be used interchangeably.
8
8
 
9
+ #### Regexp differences ####
10
+
11
+ We are using JavaScript regular expressions. While we do translate a few of Ruby specific instructions like `\A` or `\z`, there are a lot of incompatibilities that you should be aware of - for example `$` and `^` don't match newlines like they do in Ruby. Support for features like named matches or lookahead/lookbehind is dependent on the JavaScript environment support for those. To support everything, we would need to [compile in the entire Ruby's regular expression engine](https://opalrb.com/blog/2021/06/26/webassembly-and-advanced-regexp-with-opal/) which is unfeasible at the current time.
12
+
9
13
  #### Integer / Float difference ####
10
14
 
11
15
  In Opal, both integers and floats belong to same class `Number` (using JavaScript native numbers). So `1 / 4` is `0.25` (not `0`) and `4.0 / 2` is `2` (not `2.0`).
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rack'
4
4
  gem 'opal', :path => '../../'
5
+ gem 'puma'
@@ -1,24 +1,28 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- opal (1.0.0)
4
+ opal (1.3.0.dev)
5
5
  ast (>= 2.3.0)
6
- parser (~> 2.6)
6
+ parser (~> 3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.0)
12
- parser (2.6.4.1)
13
- ast (~> 2.4.0)
14
- rack (2.0.7)
11
+ ast (2.4.2)
12
+ nio4r (2.5.8)
13
+ parser (3.0.2.0)
14
+ ast (~> 2.4.1)
15
+ puma (5.5.0)
16
+ nio4r (~> 2.0)
17
+ rack (2.2.3)
15
18
 
16
19
  PLATFORMS
17
20
  ruby
18
21
 
19
22
  DEPENDENCIES
20
23
  opal!
24
+ puma
21
25
  rack
22
26
 
23
27
  BUNDLED WITH
24
- 1.17.3
28
+ 2.1.4
@@ -0,0 +1 @@
1
+ tmp
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack'
4
+ gem 'opal', :path => '../../'
5
+ gem 'puma'