opal 1.0.0.beta1 → 1.0.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.
@@ -138,6 +138,7 @@ module Opal
138
138
  end
139
139
 
140
140
  on('-P', '--map FILE', 'Enable/Disable source map') do |file|
141
+ options[:runner_options] ||= {}
141
142
  options[:runner_options][:map_file] = file
142
143
  end
143
144
 
@@ -13,9 +13,9 @@ fs.writeFileSync("/tmp/chrome-opal.html", "" +
13
13
  "<html>" +
14
14
  "<head>" +
15
15
  "<meta charset='utf-8'>" +
16
- "<script src='chrome-opal.js'></script>" +
17
16
  "</head>" +
18
17
  "<body>" +
18
+ "<script src='./chrome-opal.js'></script>" +
19
19
  "</body>" +
20
20
  "</html>"
21
21
  );
@@ -91,7 +91,7 @@ CDP(options, function(client) {
91
91
  Runtime.exceptionThrown(function(exception) {
92
92
  var exceptionDetails = exception.exceptionDetails,
93
93
  properties = exceptionDetails.exception.preview.properties,
94
- stackTrace = exceptionDetails.stackTrace.callFrames,
94
+ stackTrace = exceptionDetails.stackTrace ? exceptionDetails.stackTrace.callFrames : [],
95
95
  name, message, trace = [], i;
96
96
 
97
97
 
@@ -62,10 +62,10 @@ module Opal
62
62
 
63
63
  chrome_pid = Process.spawn(chrome_server_cmd)
64
64
 
65
- Timeout.timeout(1) do
65
+ Timeout.timeout(10) do
66
66
  loop do
67
67
  break if chrome_server_running?
68
- sleep 0.1
68
+ sleep 0.5
69
69
  end
70
70
  end
71
71
 
@@ -1,6 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if RUBY_ENGINE == 'opal'
4
+ class Parser::Lexer
5
+ def source_buffer=(source_buffer)
6
+ @source_buffer = source_buffer
7
+
8
+ if @source_buffer
9
+ source = @source_buffer.source
10
+ # Force UTF8 unpacking even if JS works with UTF-16/UCS-2
11
+ # See: https://mathiasbynens.be/notes/javascript-encoding
12
+ @source_pts = source.unpack('U*')
13
+ else
14
+ @source_pts = nil
15
+ end
16
+ end
17
+ end
18
+
4
19
  class Parser::Lexer::Literal
5
20
  undef :extend_string
6
21
 
@@ -6,66 +6,29 @@ module Opal
6
6
  module Util
7
7
  extend self
8
8
 
9
+ ExitStatusError = Class.new(StandardError)
10
+
9
11
  # Used for uglifying source to minify.
10
12
  #
11
13
  # Opal::Util.uglify("javascript contents")
12
14
  #
13
15
  # @param str [String] string to minify
14
16
  # @return [String]
15
- def uglify(str)
16
- uglifyjs = DigestSourceCommand.new(:uglifyjs, '-c', ' (install with: "npm install -g uglify-js")')
17
- uglifyjs.digest(str)
17
+ def uglify(source)
18
+ sh 'bin/yarn -s run uglifyjs -c', data: source
18
19
  end
19
20
 
20
21
  # Gzip code to check file size.
21
- def gzip(str)
22
- gzip = DigestSourceCommand.new(:gzip, '-f', ', it is required to produce the .gz version')
23
- gzip.digest(str)
22
+ def gzip(source)
23
+ sh 'gzip -f', data: source
24
24
  end
25
25
 
26
- class Command
27
- def initialize(command, options, message = nil)
28
- @command, @options, @message = command, options, message
29
- return unless command_installed? command, message
30
- end
31
- attr_reader :command, :options, :message
32
-
33
- private
34
-
35
- def hide_stderr
36
- if (/mswin|mingw/ =~ RUBY_PLATFORM).nil?
37
- '2> /dev/null'
38
- else
39
- '2> nul'
40
- end
41
- end
42
-
43
- # Code from http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
44
- def which(cmd)
45
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
46
- ENV['PATH'].split(File::PATH_SEPARATOR).find do |path|
47
- exts.find do |ext|
48
- exe = File.join(path, "#{cmd}#{ext}")
49
- exe if File.executable? exe
50
- end
51
- end
52
- end
53
-
54
- INSTALLED = {}
55
- def command_installed?(cmd, install_comment)
56
- command_installed = Command::INSTALLED[cmd.to_s] ||= which(cmd)
57
- $stderr.puts %{"#{cmd}" command not found#{install_comment}} unless command_installed
58
- command_installed
59
- end
60
- end
26
+ private
61
27
 
62
- class DigestSourceCommand < Command
63
- ExitStatusError = Class.new(StandardError)
64
- def digest(source)
65
- out, _, status = Open3.capture3("#{command} #{options} #{hide_stderr}", stdin_data: source)
66
- raise ExitStatusError, "exited with status #{status.exitstatus}" unless status.success?
67
- out
68
- end
28
+ def sh(command, data:)
29
+ out, _err, status = Open3.capture3(command, stdin_data: data)
30
+ raise ExitStatusError, "exited with status #{status.exitstatus}" unless status.success?
31
+ out
69
32
  end
70
33
  end
71
34
  end
@@ -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.0.0.beta1'
6
+ VERSION = '1.0.4'
7
7
  end
@@ -33,10 +33,10 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ['lib']
35
35
 
36
- spec.required_ruby_version = '>= 2.0.0'
36
+ spec.required_ruby_version = '>= 2.3'
37
37
 
38
38
  spec.add_dependency 'ast', '>= 2.3.0'
39
- spec.add_dependency 'parser', '= 2.5.3.0'
39
+ spec.add_dependency 'parser', '~> 2.6'
40
40
 
41
41
  spec.add_development_dependency 'sourcemap', '~> 0.1.0'
42
42
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,9 +1,9 @@
1
1
  RUBY_PLATFORM = 'opal'
2
2
  RUBY_ENGINE = 'opal'
3
- RUBY_VERSION = '2.5.3'
4
- RUBY_ENGINE_VERSION = '1.0.0.beta1'
5
- RUBY_RELEASE_DATE = '2019-02-24'
3
+ RUBY_VERSION = '2.5.8'
4
+ RUBY_ENGINE_VERSION = '1.0.4'
5
+ RUBY_RELEASE_DATE = '2020-12-13'
6
6
  RUBY_PATCHLEVEL = 0
7
7
  RUBY_REVISION = 0
8
- RUBY_COPYRIGHT = 'opal - Copyright (C) 2013-2019 Adam Beynon and the Opal contributors'
8
+ RUBY_COPYRIGHT = 'opal - Copyright (C) 2013-2020 Adam Beynon and the Opal contributors'
9
9
  RUBY_DESCRIPTION = "opal #{RUBY_ENGINE_VERSION} (#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION})"
@@ -61,6 +61,7 @@ class Exception < `Error`
61
61
 
62
62
  var cloned = #{clone};
63
63
  cloned.message = str;
64
+ cloned.stack = self.stack;
64
65
  return cloned;
65
66
  }
66
67
  end
@@ -81,8 +82,10 @@ class Exception < `Error`
81
82
 
82
83
  if (backtrace === nil) {
83
84
  self.backtrace = nil;
85
+ self.stack = '';
84
86
  } else if (backtrace.$$is_string) {
85
87
  self.backtrace = [backtrace];
88
+ self.stack = backtrace;
86
89
  } else {
87
90
  if (backtrace.$$is_array) {
88
91
  for (i = 0, ii = backtrace.length; i < ii; i++) {
@@ -100,6 +103,7 @@ class Exception < `Error`
100
103
  }
101
104
 
102
105
  self.backtrace = backtrace;
106
+ self.stack = backtrace.join('\n');
103
107
  }
104
108
 
105
109
  return backtrace;
@@ -63,7 +63,7 @@
63
63
  missing_require_severity: 'error', // error, warning, ignore
64
64
  unsupported_features_severity: 'warning', // error, warning, ignore
65
65
  enable_stack_trace: true // true, false
66
- }
66
+ };
67
67
 
68
68
  // Minify common function calls
69
69
  var $hasOwn = Object.hasOwnProperty;
@@ -90,7 +90,7 @@
90
90
  if (obj.$$is_number) return (obj * 2)+1;
91
91
  if (obj.$$id != null) {
92
92
  return obj.$$id;
93
- };
93
+ }
94
94
  $defineProperty(obj, '$$id', Opal.uid());
95
95
  return obj.$$id;
96
96
  };
@@ -109,7 +109,7 @@
109
109
  // Pops an exception from the stack and updates `$!`.
110
110
  Opal.pop_exception = function() {
111
111
  Opal.gvars["!"] = Opal.exceptions.pop() || nil;
112
- }
112
+ };
113
113
 
114
114
  // Inspect any kind of object, including non Ruby ones
115
115
  Opal.inspect = function(obj) {
@@ -125,7 +125,7 @@
125
125
  else {
126
126
  return obj.$inspect();
127
127
  }
128
- }
128
+ };
129
129
 
130
130
  function $defineProperty(object, name, initialValue) {
131
131
  if (typeof(object) === "string") {
@@ -239,7 +239,7 @@
239
239
 
240
240
  result = const_get_name(cref, name); if (result != null) return result;
241
241
  result = const_missing(cref, name, skip_missing); if (result != null) return result;
242
- }
242
+ };
243
243
 
244
244
  // Look for the constant relative to a cref or call `#const_missing` (when the
245
245
  // constant is prefixed by `::`).
@@ -453,10 +453,10 @@
453
453
  // If superclass has metaclass then we have explicitely inherit it.
454
454
  Opal.build_class_singleton_class(klass);
455
455
  }
456
- };
456
+ }
457
457
 
458
458
  return klass;
459
- }
459
+ };
460
460
 
461
461
 
462
462
  function find_existing_class(scope, name) {
@@ -528,7 +528,7 @@
528
528
  }
529
529
 
530
530
  return klass;
531
- }
531
+ };
532
532
 
533
533
  // Define new module (or return existing module). The given `scope` is basically
534
534
  // the current `self` value the `module` statement was defined in. If this is
@@ -575,7 +575,7 @@
575
575
  $setPrototype(module, Opal.Module.prototype);
576
576
 
577
577
  return module;
578
- }
578
+ };
579
579
 
580
580
  function find_existing_module(scope, name) {
581
581
  var module = const_get_name(scope, name);
@@ -612,7 +612,7 @@
612
612
  Opal.const_set(scope, name, module);
613
613
 
614
614
  return module;
615
- }
615
+ };
616
616
 
617
617
  // Return the singleton class for the passed object.
618
618
  //
@@ -687,7 +687,7 @@
687
687
  $defineProperty(mod, '$$class', Opal.Module);
688
688
 
689
689
  return meta;
690
- }
690
+ };
691
691
 
692
692
  // Build the singleton class for a Ruby (non class) Object.
693
693
  //
@@ -711,7 +711,7 @@
711
711
 
712
712
  Opal.is_method = function(prop) {
713
713
  return (prop[0] === '$' && prop[1] !== '$');
714
- }
714
+ };
715
715
 
716
716
  Opal.instance_methods = function(mod) {
717
717
  var exclude = [], results = [], ancestors = Opal.ancestors(mod);
@@ -745,7 +745,7 @@
745
745
  }
746
746
 
747
747
  return results;
748
- }
748
+ };
749
749
 
750
750
  Opal.own_instance_methods = function(mod) {
751
751
  var results = [],
@@ -771,22 +771,22 @@
771
771
  }
772
772
 
773
773
  return results;
774
- }
774
+ };
775
775
 
776
776
  Opal.methods = function(obj) {
777
777
  return Opal.instance_methods(Opal.get_singleton_class(obj));
778
- }
778
+ };
779
779
 
780
780
  Opal.own_methods = function(obj) {
781
781
  return Opal.own_instance_methods(Opal.get_singleton_class(obj));
782
- }
782
+ };
783
783
 
784
784
  Opal.receiver_methods = function(obj) {
785
785
  var mod = Opal.get_singleton_class(obj);
786
786
  var singleton_methods = Opal.own_instance_methods(mod);
787
787
  var instance_methods = Opal.own_instance_methods(mod.$$super);
788
788
  return singleton_methods.concat(instance_methods);
789
- }
789
+ };
790
790
 
791
791
  // Returns an object containing all pairs of names/values
792
792
  // for all class variables defined in provided +module+
@@ -808,7 +808,7 @@
808
808
  }
809
809
 
810
810
  return result;
811
- }
811
+ };
812
812
 
813
813
  // Sets class variable with specified +name+ to +value+
814
814
  // in provided +module+
@@ -832,7 +832,7 @@
832
832
  module.$$cvars[name] = value;
833
833
 
834
834
  return value;
835
- }
835
+ };
836
836
 
837
837
  function isRoot(proto) {
838
838
  return proto.hasOwnProperty('$$iclass') && proto.hasOwnProperty('$$root');
@@ -976,7 +976,7 @@
976
976
  includer.$$own_included_modules = own_included_modules(includer);
977
977
 
978
978
  Opal.const_cache_version++;
979
- }
979
+ };
980
980
 
981
981
  Opal.prepend_features = function(module, prepender) {
982
982
  // Here we change the ancestors chain from
@@ -1064,7 +1064,7 @@
1064
1064
  prepender.$$own_prepended_modules = own_prepended_modules(prepender);
1065
1065
 
1066
1066
  Opal.const_cache_version++;
1067
- }
1067
+ };
1068
1068
 
1069
1069
  function flush_methods_in(module) {
1070
1070
  var proto = module.$$prototype,
@@ -1222,7 +1222,7 @@
1222
1222
  module.$$ancestors = result;
1223
1223
 
1224
1224
  return result;
1225
- }
1225
+ };
1226
1226
 
1227
1227
  Opal.included_modules = function(module) {
1228
1228
  var result = [], mod = null, proto = Object.getPrototypeOf(module.$$prototype);
@@ -1235,7 +1235,7 @@
1235
1235
  }
1236
1236
 
1237
1237
  return result;
1238
- }
1238
+ };
1239
1239
 
1240
1240
 
1241
1241
  // Method Missing
@@ -1608,7 +1608,7 @@
1608
1608
  else {
1609
1609
  return Opal.hash2([], {});
1610
1610
  }
1611
- }
1611
+ };
1612
1612
 
1613
1613
  // Used to get a list of rest keyword arguments. Method takes the given
1614
1614
  // keyword args, i.e. the hash literal passed to the method containing all
@@ -1624,7 +1624,7 @@
1624
1624
  Opal.kwrestargs = function(given_args, used_args) {
1625
1625
  var keys = [],
1626
1626
  map = {},
1627
- key = null,
1627
+ key ,
1628
1628
  given_map = given_args.$$smap;
1629
1629
 
1630
1630
  for (key in given_map) {
@@ -1672,12 +1672,12 @@
1672
1672
  }
1673
1673
 
1674
1674
  return recv.$method_missing.apply(recv, [method].concat(args));
1675
- }
1675
+ };
1676
1676
 
1677
1677
  Opal.lambda = function(block) {
1678
1678
  block.$$is_lambda = true;
1679
1679
  return block;
1680
- }
1680
+ };
1681
1681
 
1682
1682
  // Used to define methods on an object. This is a helper method, used by the
1683
1683
  // compiled source to define methods on special case objects when the compiler
@@ -1759,7 +1759,7 @@
1759
1759
  else if (singleton_of && singleton_of.$singleton_method_added && !singleton_of.$singleton_method_added.$$stub) {
1760
1760
  singleton_of.$singleton_method_added(jsid.substr(1));
1761
1761
  }
1762
- }
1762
+ };
1763
1763
 
1764
1764
  // Define a singleton method on the given object (see Opal.def).
1765
1765
  Opal.defs = function(obj, jsid, body) {
@@ -2342,10 +2342,10 @@
2342
2342
 
2343
2343
  // Initialization
2344
2344
  // --------------
2345
- function $BasicObject() {};
2346
- function $Object() {};
2347
- function $Module() {};
2348
- function $Class() {};
2345
+ function $BasicObject() {}
2346
+ function $Object() {}
2347
+ function $Module() {}
2348
+ function $Class() {}
2349
2349
 
2350
2350
  Opal.BasicObject = BasicObject = Opal.allocate_class('BasicObject', null, $BasicObject);
2351
2351
  Opal.Object = _Object = Opal.allocate_class('Object', Opal.BasicObject, $Object);
@@ -2398,7 +2398,7 @@
2398
2398
 
2399
2399
 
2400
2400
  // Nil
2401
- function $NilClass() {};
2401
+ function $NilClass() {}
2402
2402
  Opal.NilClass = Opal.allocate_class('NilClass', Opal.Object, $NilClass);
2403
2403
  Opal.const_set(_Object, 'NilClass', Opal.NilClass);
2404
2404
  nil = Opal.nil = new Opal.NilClass();