Sha256: ca296bcfdf36d407edbcb3fa71e8b7718c94dce141a8a87e37881aadf23b80cd

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

# backtick_javascript: true

module ::Errno
  errors = [
    [:EINVAL, 'Invalid argument', 22],
    [:EEXIST, 'File exists', 17],
    [:EISDIR, 'Is a directory', 21],
    [:EMFILE, 'Too many open files', 24],
    [:ESPIPE, 'Illegal seek', 29],
    [:EACCES, 'Permission denied', 13],
    [:EPERM, 'Operation not permitted', 1],
    [:ENOENT, 'No such file or directory', 2],
    [:ENAMETOOLONG, 'File name too long', 36]
  ]

  klass = nil

  %x{
    var i;
    for (i = 0; i < errors.length; i++) {
      (function() { // Create a closure
        var class_name = errors[i][0];
        var default_message = errors[i][1];
        var errno = errors[i][2];

        klass = Opal.klass(self, Opal.SystemCallError, class_name);
        klass.errno = errno;

        #{
          class << klass
            def new(name = nil)
              message = `default_message`
              message += " - #{name}" if name
              super(message)
            end
          end
        }
      })();
    }
  }
end

class ::SystemCallError < ::StandardError
  def errno
    self.class.errno
  end

  class << self
    attr_reader :errno
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 opal/corelib/error/errno.rb
opal-1.8.2 opal/corelib/error/errno.rb
opal-1.8.1 opal/corelib/error/errno.rb
opal-1.8.0 opal/corelib/error/errno.rb
opal-1.8.0.beta1 opal/corelib/error/errno.rb
opal-1.8.0.alpha1 opal/corelib/error/errno.rb