opal 1.7.2 → 1.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3221ae5854f26b0d0722ddf2689773633648086a616add372e8fdd617b31d7c0
4
- data.tar.gz: b6b4a65b1905bddb6c1fd2310b13c03600ef4bb8fb416fff54e5499bfae8616c
3
+ metadata.gz: 1e1885b32b1546863d767adcebce41e10b5b10872bdad28d197b2a193fb29e54
4
+ data.tar.gz: 24a27f9aa47ddd775a36b6bb2bf6fcf32ab51c80ff6ad5bf9c5baf685da83576
5
5
  SHA512:
6
- metadata.gz: 5a009bcca000c8fef3d73cda99453023b2860615e4c4c7176e328448cd12d5f26bbf6d2809ca040f064e64af7b04ddb94857b35ac36486a0c7996be28a63230b
7
- data.tar.gz: d9154247ad9e90fbc770d647524db30fc8132b3fb77f8c5115abb67a3507fe66c0f7306a2965f1aca11bc790b2f6b7308d7db7bda7e9c3443b54bce42a957bab
6
+ metadata.gz: d4c34638370c988ad9adad7eab68f643b399cdacaa5e88dd4f11db224efbcdf7a7c7278afdb5586ef65b27bb7918c836641ac18dfc4db1b968c2aa73358fb192
7
+ data.tar.gz: 3a3fce3444d3f14b8aaee302f6ec0cf67991f80dac46702a21bdbf1a51534bd114584a7a94d7d03abea6d333a527db249244cdc1fd7b94b09abe11716259788f
data/.eslintrc.js CHANGED
@@ -33,5 +33,6 @@ module.exports = {
33
33
  "Reflect": "readonly",
34
34
  "Uint8Array": "readonly",
35
35
  "WeakRef": "readonly",
36
+ "Map": "readonly",
36
37
  }
37
38
  };
data/CHANGELOG.md CHANGED
@@ -16,7 +16,7 @@ Changes are grouped as follows:
16
16
 
17
17
 
18
18
 
19
- ## [1.7.2](https://github.com/opal/opal/compare/v1.7.1...v1.7.2) - 2023-01-20
19
+ ## [1.7.4](https://github.com/opal/opal/compare/v1.7.3...v1.7.4) - 2023-09-14
20
20
 
21
21
 
22
22
  <!--
@@ -26,9 +26,37 @@ Changes are grouped as follows:
26
26
  ### Removed
27
27
  ### Deprecated
28
28
  ### Performance
29
- ### Fixed
30
29
  -->
31
30
 
31
+ ### Fixed
32
+
33
+ - Use a Map instead of a POJO for the jsid_cache ([#2584](https://github.com/opal/opal/pull/2584))
34
+ - Lowercase response headers in `SimpleServer` for rack 3.0 compatibility ([#2578](https://github.com/opal/opal/pull/2578))
35
+ - Fix `switch` with Object-wrapped values ([#2542](https://github.com/opal/opal/pull/2542))
36
+ - Regexp.escape: Cast to String or drop exception ([#2552](https://github.com/opal/opal/pull/2552))
37
+ - Chrome runner fix: support code that contains `</script>` ([#2581](https://github.com/opal/opal/pull/2581))
38
+
39
+
40
+
41
+
42
+ ## [1.7.3](https://github.com/opal/opal/compare/v1.7.2...v1.7.3) - 2023-03-23
43
+
44
+
45
+ ### Fixed
46
+
47
+ - Disallow to define a singleton class for Number ([#2521](https://github.com/opal/opal/pull/2521))
48
+ - Fix eval with parser gem v3.2.1 ([#2526](https://github.com/opal/opal/pull/2526))
49
+ - Fix certain encoding issues when using Prefork ([#2527](https://github.com/opal/opal/pull/2527))
50
+ - Fix Chrome CDP interface connection ([#2528](https://github.com/opal/opal/pull/2528))
51
+ - Fix for Opal::Cache::FileCache.dir_writable? ([#2529](https://github.com/opal/opal/pull/2529))
52
+ - Fix Array#sample randomness ([#2530](https://github.com/opal/opal/pull/2530))
53
+
54
+
55
+
56
+
57
+ ## [1.7.2](https://github.com/opal/opal/compare/v1.7.1...v1.7.2) - 2023-01-20
58
+
59
+
32
60
  ### Fixed
33
61
 
34
62
  - Fix the `--debug-source-map` CLI option ([#2520](https://github.com/opal/opal/pull/2520))
data/docs/index.md CHANGED
@@ -8,7 +8,7 @@ The guides for earlier releases are [available here](/docs).
8
8
 
9
9
  ## Start here
10
10
 
11
- #### [Getting Started with Opal](etting_started.html)
11
+ #### [Getting Started with Opal](getting_started.html)
12
12
 
13
13
  Everything you need to know to install Opal and create your first application.
14
14
 
@@ -131,8 +131,8 @@ module Opal
131
131
 
132
132
  class Fork
133
133
  def initialize(forkset)
134
- @parent_read, @child_write = IO.pipe
135
- @child_read, @parent_write = IO.pipe
134
+ @parent_read, @child_write = IO.pipe(binmode: true)
135
+ @child_read, @parent_write = IO.pipe(binmode: true)
136
136
  @forkset = forkset
137
137
  @in_fork = false
138
138
 
@@ -78,19 +78,16 @@ module Opal
78
78
  nil
79
79
  end
80
80
 
81
- # This complex piece of code tries to check if we can robustly mkdir_p a directory.
81
+ # Check if we can robustly mkdir_p a directory.
82
82
  def self.dir_writable?(*paths)
83
- dir = nil
84
- paths = paths.reduce([]) do |a, b|
85
- [*a, dir = a.last ? File.expand_path(b, a.last) : b]
86
- end
83
+ return false unless File.exist?(paths.first)
87
84
 
88
- File.exist?(paths.first) &&
89
- paths.reverse.all? do |i|
90
- !File.exist?(i) || (File.directory?(i) && File.writable?(i))
91
- end
85
+ until paths.empty?
86
+ dir = File.expand_path(paths.shift, dir)
87
+ ok = File.directory?(dir) && File.writable?(dir) if File.exist?(dir)
88
+ end
92
89
 
93
- dir
90
+ dir if ok
94
91
  end
95
92
 
96
93
  def self.find_dir
@@ -70,6 +70,10 @@ module Opal
70
70
  ext = builder.output_extension
71
71
  module_type = ' type="module"' if builder.esm?
72
72
 
73
+ # Some maps may contain `</script>` fragment (eg. in strings) which would close our
74
+ # `<script>` tag prematurely. For this case, we need to escape the `</script>` tag.
75
+ map_json = map.to_json.gsub(/(<\/scr)(ipt>)/i, '\1"+"\2')
76
+
73
77
  # Chrome can't handle huge data passed to `addScriptToEvaluateOnLoad`
74
78
  # https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/U5qyeX_ydBo
75
79
  # The only way is to create temporary files and pass them to chrome.
@@ -86,7 +90,7 @@ module Opal
86
90
  sourceMapSupport.install({
87
91
  retrieveSourceMap: function(path) {
88
92
  return path.endsWith('/index.#{ext}') ? {
89
- url: './index.map', map: #{map.to_json}
93
+ url: './index.map', map: #{map_json}
90
94
  } : null;
91
95
  }
92
96
  });
@@ -121,14 +121,16 @@ var server = http.createServer(function(req, res) {
121
121
 
122
122
  // actual CDP code
123
123
 
124
- CDP.List(options, function(err, targets) {
124
+ CDP.List(options, async function(err, targets) {
125
125
  // default CDP port is 9222, Firefox runner is at 9333
126
126
  // Lets collect clients for
127
127
  // Chrome CDP starting at 9273 ...
128
128
  // Firefox CDP starting 9334 ...
129
129
  port_offset = targets ? targets.length + 51 : 51; // default CDP port is 9222, Node CDP port 9229, Firefox is at 9333
130
130
 
131
- return CDP(options, function(browser_client) {
131
+ const {webSocketDebuggerUrl} = await CDP.Version(options);
132
+
133
+ return await CDP({target: webSocketDebuggerUrl}, function(browser_client) {
132
134
 
133
135
  server.listen({ port: port_offset + options.port, host: options.host });
134
136
 
@@ -94,10 +94,12 @@ var server = http.createServer(function(req, res) {
94
94
 
95
95
  // actual CDP code
96
96
 
97
- CDP.List(options, function(err, targets) {
97
+ CDP.List(options, async function(err, targets) {
98
98
  offset = targets ? targets.length + 1 : 1;
99
99
 
100
- return CDP(options, function(browser_client) {
100
+ const {webSocketDebuggerUrl} = await CDP.Version(options);
101
+
102
+ return await CDP({target: webSocketDebuggerUrl}, function(browser_client) {
101
103
 
102
104
  server.listen({port: offset + options.port, host: options.host });
103
105
 
data/lib/opal/nodes/if.rb CHANGED
@@ -349,7 +349,7 @@ module Opal
349
349
  @switch_additional_rules = sexp.meta[:switch_additional_rules]
350
350
  compile_switch_case(sexp.meta[:switch_test])
351
351
  else
352
- line "switch (", expr(@switch_first_test), ") {"
352
+ line "switch (", expr(@switch_first_test), ".valueOf()) {"
353
353
  indent do
354
354
  compile_switch_case(@switch_test)
355
355
  end
@@ -13,6 +13,12 @@ if RUBY_ENGINE == 'opal'
13
13
  else
14
14
  @source_pts = nil
15
15
  end
16
+
17
+ # Since parser v3.2.1 Parser::Lexer has @strings
18
+ if @strings
19
+ @strings.source_buffer = @source_buffer
20
+ @strings.source_pts = @source_pts
21
+ end
16
22
  end
17
23
  end
18
24
 
@@ -51,7 +51,7 @@ class Opal::SimpleServer
51
51
  asset = fetch_asset(path)
52
52
  [
53
53
  200,
54
- { 'Content-Type' => 'application/javascript' },
54
+ { 'content-type' => 'application/javascript' },
55
55
  [asset[:data], "\n", asset[:map].to_data_uri_comment],
56
56
  ]
57
57
  end
@@ -99,6 +99,6 @@ class Opal::SimpleServer
99
99
  </html>
100
100
  HTML
101
101
  end
102
- [200, { 'Content-Type' => 'text/html' }, [html]]
102
+ [200, { 'content-type' => 'text/html' }, [html]]
103
103
  end
104
104
  end
data/lib/opal/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module Opal
4
4
  # WHEN RELEASING:
5
5
  # Remember to update RUBY_ENGINE_VERSION in opal/corelib/constants.rb too!
6
- VERSION = '1.7.2'
6
+ VERSION = '1.7.4'
7
7
  end
@@ -1927,9 +1927,9 @@ class ::Array < `Array`
1927
1927
  break;
1928
1928
  case 2:
1929
1929
  i = #{rng.rand(`self.length`)};
1930
- j = #{rng.rand(`self.length`)};
1931
- if (i === j) {
1932
- j = i === 0 ? i + 1 : i - 1;
1930
+ j = #{rng.rand(`self.length - 1`)};
1931
+ if (i <= j) {
1932
+ j++;
1933
1933
  }
1934
1934
  return [self[i], self[j]];
1935
1935
  break;
@@ -1981,7 +1981,7 @@ class ::Array < `Array`
1981
1981
  result = self.slice();
1982
1982
 
1983
1983
  for (var c = 0; c < count; c++) {
1984
- targetIndex = #{rng.rand(`self.length`)};
1984
+ targetIndex = #{rng.rand(`self.length - c`)} + c;
1985
1985
  oldValue = result[c];
1986
1986
  result[c] = result[targetIndex];
1987
1987
  result[targetIndex] = oldValue;
@@ -1,8 +1,8 @@
1
1
  ::RUBY_PLATFORM = 'opal'
2
2
  ::RUBY_ENGINE = 'opal'
3
3
  ::RUBY_VERSION = '3.2.0'
4
- ::RUBY_ENGINE_VERSION = '1.7.2'
5
- ::RUBY_RELEASE_DATE = '2023-01-20'
4
+ ::RUBY_ENGINE_VERSION = '1.7.4'
5
+ ::RUBY_RELEASE_DATE = '2023-09-14'
6
6
  ::RUBY_PATCHLEVEL = 0
7
7
  ::RUBY_REVISION = '0'
8
8
  ::RUBY_COPYRIGHT = 'opal - Copyright (C) 2011-2023 Adam Beynon and the Opal contributors'
@@ -17,7 +17,10 @@ class ::Regexp < `RegExp`
17
17
  end
18
18
 
19
19
  def escape(string)
20
- `Opal.escape_regexp(string)`
20
+ %x{
21
+ string = $coerce_to(string, #{::String}, 'to_str');
22
+ return Opal.escape_regexp(string);
23
+ }
21
24
  end
22
25
 
23
26
  def last_match(n = nil)
@@ -824,6 +824,9 @@
824
824
  // @param object [Object] the ruby object
825
825
  // @return [Class] the singleton class for object
826
826
  Opal.get_singleton_class = function(object) {
827
+ if (object.$$is_number) {
828
+ $raise(Opal.TypeError, "can't define singleton");
829
+ }
827
830
  if (object.$$meta) {
828
831
  return object.$$meta;
829
832
  }
@@ -1860,9 +1863,14 @@
1860
1863
  }
1861
1864
 
1862
1865
  // Optimization for a costly operation of prepending '$' to method names
1863
- var jsid_cache = {}
1866
+ var jsid_cache = new Map();
1864
1867
  function $jsid(name) {
1865
- return jsid_cache[name] || (jsid_cache[name] = '$' + name);
1868
+ var jsid = jsid_cache.get(name);
1869
+ if (!jsid) {
1870
+ jsid = '$' + name;
1871
+ jsid_cache.set(name, jsid);
1872
+ }
1873
+ return jsid;
1866
1874
  }
1867
1875
  Opal.jsid = $jsid;
1868
1876
 
@@ -27,7 +27,6 @@ opal_filter "Array" do
27
27
  fails "Array#rassoc calls elem == obj on the second element of each contained array" # Expected [1, "foobar"] == [2, #<MockObject:0x4a6b4 @name="foobar", @null=nil>] to be truthy but was false
28
28
  fails "Array#rassoc does not check the last element in each contained but specifically the second" # Expected [1, "foobar", #<MockObject:0x4a37e @name="foobar", @null=nil>] == [2, #<MockObject:0x4a37e @name="foobar", @null=nil>, 1] to be truthy but was false
29
29
  fails "Array#sample returns nil for an empty array when called without n and a Random is given" # ArgumentError: invalid argument - 0
30
- fails "Array#sample samples evenly" # Expected 15.82 <= 13.277 to be truthy but was false
31
30
  fails "Array#select returns a new array of elements for which block is true" # Expected [1] == [1, 4, 6] to be truthy but was false
32
31
  fails "Array#slice can be sliced with Enumerator::ArithmeticSequence has endless range with start outside of array's bounds" # Expected [] == nil to be truthy but was false
33
32
  fails "Array#slice can be sliced with Enumerator::ArithmeticSequence has range with bounds outside of array" # Expected RangeError but no exception was raised ([0, 2, 4] was returned)
@@ -1,6 +1,5 @@
1
1
  # NOTE: run bin/format-filters after changing this file
2
2
  opal_filter "Integer" do
3
- fails "A singleton class raises a TypeError for Integer's" # Expected TypeError but got: Exception (Object.defineProperty called on non-object)
4
3
  fails "Bignum is deprecated" # NameError: uninitialized constant Bignum
5
4
  fails "Bignum is unified into Integer" # NameError: uninitialized constant Bignum
6
5
  fails "Fixnum is deprecated" # Expected warning to match: /constant ::Fixnum is deprecated/ but got: ""
@@ -134,7 +134,6 @@ opal_filter "Kernel" do
134
134
  fails "Kernel#respond_to? throws a type error if argument can't be coerced into a Symbol" # Expected TypeError (/is not a symbol nor a string/) but no exception was raised (false was returned)
135
135
  fails "Kernel#respond_to_missing? causes #respond_to? to return false if called and returning nil" # Expected nil to be false
136
136
  fails "Kernel#respond_to_missing? causes #respond_to? to return true if called and not returning false" # Expected "glark" to be true
137
- fails "Kernel#singleton_class raises TypeError for Integer" # Expected TypeError but got: Exception (Object.defineProperty called on non-object)
138
137
  fails "Kernel#singleton_class raises TypeError for Symbol" # Expected TypeError but no exception was raised (#<Class:#<String:0x53aaa>> was returned)
139
138
  fails "Kernel#singleton_method find a method defined on the singleton class" # NoMethodError: undefined method `singleton_method' for #<Object:0x4540a>
140
139
  fails "Kernel#singleton_method only looks at singleton methods and not at methods in the class" # Expected NoMethodError == NameError to be truthy but was false
@@ -16,7 +16,6 @@ opal_filter "language" do
16
16
  fails "A block yielded a single Array when non-symbol keys are in a keyword arguments Hash does not separate non-symbol keys and symbol keys and does not autosplat" # Expected [nil, {"a"=>10, "b"=>2}] == [[{"a"=>10, "b"=>2}], {}] to be truthy but was false
17
17
  fails "A block yielded a single Object receives the object if it does not respond to #respond_to?" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x551e>
18
18
  fails "A class definition extending an object (sclass) can use return to cause the enclosing method to return" # Expected "outer" == "inner" to be truthy but was false
19
- fails "A class definition extending an object (sclass) raises a TypeError when trying to extend numbers" # Expected TypeError but got: Exception (Object.defineProperty called on non-object)
20
19
  fails "A class definition raises TypeError if any constant qualifying the class is not a Module" # Expected TypeError but no exception was raised (nil was returned)
21
20
  fails "A class definition raises TypeError if the constant qualifying the class is nil" # Expected TypeError but no exception was raised (nil was returned)
22
21
  fails "A class definition raises a TypeError if inheriting from a metaclass" # Expected TypeError but no exception was raised (nil was returned)
@@ -50,7 +49,6 @@ opal_filter "language" do
50
49
  fails "A nested method definition creates an instance method when evaluated in an instance method" # NoMethodError: undefined method `an_instance_method' for #<DefSpecNested:0x1064c>
51
50
  fails "A number literal can be a decimal literal with trailing 'r' to represent a Rational" # Expected (5404319552844595/18014398509481984) == (3/10) to be truthy but was false
52
51
  fails "A number literal can be a float literal with trailing 'r' to represent a Rational" # Expected (5030569068109113/288230376151711740) == (136353847812057/7812500000000000) to be truthy but was false
53
- fails "A singleton class doesn't have singleton class" # Expected TypeError but got: Exception (Object.defineProperty called on non-object)
54
52
  fails "A singleton class raises a TypeError for symbols" # Expected TypeError but no exception was raised (#<Class:#<String:0x9093e>> was returned)
55
53
  fails "A singleton method definition can be declared for a global variable" # TypeError: can't define singleton
56
54
  fails "A singleton method definition raises FrozenError with the correct class name" # Expected "can't modify frozen Class: #<Class:#<Object:0x10574>>".start_with? "can't modify frozen object" to be truthy but was false
@@ -325,7 +323,6 @@ opal_filter "language" do
325
323
  fails "a method definition that sets more than one default parameter all to the same value treats the argument after the multi-parameter normally" # Expected ArgumentError (wrong number of arguments (given 3, expected 0..2)) but got: ArgumentError ([MSpecEnv#bar] wrong number of arguments (given 3, expected -1))
326
324
  fails "kwarg with omitted value in a method call accepts short notation 'kwarg' in method call for definition 'def call(*args, **kwargs) = [args, kwargs]'" # NameError: uninitialized constant SpecEvaluate::a
327
325
  fails "kwarg with omitted value in a method call with methods and local variables for definition \n def call(*args, **kwargs) = [args, kwargs]\n def bar\n \"baz\"\n end\n def foo(val)\n call bar:, val:\n end" # NameError: uninitialized constant SpecEvaluate::bar
328
- fails "self in a metaclass body (class << obj) raises a TypeError for numbers" # Expected TypeError but got: Exception (Object.defineProperty called on non-object)
329
326
  fails "self in a metaclass body (class << obj) raises a TypeError for symbols" # Expected TypeError but got: Exception (Cannot create property '$$meta' on string 'symbol')
330
327
  fails "self.send(:block_given?) returns false when a method defined by define_method is called with a block" # NoMethodError: undefined method `block_given?' for KernelSpecs::SelfBlockGiven
331
328
  fails "self.send(:block_given?) returns true if and only if a block is supplied" # NoMethodError: undefined method `block_given?' for KernelSpecs::SelfBlockGiven
@@ -0,0 +1,13 @@
1
+ describe "Case statement" do
2
+ it "works with JS object-wrapped values" do
3
+ a = false
4
+ objwr = `new String("abc")`
5
+
6
+ case objwr
7
+ when "abc"
8
+ a = true
9
+ end
10
+
11
+ a.should == true
12
+ end
13
+ end
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.7.2
4
+ version: 1.7.4
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: 2023-01-20 00:00:00.000000000 Z
13
+ date: 2023-09-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ast
@@ -904,6 +904,7 @@ files:
904
904
  - spec/opal/core/language/DATA/multiple___END___crlf_spec.rb
905
905
  - spec/opal/core/language/DATA/multiple___END___spec.rb
906
906
  - spec/opal/core/language/arguments/mlhs_arg_spec.rb
907
+ - spec/opal/core/language/case_spec.rb
907
908
  - spec/opal/core/language/forward_args_spec.rb
908
909
  - spec/opal/core/language/if_spec.rb
909
910
  - spec/opal/core/language/infinite_range_spec.rb
@@ -1215,10 +1216,10 @@ licenses:
1215
1216
  metadata:
1216
1217
  homepage_uri: https://opalrb.com/
1217
1218
  bug_tracker_uri: https://github.com/opal/opal/issues
1218
- changelog_uri: https://github.com/opal/opal/blob/v1.7.2/CHANGELOG.md
1219
- readme_uri: https://github.com/opal/opal/blob/v1.7.2/README.md
1220
- api_documentation_uri: http://opalrb.com/docs/api/v1.7.2/index.html
1221
- guides_uri: http://opalrb.com/docs/guides/v1.7.2/index.html
1219
+ changelog_uri: https://github.com/opal/opal/blob/v1.7.4/CHANGELOG.md
1220
+ readme_uri: https://github.com/opal/opal/blob/v1.7.4/README.md
1221
+ api_documentation_uri: http://opalrb.com/docs/api/v1.7.4/index.html
1222
+ guides_uri: http://opalrb.com/docs/guides/v1.7.4/index.html
1222
1223
  chat_uri: https://gitter.im/opal/opal
1223
1224
  source_code_uri: https://github.com/opal/opal
1224
1225
  post_install_message:
@@ -1236,7 +1237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1236
1237
  - !ruby/object:Gem::Version
1237
1238
  version: '0'
1238
1239
  requirements: []
1239
- rubygems_version: 3.4.3
1240
+ rubygems_version: 3.4.5
1240
1241
  signing_key:
1241
1242
  specification_version: 4
1242
1243
  summary: Ruby runtime and core library for JavaScript