Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 81640c516d4e
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b9516a21cf5e
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jan 11, 2015

  1. Add some missing error classes

    - NoMemoryError
    - SignalException
    - Interrupt
    elia committed Jan 11, 2015
    Copy the full SHA
    f37f4b6 View commit details
  2. Copy the full SHA
    bdb9f92 View commit details
  3. Add Module#class_variable_get/set

    ref: #677
    elia committed Jan 11, 2015
    Copy the full SHA
    b9516a2 View commit details
Showing with 37 additions and 0 deletions.
  1. +8 −0 Rakefile
  2. +3 −0 opal/corelib/error.rb
  3. +19 −0 opal/corelib/module.rb
  4. +3 −0 spec/filters/bugs/module.rb
  5. +2 −0 spec/filters/unsupported/frozen.rb
  6. +2 −0 spec/rubyspecs
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -20,7 +20,15 @@ end

task :default => [:rspec, :mspec_node]

desc <<-DESC
Run the MSpec test suite on node
Use PATTERN and env var to manually set the glob for specs:
# Will run all specs matching the specified pattern.
# (Note: the rubyspecs filters will still apply)
rake mspec_node PATTERN=spec/corelib/core/module/class_variable*
DESC
task :mspec_node do
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty?
3 changes: 3 additions & 0 deletions opal/corelib/error.rb
Original file line number Diff line number Diff line change
@@ -48,6 +48,9 @@ class LoadError < ScriptError; end
class NotImplementedError < ScriptError; end

class SystemExit < Exception; end
class NoMemoryError < Exception; end
class SignalException < Exception; end
class Interrupt < Exception; end

class StandardError < Exception; end
class NameError < StandardError; end
19 changes: 19 additions & 0 deletions opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -136,6 +136,25 @@ def autoload(const, path)
}
end

def class_variable_get(name)
name = Opal.coerce_to!(name, String, :to_str)
raise NameError, 'class vars should start with @@' if `name.length < 3 || name.slice(0,2) !== '@@'`
%x{
var value = Opal.cvars[name.slice(2)];
#{raise NameError, 'uninitialized class variable @@a in' if `value == null`}
return value;
}
end

def class_variable_set(name, value)
name = Opal.coerce_to!(name, String, :to_str)
raise NameError if `name.length < 3 || name.slice(0,2) !== '@@'`
%x{
Opal.cvars[name.slice(2)] = value;
return value;
}
end

def constants
`self.$$scope.constants`
end
3 changes: 3 additions & 0 deletions spec/filters/bugs/module.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@
fails "Module#const_defined? should not search parent scopes of classes and modules if inherit is false"
fails "Module#const_get should not search parent scopes of classes and modules if inherit is false"

fails "Module#class_variable_set sets the value of a class variable with the given name defined in an included module"
fails "Module#class_variable_get returns the value of a class variable with the given name defined in an included module"

fails "Module#module_function as a toggle (no arguments) in a Module body functions normally if both toggle and definitions inside a eval"
fails "Module#module_function as a toggle (no arguments) in a Module body does not affect definitions when inside an eval even if the definitions are outside of it"

2 changes: 2 additions & 0 deletions spec/filters/unsupported/frozen.rb
Original file line number Diff line number Diff line change
@@ -87,4 +87,6 @@
fails "Hash#update raises a RuntimeError on a frozen instance that is modified"
fails "Hash#rehash raises a RuntimeError if called on a frozen instance"
fails "Hash#[]= duplicates and freezes string keys"

fails "Module#class_variable_set raises a RuntimeError when self is frozen"
end
2 changes: 2 additions & 0 deletions spec/rubyspecs
Original file line number Diff line number Diff line change
@@ -69,6 +69,8 @@ corelib/core/matchdata/to_a_spec
corelib/core/matchdata/to_s_spec
corelib/core/matchdata/values_at_spec

corelib/core/module/class_variable_get_spec
corelib/core/module/class_variable_set_spec
corelib/core/module/module_function_spec

corelib/core/range/begin_spec