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: cef2632f2aff
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ec61e26d47db
Choose a head ref
  • 10 commits
  • 4 files changed
  • 2 contributors

Commits on May 13, 2015

  1. * Exclude items that are unsupported in Opal (private methods, frozen)

    * Exclude bugs we can't fix right now
    wied03 committed May 13, 2015
    Copy the full SHA
    496a00d View commit details
  2. * Handle Methods

    * Handle case where nil is passed in without a block (kind of semantics, but better to pass ruby specs)
    wied03 committed May 13, 2015
    Copy the full SHA
    74eef1f View commit details
  3. Copy the full SHA
    559e5d8 View commit details
  4. Copy the full SHA
    24435a6 View commit details
  5. Copy the full SHA
    973eb61 View commit details
  6. Explain why

    wied03 committed May 13, 2015
    Copy the full SHA
    91aed7c View commit details

Commits on May 14, 2015

  1. Get rid of default symbol

    wied03 committed May 14, 2015
    Copy the full SHA
    a31575b View commit details
  2. More refactoring:

    * Use ArgumentError exceptions consistent with Ruby
    * Follow convention in opal/opal/corelib/array.rb, where we can have easier to read code by specifying real parameters instead of args and use native Javascript to check the actual amount of arguments passed
    wied03 committed May 14, 2015
    Copy the full SHA
    8493b01 View commit details
  3. Cleanup Module#define_method

    elia committed May 14, 2015
    Copy the full SHA
    f955e0d View commit details
  4. Merge pull request #853 from wied03/master

    define_method fixes for issue #850 (Method,UnboundMethod)
    
    fixes #850
    elia committed May 14, 2015
    Copy the full SHA
    ec61e26 View commit details
Showing with 42 additions and 10 deletions.
  1. +16 −10 opal/corelib/module.rb
  2. +19 −0 spec/filters/bugs/module.rb
  3. +6 −0 spec/filters/unsupported/module.rb
  4. +1 −0 spec/rubyspecs
26 changes: 16 additions & 10 deletions opal/corelib/module.rb
Original file line number Diff line number Diff line change
@@ -278,18 +278,24 @@ def const_set(name, value)
value
end

def define_method(name, method = nil, &block)
unless method || block
raise ArgumentError, 'tried to create Proc object without a block'
def define_method(name, method = undefined, &block)
if `method === undefined && !#{block_given?}`
raise ArgumentError, "tried to create a Proc object without a block"
end

if method
if Proc === method
block = method
else
raise TypeError, "wrong argument type #{method.class} (expected Proc/Method)"
end
end
block ||= case method
when Proc
method
when Method
method.to_proc
when UnboundMethod
lambda do |*args|
bound = method.bind(self)
bound.call *args
end
else
raise TypeError, "wrong argument type #{block.class} (expected Proc/Method)"
end

%x{
var id = '$' + name;
19 changes: 19 additions & 0 deletions spec/filters/bugs/module.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
opal_filter "Module" do
fails "passed { |a, b = 1| } creates a method that raises an ArgumentError when passed zero arguments"
fails "passed { |a, b = 1| } creates a method that raises an ArgumentError when passed three arguments"
fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed one argument"
fails "Module#define_method calls #method_added after the method is added to the Module"
fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed two arguments"
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed one argument"
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed two arguments"
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments"
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments and a block"
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed two arguments"
fails "Module#define_method passed { |a, *b| } creates a method that raises an ArgumentError when passed zero arguments"
fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed zero arguments"
fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument"
fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed one argument and a block"
fails "Module#define_method passed { |a, b| } creates a method that raises an ArgumentError when passed three arguments"
fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed zero arguments"
fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument"
fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument and a block"
fails "Module#define_method does not change the arity check style of the original proc"
fails "A class definition has no class variables"
fails "A class definition allows the declaration of class variables in the body"
fails "A class definition allows the declaration of class variables in a class method"
6 changes: 6 additions & 0 deletions spec/filters/unsupported/module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
opal_filter "Module" do
fails "Module#define_method raises a RuntimeError if frozen"
fails "Module#define_method is private"
fails "Module#define_method when name is :initialize passed a block sets visibility to private when method name is :initialize"
fails "Module#define_method when name is :initialize given an UnboundMethod sets the visibility to private when method is named :initialize"
end
1 change: 1 addition & 0 deletions spec/rubyspecs
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ corelib/core/module/module_function_spec
corelib/core/module/const_get_spec
corelib/core/module/include_spec
corelib/core/module/instance_methods_spec
corelib/core/module/define_method_spec

corelib/core/range/begin_spec
corelib/core/range/case_compare_spec