opal 0.9.0.beta1 → 0.9.0.beta2
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 +4 -4
- data/CHANGELOG.md +39 -20
- data/CONTRIBUTING.md +8 -16
- data/lib/opal/compiler.rb +5 -0
- data/lib/opal/nodes/def.rb +10 -3
- data/lib/opal/nodes/definitions.rb +14 -3
- data/lib/opal/paths.rb +21 -4
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/array.rb +1 -1
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/constants.rb +2 -2
- data/opal/corelib/enumerable.rb +79 -2
- data/opal/corelib/error.rb +18 -0
- data/opal/corelib/helpers.rb +2 -8
- data/opal/corelib/kernel.rb +7 -7
- data/opal/corelib/module.rb +10 -10
- data/opal/corelib/number.rb +1 -1
- data/opal/corelib/regexp.rb +31 -30
- data/opal/corelib/string.rb +1 -1
- data/opal/corelib/struct.rb +8 -10
- data/opal/corelib/time.rb +4 -2
- data/opal/corelib/unsupported.rb +2 -2
- data/spec/filters/bugs/enumerable.rb +0 -19
- data/spec/filters/bugs/exception.rb +0 -4
- data/spec/filters/bugs/language.rb +7 -5
- data/spec/filters/bugs/module.rb +18 -19
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +0 -8
- data/spec/filters/bugs/struct.rb +2 -2
- data/spec/filters/unsupported/bignum.rb +1 -0
- data/spec/filters/unsupported/language.rb +7 -0
- data/spec/lib/compiler_spec.rb +5 -0
- data/spec/lib/parser/undef_spec.rb +4 -0
- data/spec/lib/paths_spec.rb +11 -0
- data/spec/lib/spec_helper.rb +1 -1
- data/spec/opal/core/arity_spec.rb +142 -0
- data/spec/rubyspecs +1 -0
- data/stdlib/json.rb +13 -8
- data/stdlib/native.rb +1 -1
- data/stdlib/observer.rb +1 -1
- data/stdlib/ostruct.rb +1 -1
- data/stdlib/set.rb +33 -0
- data/tasks/testing.rake +8 -7
- metadata +7 -3
data/spec/filters/bugs/module.rb
CHANGED
@@ -5,8 +5,8 @@ opal_filter "Module" do
|
|
5
5
|
fails "Module#<= raises a TypeError if the argument is not a class/module"
|
6
6
|
fails "Module#<= returns nil if self is not related to the given module"
|
7
7
|
fails "Module#<= returns true if self is a subclass of, the same as or includes the given module"
|
8
|
-
fails "Module#<=> returns +1 if self is a superclas of or included by the given module"
|
9
8
|
fails "Module#<=> returns -1 if self is a subclass of or includes the given module"
|
9
|
+
fails "Module#<=> returns +1 if self is a superclas of or included by the given module"
|
10
10
|
fails "Module#=== returns true when the given Object's class includes self or when the given Object is extended by self"
|
11
11
|
fails "Module#> raises a TypeError if the argument is not a class/module"
|
12
12
|
fails "Module#> returns false if self is a subclass of or includes the given module"
|
@@ -58,12 +58,6 @@ opal_filter "Module" do
|
|
58
58
|
fails "Module#class_eval resolves constants in the receiver's scope"
|
59
59
|
fails "Module#class_eval uses the optional filename and lineno parameters for error messages"
|
60
60
|
fails "Module#class_exec defines method in the receiver's scope"
|
61
|
-
fails "Module#class_exec passes arguments to the block"
|
62
|
-
fails "Module#class_exec raises a LocalJumpError when no block is given"
|
63
|
-
fails "Module#class_variables does not return class variables defined in extended modules"
|
64
|
-
fails "Module#class_variables returns an Array of Symbols of class variable names defined in a metaclass"
|
65
|
-
fails "Module#class_variables returns an Array with names of class variables defined in metaclasses"
|
66
|
-
fails "Module#class_variables returns an Array with the names of class variables of self"
|
67
61
|
fails "Module#class_variable_defined? converts a non string/symbol/fixnum name to string using to_str"
|
68
62
|
fails "Module#class_variable_defined? raises a TypeError when the given names can't be converted to strings using to_str"
|
69
63
|
fails "Module#class_variable_defined? returns false if a class variables with the given name is defined in an extended module"
|
@@ -74,13 +68,10 @@ opal_filter "Module" do
|
|
74
68
|
fails "Module#class_variable_defined? returns true if the class variable is defined in a metaclass"
|
75
69
|
fails "Module#class_variable_get returns the value of a class variable with the given name defined in an included module"
|
76
70
|
fails "Module#class_variable_set sets the value of a class variable with the given name defined in an included module"
|
77
|
-
fails "Module#
|
78
|
-
fails "Module#
|
79
|
-
fails "Module#
|
80
|
-
fails "Module#
|
81
|
-
fails "Module#constants returns all constants including inherited when passed true"
|
82
|
-
fails "Module#constants returns an array of Symbol names of all constants defined in the module and all included modules"
|
83
|
-
fails "Module#constants returns only public constants"
|
71
|
+
fails "Module#class_variables does not return class variables defined in extended modules"
|
72
|
+
fails "Module#class_variables returns an Array of Symbols of class variable names defined in a metaclass"
|
73
|
+
fails "Module#class_variables returns an Array with names of class variables defined in metaclasses"
|
74
|
+
fails "Module#class_variables returns an Array with the names of class variables of self"
|
84
75
|
fails "Module#const_get accepts a toplevel scope qualifier"
|
85
76
|
fails "Module#const_get calls #to_str to convert the given name to a String"
|
86
77
|
fails "Module#const_get does not search the singleton class of a Class or Module"
|
@@ -92,9 +83,18 @@ opal_filter "Module" do
|
|
92
83
|
fails "Module#const_get with dynamically assigned constants searches a module included in the superclass"
|
93
84
|
fails "Module#const_get with dynamically assigned constants searches the superclass chain"
|
94
85
|
fails "Module#const_missing raises NameError and does not include toplevel Object"
|
86
|
+
fails "Module#constants doesn't returns inherited constants when passed false"
|
87
|
+
fails "Module#constants doesn't returns inherited constants when passed nil"
|
88
|
+
fails "Module#constants includes names of constants defined after a module is included"
|
89
|
+
fails "Module#constants returns all constants including inherited when passed some object"
|
90
|
+
fails "Module#constants returns all constants including inherited when passed true"
|
91
|
+
fails "Module#constants returns an array of Symbol names of all constants defined in the module and all included modules"
|
92
|
+
fails "Module#constants returns only public constants"
|
95
93
|
fails "Module#define_method does not change the arity check style of the original proc"
|
96
94
|
fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed one argument"
|
97
95
|
fails "Module#define_method passed { } creates a method that raises an ArgumentError when passed two arguments"
|
96
|
+
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed one argument"
|
97
|
+
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed two arguments"
|
98
98
|
fails "Module#define_method passed { |a, *b| } creates a method that raises an ArgumentError when passed zero arguments"
|
99
99
|
fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument and a block"
|
100
100
|
fails "Module#define_method passed { |a, b, *c| } creates a method that raises an ArgumentError when passed one argument"
|
@@ -106,8 +106,6 @@ opal_filter "Module" do
|
|
106
106
|
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed two arguments"
|
107
107
|
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments and a block"
|
108
108
|
fails "Module#define_method passed { |a| } creates a method that raises an ArgumentError when passed zero arguments"
|
109
|
-
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed one argument"
|
110
|
-
fails "Module#define_method passed { || } creates a method that raises an ArgumentError when passed two arguments"
|
111
109
|
fails "Module#define_method raises a TypeError when a Method from a singleton class is defined on another class"
|
112
110
|
fails "Module#define_method raises a TypeError when a Method from one class is defined on an unrelated class"
|
113
111
|
fails "Module#define_method raises a TypeError when an UnboundMethod from a child class is defined on a parent class"
|
@@ -149,8 +147,6 @@ opal_filter "Module" do
|
|
149
147
|
fails "Module#module_eval resolves constants in the receiver's scope"
|
150
148
|
fails "Module#module_eval uses the optional filename and lineno parameters for error messages"
|
151
149
|
fails "Module#module_exec defines method in the receiver's scope"
|
152
|
-
fails "Module#module_exec passes arguments to the block"
|
153
|
-
fails "Module#module_exec raises a LocalJumpError when no block is given"
|
154
150
|
fails "Module#module_function as a toggle (no arguments) in a Module body affects evaled method definitions also even when outside the eval itself"
|
155
151
|
fails "Module#module_function as a toggle (no arguments) in a Module body does not affect module_evaled method definitions also if outside the eval itself"
|
156
152
|
fails "Module#module_function as a toggle (no arguments) in a Module body doesn't affect definitions when inside an eval even if the definitions are outside of it"
|
@@ -183,15 +179,18 @@ opal_filter "Module" do
|
|
183
179
|
fails "Module#prepend reports the prepended module as the unbound method owner"
|
184
180
|
fails "Module#prepend returns the class it's included into"
|
185
181
|
fails "Module#prepend sees an instance of a prepended class as kind of the prepended module"
|
182
|
+
fails "Module#prepend supports super when the module is prepended into a singleton class with a class super"
|
186
183
|
fails "Module#prepend supports super when the module is prepended into a singleton class"
|
187
184
|
fails "Module#prepend throws a NoMethodError when there is no more superclass"
|
188
185
|
fails "Module#prepend works with subclasses"
|
189
|
-
fails "Module#prepended is invoked when self is prepended to another module or class"
|
190
186
|
fails "Module#prepend_features copies own tainted status to the given module"
|
191
187
|
fails "Module#prepend_features copies own untrusted status to the given module"
|
192
188
|
fails "Module#prepend_features gets called when self is included in another module/class"
|
193
189
|
fails "Module#prepend_features on Class raises a TypeError if calling after rebinded to Class"
|
194
190
|
fails "Module#prepend_features raises an ArgumentError on a cyclic prepend"
|
191
|
+
fails "Module#prepended is invoked when self is prepended to another module or class"
|
192
|
+
fails "Module#private without arguments within a closure sets the visibility outside the closure"
|
193
|
+
fails "Module#protected without arguments within a closure sets the visibility outside the closure"
|
195
194
|
fails "Module#remove_class_variable raises a NameError when an uninitialized class variable is given"
|
196
195
|
fails "Module#remove_class_variable raises a NameError when passed a symbol with no leading @"
|
197
196
|
fails "Module#remove_class_variable raises a NameError when passed a symbol with one leading @"
|
data/spec/filters/bugs/regexp.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
opal_filter "regular_expressions" do
|
2
|
-
fails "Regexp#=== returns false if the other value cannot be coerced to a string"
|
3
2
|
fails "Regexp#hash is based on the text and options of Regexp"
|
4
3
|
fails "Regexp#hash returns the same value for two Regexps differing only in the /n option"
|
5
4
|
fails "Regexp#initialize is a private method"
|
@@ -12,8 +11,6 @@ opal_filter "regular_expressions" do
|
|
12
11
|
fails "Regexp#inspect escapes 2 slashes in a row properly"
|
13
12
|
fails "Regexp#inspect returns a formatted string that would eval to the same regexp"
|
14
13
|
fails "Regexp#inspect returns options in the order 'mixn'"
|
15
|
-
fails "Regexp#match raises a TypeError on an uninitialized Regexp"
|
16
|
-
fails "Regexp#options returns 0 for a Regexp literal without options"
|
17
14
|
fails "Regexp#source returns the original string of the pattern"
|
18
15
|
fails "Regexp#to_s deals properly with the two types of lookahead groups"
|
19
16
|
fails "Regexp#to_s returns a string in (?xxx:yyy) notation"
|
data/spec/filters/bugs/set.rb
CHANGED
@@ -27,10 +27,6 @@ opal_filter "Set" do
|
|
27
27
|
fails "Set#merge raises an ArgumentError when passed a non-Enumerable"
|
28
28
|
fails "Set#pretty_print passes the 'pretty print' representation of self to the pretty print writer"
|
29
29
|
fails "Set#pretty_print_cycle passes the 'pretty print' representation of a self-referencing Set to the pretty print writer"
|
30
|
-
fails "Set#proper_subset? raises an ArgumentError when passed a non-Set"
|
31
|
-
fails "Set#proper_subset? returns true if passed a Set that self is a proper subset of"
|
32
|
-
fails "Set#proper_superset? raises an ArgumentError when passed a non-Set"
|
33
|
-
fails "Set#proper_superset? returns true if passed a Set that self is a proper superset of"
|
34
30
|
fails "Set#reject! deletes every element from self for which the passed block returns true"
|
35
31
|
fails "Set#reject! returns an Enumerator when passed no block"
|
36
32
|
fails "Set#reject! returns nil when self was not modified"
|
@@ -41,10 +37,6 @@ opal_filter "Set" do
|
|
41
37
|
fails "Set#select! returns nil when self was not modified"
|
42
38
|
fails "Set#select! returns self when self was modified"
|
43
39
|
fails "Set#select! yields every element of self"
|
44
|
-
fails "Set#subset? raises an ArgumentError when passed a non-Set"
|
45
|
-
fails "Set#subset? returns true if passed a Set that is equal to self or self is a subset of"
|
46
|
-
fails "Set#superset? raises an ArgumentError when passed a non-Set"
|
47
|
-
fails "Set#superset? returns true if passed a Set that equals self or self is a proper superset of"
|
48
40
|
fails "Set#^ raises an ArgumentError when passed a non-Enumerable"
|
49
41
|
fails "Set#^ returns a new Set containing elements that are not in both self and the passed Enumberable"
|
50
42
|
end
|
data/spec/filters/bugs/struct.rb
CHANGED
@@ -11,9 +11,9 @@ opal_filter "Struct" do
|
|
11
11
|
fails "Struct.new does not create a constant with symbol as first argument"
|
12
12
|
fails "Struct.new fails with invalid constant name as first argument"
|
13
13
|
fails "Struct.new fails with too many arguments"
|
14
|
+
fails "Struct.new on subclasses creates a constant in subclass' namespace"
|
15
|
+
fails "Struct.new on subclasses fails with too many arguments"
|
14
16
|
fails "Struct.new raises a TypeError if object doesn't respond to to_sym"
|
15
17
|
fails "Struct.new raises a TypeError if object is not a Symbol"
|
16
|
-
fails "Struct.new on subclasses fails with too many arguments"
|
17
|
-
fails "Struct.new on subclasses creates a constant in subclass' namespace"
|
18
18
|
fails "Struct.new with a block passes same struct class to the block"
|
19
19
|
end
|
@@ -8,6 +8,7 @@ opal_filter "Bignum" do
|
|
8
8
|
fails "Complex#rect returns an Array"
|
9
9
|
fails "Complex#rect returns the imaginary part of self as the last element"
|
10
10
|
fails "Complex#rect returns the real part of self as the first element"
|
11
|
+
fails "Enumerable#first raises a RangeError when passed a Bignum"
|
11
12
|
fails "Fixnum#& returns self bitwise AND a Bignum"
|
12
13
|
fails "Fixnum#& returns self bitwise AND other"
|
13
14
|
fails "Fixnum#* overflows to Bignum when the result does not fit in Fixnum"
|
@@ -6,6 +6,13 @@ opal_filter "language" do
|
|
6
6
|
fails "Magic comment is case-insensitive"
|
7
7
|
fails "Magic comment must be at the first line"
|
8
8
|
fails "Magic comment must be the first token of the line"
|
9
|
+
fails "Regexps with modifers supports /x (extended syntax)"
|
10
|
+
fails "Regexps with modifers supports /o (once)"
|
11
|
+
fails "Regexps with modifers invokes substitutions for /o only once"
|
12
|
+
fails "Regexps with modifers supports modifier combinations"
|
13
|
+
fails "Regexps with modifers supports (?imx-imx) (inline modifiers)"
|
14
|
+
fails "Regexps with modifers supports (?imx-imx:expr) (scoped inline modifiers)"
|
15
|
+
fails "Regexps with modifers supports ASII/Unicode modifiers"
|
9
16
|
fails "The defined? keyword for pseudo-variables returns 'expression' for __ENCODING__"
|
10
17
|
fails "The defined? keyword when called with a method name having a module as receiver returns nil if the method is private"
|
11
18
|
fails "The defined? keyword when called with a method name having a module as receiver returns nil if the method is protected"
|
data/spec/lib/compiler_spec.rb
CHANGED
@@ -51,6 +51,11 @@ describe Opal::Compiler do
|
|
51
51
|
expect_compiled("Object").to include("Object")
|
52
52
|
expect_compiled("Array").to include("Array")
|
53
53
|
end
|
54
|
+
|
55
|
+
it "should compile undef calls" do
|
56
|
+
expect_compiled("undef a").to include("Opal.udef(self, '$a')")
|
57
|
+
expect_compiled("undef a,b").to match(/Opal.udef\(self, '\$a'\);.*return Opal.udef\(self, '\$b'\);/m)
|
58
|
+
end
|
54
59
|
|
55
60
|
describe "class names" do
|
56
61
|
it "generates a named function for class using $ prefix" do
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
describe 'Opal.use_gem' do
|
4
|
+
it 'adds require_paths of a gem to Opal paths' do
|
5
|
+
Opal.use_gem 'sprockets'
|
6
|
+
# Will fail if GEM_HOME has "sprockets" in the path, that's ok.
|
7
|
+
added_sprockets_paths = Opal.paths.grep /sprockets/
|
8
|
+
expect(added_sprockets_paths.size).to eq(1)
|
9
|
+
expect(added_sprockets_paths.first).to match(%r{/sprockets-[\d\.]+/lib$})
|
10
|
+
end
|
11
|
+
end
|
data/spec/lib/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ RSpec.configure do |config|
|
|
5
5
|
config.run_all_when_everything_filtered = true
|
6
6
|
config.filter_run :focus
|
7
7
|
config.order = 'random'
|
8
|
-
config.before { Opal.
|
8
|
+
config.before { Opal.reset_paths! }
|
9
9
|
config.before { Opal::Config.reset! if defined? Opal::Config }
|
10
10
|
config.before { Opal::Processor.reset_cache_key! if defined? Opal::Processor }
|
11
11
|
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# This spec has been copied over from rubyspec and modified to avoid the use
|
2
|
+
# of instance_eval with a String argument and also because some syntaxes are
|
3
|
+
# not suppoted yet by Opal (e.g. def a(b, *c, d)).
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe "UnboundMethod#arity" do
|
8
|
+
context "returns zero" do
|
9
|
+
|
10
|
+
def self.evaluate_in_module message, &block
|
11
|
+
it message do
|
12
|
+
Module.new do
|
13
|
+
def self.arity_of(method_name)
|
14
|
+
instance_method(method_name).arity
|
15
|
+
end
|
16
|
+
end.class_eval(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
evaluate_in_module "for m()" do
|
21
|
+
arity_of(def m() end).should == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
evaluate_in_module "for n(&b)" do
|
25
|
+
arity_of(def n(&b) end).should == 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "returns positive values," do
|
30
|
+
evaluate_in_module "the number of args for simple args" do
|
31
|
+
arity_of(def m(a) end).should == 1
|
32
|
+
arity_of(def n(a, b) end).should == 2
|
33
|
+
arity_of(def o(a, b, c) end).should == 3
|
34
|
+
arity_of(def p(a, b, c, d) end).should == 4
|
35
|
+
end
|
36
|
+
|
37
|
+
ruby_version_is "2.1" do
|
38
|
+
evaluate_in_module "1 for kwargs" do
|
39
|
+
arity_of(def m(a:) end).should == 1
|
40
|
+
arity_of(def n(a:, b:) end).should == 1
|
41
|
+
arity_of(def o(a: 1, b:, c:, d: 2) end).should == 1
|
42
|
+
end
|
43
|
+
|
44
|
+
evaluate_in_module __LINE__ do
|
45
|
+
arity_of(def m(a, b:) end).should == 2
|
46
|
+
arity_of(def n(a, b:, &l) end).should == 2
|
47
|
+
end
|
48
|
+
|
49
|
+
evaluate_in_module __LINE__ do
|
50
|
+
arity_of(def m(a, b, c:, d: 1) end).should == 3
|
51
|
+
arity_of(def n(a, b, c:, d: 1, **k, &l) end).should == 3
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "returns negative values" do
|
57
|
+
# evaluate_in_module __LINE__ do
|
58
|
+
# arity_of(def m(a=1) end).should == -1
|
59
|
+
# arity_of(def n(a=1, b=2) end).should == -1
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# evaluate_in_module __LINE__ do
|
63
|
+
# arity_of(def m(a, b=1) end).should == -2
|
64
|
+
# arity_of(def n(a, b, c=1, d=2) end).should == -3
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# evaluate_in_module __LINE__ do
|
68
|
+
# arity_of(def m(a=1, *b) end).should == -1
|
69
|
+
# arity_of(def n(a=1, b=2, *c) end).should == -1
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# evaluate_in_module __LINE__ do
|
73
|
+
# arity_of(def m(*) end).should == -1
|
74
|
+
# arity_of(def n(*a) end).should == -1
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# evaluate_in_module __LINE__ do
|
78
|
+
# arity_of(def m(a, *) end).should == -2
|
79
|
+
# arity_of(def n(a, *b) end).should == -2
|
80
|
+
# arity_of(def o(a, b, *c) end).should == -3
|
81
|
+
# arity_of(def p(a, b, c, *d) end).should == -4
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# evaluate_in_module __LINE__ do
|
85
|
+
# arity_of(def m(*a, b) end).should == -2
|
86
|
+
# arity_of(def n(*a, b, c) end).should == -3
|
87
|
+
# arity_of(def o(*a, b, c, d) end).should == -4
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# evaluate_in_module __LINE__ do
|
91
|
+
# arity_of(def m(a, *b, c) end).should == -3
|
92
|
+
# arity_of(def n(a, b, *c, d, e) end).should == -5
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# evaluate_in_module __LINE__ do
|
96
|
+
# arity_of(def m(a, b=1, c=2, *d, e, f) end).should == -4
|
97
|
+
# arity_of(def n(a, b, c=1, *d, e, f, g) end).should == -6
|
98
|
+
# end
|
99
|
+
|
100
|
+
# ruby_version_is "2.1" do
|
101
|
+
# evaluate_in_module __LINE__ do
|
102
|
+
# arity_of(def m(a: 1) end).should == -1
|
103
|
+
# arity_of(def n(a: 1, b: 2) end).should == -1
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# evaluate_in_module __LINE__ do
|
108
|
+
# arity_of(def m(a=1, b: 2) end).should == -1
|
109
|
+
# # arity_of(def n(*a, b: 1) end).should == -1
|
110
|
+
# arity_of(def o(a=1, b: 2) end).should == -1
|
111
|
+
# # arity_of(def p(a=1, *b, c: 2, &l) end).should == -1
|
112
|
+
# end
|
113
|
+
|
114
|
+
ruby_version_is "2.1" do
|
115
|
+
# evaluate_in_module __LINE__ do
|
116
|
+
# arity_of(def m(**k, &l) end).should == -1
|
117
|
+
# arity_of(def n(*a, **k) end).should == -1
|
118
|
+
# arity_of(def o(a: 1, b: 2, **k) end).should == -1
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# evaluate_in_module __LINE__ do
|
122
|
+
# arity_of(def m(a=1, *b, c:, d: 2, **k, &l) end).should == -2
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# evaluate_in_module __LINE__ do
|
126
|
+
# arity_of(def m(a, b=1, *c, d, e:, f: 2, **k, &l) end).should == -4
|
127
|
+
# arity_of(def n(a, b=1, *c, d:, e:, f: 2, **k, &l) end).should == -3
|
128
|
+
# arity_of(def o(a=0, b=1, *c, d, e:, f: 2, **k, &l) end).should == -3
|
129
|
+
# arity_of(def p(a=0, b=1, *c, d:, e:, f: 2, **k, &l) end).should == -2
|
130
|
+
# end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# context "for a Method generated by respond_to_missing?" do
|
135
|
+
# it "returns -1" do
|
136
|
+
# obj = mock("method arity respond_to_missing")
|
137
|
+
# obj.should_receive(:respond_to_missing?).and_return(true)
|
138
|
+
#
|
139
|
+
# obj.method(:m).unbind.arity.should == -1
|
140
|
+
# end
|
141
|
+
# end
|
142
|
+
end
|
data/spec/rubyspecs
CHANGED
@@ -125,6 +125,7 @@ rubyspec/language
|
|
125
125
|
!rubyspec/language/predefined_spec
|
126
126
|
!rubyspec/language/proc_spec
|
127
127
|
!rubyspec/language/regexp_spec
|
128
|
+
rubyspec/language/regexp/modifiers_spec
|
128
129
|
!rubyspec/language/return_spec
|
129
130
|
!rubyspec/language/send_spec
|
130
131
|
!rubyspec/language/string_spec
|
data/stdlib/json.rb
CHANGED
@@ -4,6 +4,8 @@ module JSON
|
|
4
4
|
$hasOwn = Opal.hasOwnProperty;
|
5
5
|
|
6
6
|
function to_opal(value, options) {
|
7
|
+
var klass, arr, hash, i, ii, k;
|
8
|
+
|
7
9
|
switch (typeof value) {
|
8
10
|
case 'string':
|
9
11
|
return value;
|
@@ -21,25 +23,24 @@ module JSON
|
|
21
23
|
if (!value) return nil;
|
22
24
|
|
23
25
|
if (value.$$is_array) {
|
24
|
-
|
26
|
+
arr = #{`options.array_class`.new};
|
25
27
|
|
26
|
-
for (
|
28
|
+
for (i = 0, ii = value.length; i < ii; i++) {
|
27
29
|
#{`arr`.push(`to_opal(value[i], options)`)};
|
28
30
|
}
|
29
31
|
|
30
32
|
return arr;
|
31
33
|
}
|
32
34
|
else {
|
33
|
-
|
35
|
+
hash = #{`options.object_class`.new};
|
34
36
|
|
35
|
-
for (
|
37
|
+
for (k in value) {
|
36
38
|
if ($hasOwn.call(value, k)) {
|
37
39
|
#{`hash`[`k`] = `to_opal(value[k], options)`};
|
38
40
|
}
|
39
41
|
}
|
40
42
|
|
41
|
-
|
42
|
-
if ((klass = #{`hash`[JSON.create_id]}) != nil) {
|
43
|
+
if (!options.parse && (klass = #{`hash`[JSON.create_id]}) != nil) {
|
43
44
|
klass = Opal.get(klass);
|
44
45
|
return #{`klass`.json_create(`hash`)};
|
45
46
|
}
|
@@ -47,7 +48,7 @@ module JSON
|
|
47
48
|
return hash;
|
48
49
|
}
|
49
50
|
}
|
50
|
-
|
51
|
+
}
|
51
52
|
};
|
52
53
|
}
|
53
54
|
|
@@ -66,13 +67,17 @@ module JSON
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def self.parse(source, options = {})
|
69
|
-
from_object(`$parse(source)`, options)
|
70
|
+
from_object(`$parse(source)`, options.merge(parse: true))
|
70
71
|
end
|
71
72
|
|
72
73
|
def self.parse!(source, options = {})
|
73
74
|
parse(source, options)
|
74
75
|
end
|
75
76
|
|
77
|
+
def self.load(source, options = {})
|
78
|
+
from_object(`$parse(source)`, options)
|
79
|
+
end
|
80
|
+
|
76
81
|
# Raw js object => opal object
|
77
82
|
def self.from_object(js_object, options = {})
|
78
83
|
options[:object_class] ||= Hash
|
data/stdlib/native.rb
CHANGED
@@ -601,7 +601,7 @@ class Class
|
|
601
601
|
%x{
|
602
602
|
var aliased = #{self}.$$proto['$' + #{existing_mid}];
|
603
603
|
if (!aliased) {
|
604
|
-
#{raise NameError
|
604
|
+
#{raise NameError.new("undefined method `#{existing_mid}' for class `#{inspect}'", exiting_mid)};
|
605
605
|
}
|
606
606
|
#{self}.$$proto[#{new_jsid}] = aliased;
|
607
607
|
}
|
data/stdlib/observer.rb
CHANGED
@@ -126,7 +126,7 @@ module Observable
|
|
126
126
|
def add_observer(observer, func=:update)
|
127
127
|
@observer_peers = {} unless defined? @observer_peers
|
128
128
|
unless observer.respond_to? func
|
129
|
-
raise NoMethodError
|
129
|
+
raise NoMethodError.new("observer does not respond to `#{func.to_s}'", func.to_s)
|
130
130
|
end
|
131
131
|
@observer_peers[observer] = func
|
132
132
|
end
|