opal 1.8.0.beta1 → 1.8.1
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 +150 -1
- data/UNRELEASED.md +1 -92
- data/lib/opal/nodes/args/parameters.rb +18 -11
- data/lib/opal/nodes/args.rb +0 -28
- data/lib/opal/nodes/super.rb +0 -9
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/deduplicate_arg_name.rb +48 -0
- data/lib/opal/rewriters/inline_args.rb +1 -13
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/array.rb +26 -22
- data/opal/corelib/constants.rb +2 -2
- data/opal/corelib/hash.rb +6 -2
- data/opal/corelib/kernel.rb +11 -14
- data/opal/corelib/method.rb +1 -0
- data/opal/corelib/module.rb +43 -22
- data/opal/corelib/proc.rb +4 -6
- data/opal/corelib/range.rb +54 -10
- data/opal/corelib/runtime.js +40 -31
- data/spec/filters/bugs/array.rb +0 -36
- data/spec/filters/bugs/cgi.rb +40 -0
- data/spec/filters/bugs/enumerable.rb +1 -3
- data/spec/filters/bugs/kernel.rb +6 -9
- data/spec/filters/bugs/method.rb +0 -3
- data/spec/filters/bugs/module.rb +1 -10
- data/spec/filters/bugs/range.rb +2 -16
- data/spec/filters/bugs/ruby-32.rb +2 -2
- data/spec/filters/unsupported/kernel.rb +0 -4
- data/spec/opal/core/language/arguments/underscore_arg_spec.rb +89 -0
- data/spec/opal/core/module/define_method_spec.rb +29 -0
- data/spec/ruby_specs +1 -0
- data/stdlib/cgi/util.rb +89 -0
- data/stdlib/cgi.rb +1 -14
- metadata +15 -8
data/spec/filters/bugs/kernel.rb
CHANGED
@@ -36,7 +36,6 @@ opal_filter "Kernel" do
|
|
36
36
|
fails "Kernel#class returns the class of the object" # Expected Number to be identical to Integer
|
37
37
|
fails "Kernel#clone replaces a singleton object's metaclass with a new copy with the same superclass" # NoMethodError: undefined method `singleton_methods' for #<#<Class:0x5537a>:0x55378>
|
38
38
|
fails "Kernel#clone uses the internal allocator and does not call #allocate" # RuntimeError: allocate should not be called
|
39
|
-
fails "Kernel#define_singleton_method when given an UnboundMethod will raise when attempting to define an object's singleton method from another object's singleton method" # Expected TypeError but no exception was raised ("other_singleton_method" was returned)
|
40
39
|
fails "Kernel#dup uses the internal allocator and does not call #allocate" # RuntimeError: allocate should not be called
|
41
40
|
fails "Kernel#eval allows a binding to be captured inside an eval" # NoMethodError: undefined method `w' for #<MSpecEnv:0x4be5a>
|
42
41
|
fails "Kernel#eval allows creating a new class in a binding" # RuntimeError: Evaluation on a Proc#binding is not supported
|
@@ -353,14 +352,12 @@ opal_filter "Kernel" do
|
|
353
352
|
fails "Kernel.printf formatting io is not specified other formats c tries to convert argument to Integer with to_int" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x4080e>
|
354
353
|
fails "Kernel.printf formatting io is not specified other formats c tries to convert argument to String with to_str" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x40800>
|
355
354
|
fails "Kernel.printf formatting io is not specified other formats s preserves encoding of the format string" # Expected #<Encoding:UTF-8> == #<Encoding:US-ASCII> to be truthy but was false
|
356
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is nil" # Expected TypeError (/no implicit conversion from nil to integer/) but got:
|
357
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is not String or Integer and cannot be converted to them" # Expected TypeError (/no implicit conversion of Array into Integer/) but got:
|
358
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to Integer with to_int returns non-Integer" # Expected TypeError (/can't convert BasicObject to
|
359
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to String with to_str returns non-String" # Expected TypeError (/can't convert BasicObject to String/) but got:
|
360
|
-
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to Integer with to_int" #
|
361
|
-
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to String with to_str" #
|
362
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with precision" # Exception: format_string.indexOf is not a function
|
363
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with width" # Exception: format_string.indexOf is not a function
|
355
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is nil" # Expected TypeError (/no implicit conversion from nil to integer/) but got: TypeError (no implicit conversion of NilClass into Integer)
|
356
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is not String or Integer and cannot be converted to them" # Expected TypeError (/no implicit conversion of Array into Integer/) but got: ArgumentError (too few arguments)
|
357
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to Integer with to_int returns non-Integer" # Expected TypeError (/can't convert BasicObject to Integer/) but got: NoMethodError (undefined method `respond_to?' for #<BasicObject:0x69e>)
|
358
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to String with to_str returns non-String" # Expected TypeError (/can't convert BasicObject to String/) but got: NoMethodError (undefined method `respond_to?' for #<BasicObject:0x6cc>)
|
359
|
+
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to Integer with to_int" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6a8>
|
360
|
+
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to String with to_str" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6c2>
|
364
361
|
fails "Kernel.printf formatting io is specified other formats s preserves encoding of the format string" # Expected #<Encoding:UTF-8> == #<Encoding:US-ASCII> to be truthy but was false
|
365
362
|
fails "Kernel.printf writes to stdout when a string is the first argument" # NoMethodError: undefined method `tmp' for #<MSpecEnv:0x4046a @name=nil @stdout=#<IO:0xa @fd=1 @flags="w" @eof=false @closed="both" @write_proc=#<Proc:0x40474> @tty=true>>
|
366
363
|
fails "Kernel.proc returned the passed Proc if given an existing Proc" # Expected false to be true
|
data/spec/filters/bugs/method.rb
CHANGED
@@ -27,8 +27,6 @@ opal_filter "Method" do
|
|
27
27
|
fails "Method#curry with optional arity argument raises ArgumentError when the method requires less arguments than the given arity" # Expected ArgumentError but no exception was raised (#<Proc:0x7c68a> was returned)
|
28
28
|
fails "Method#curry with optional arity argument raises ArgumentError when the method requires more arguments than the given arity" # Expected ArgumentError but no exception was raised (#<Proc:0x7c66a> was returned)
|
29
29
|
fails "Method#define_method when passed a Proc object and a method is defined inside defines the nested method in the default definee where the Proc was created" # Expected #<#<Class:0x51aa0>:0x51a9c> NOT to have method 'nested_method_in_proc_for_define_method' but it does
|
30
|
-
fails "Method#define_method when passed an UnboundMethod object defines a method with the same #arity as the original" # Expected -1 == -3 to be truthy but was false
|
31
|
-
fails "Method#define_method when passed an UnboundMethod object defines a method with the same #parameters as the original" # Expected [["rest", "args"]] == [["req", "a"], ["req", "b"], ["rest", "c"]] to be truthy but was false
|
32
30
|
fails "Method#eql? missing methods returns true for the same method missing" # NameError: undefined method `handled_via_method_missing' for class `MethodSpecs::Methods'
|
33
31
|
fails "Method#eql? returns true if a method was defined using the other one" # Expected false to be true
|
34
32
|
fails "Method#eql? returns true if methods are the same" # Expected false to be true
|
@@ -54,7 +52,6 @@ opal_filter "Method" do
|
|
54
52
|
fails "Method#source_location for a Method generated by respond_to_missing? returns nil" # NameError: undefined method `handled_via_method_missing' for class `MethodSpecs::Methods'
|
55
53
|
fails "Method#source_location sets the first value to the path of the file in which the method was defined" # Expected "ruby/core/method/fixtures/classes.rb" == "./ruby/core/method/fixtures/classes.rb" to be truthy but was false
|
56
54
|
fails "Method#source_location works for eval with a given line" # Expected ["(eval)", 0] == ["foo", 100] to be truthy but was false
|
57
|
-
fails "Method#source_location works for methods defined with an UnboundMethod" # Expected "<internal:corelib/module.rb>" =~ /ruby\/core\/method\/source_location_spec.rb/ to be truthy but was nil
|
58
55
|
fails "Method#super_method after aliasing an inherited method returns the expected super_method" # NoMethodError: undefined method `super_method' for #<Method: MethodSpecs::InheritedMethods::C#meow (defined in MethodSpecs::InheritedMethods::C in ruby/core/method/fixtures/classes.rb:233)>
|
59
56
|
fails "Method#super_method after changing an inherited methods visibility returns the expected super_method" # NoMethodError: undefined method `super_method' for #<Method: MethodSpecs::InheritedMethods::C#derp (defined in MethodSpecs::InheritedMethods::B in ruby/core/method/fixtures/classes.rb:233)>
|
60
57
|
fails "Method#super_method returns nil when the parent's method is removed" # NoMethodError: undefined method `super_method' for #<Method: #<Class:0x50682>#overridden (defined in #<Class:0x50682> in ruby/core/method/super_method_spec.rb:36)>
|
data/spec/filters/bugs/module.rb
CHANGED
@@ -87,18 +87,9 @@ opal_filter "Module" do
|
|
87
87
|
fails "Module#const_source_location works for eval with a given line" # NoMethodError: undefined method `const_source_location' for #<Class:0x2f66a>
|
88
88
|
fails "Module#constants doesn't returns inherited constants when passed nil" # Expected ["CS_CONST10", "CS_CONST10_LINE", "CS_CONST23", "CS_CONST24", "CS_CONST5", "ChildA"] == ["CS_CONST10", "CS_CONST10_LINE", "CS_CONST23", "CS_CONST5", "ChildA"] to be truthy but was false
|
89
89
|
fails "Module#constants returns only public constants" # Expected ["PRIVATE_CONSTANT", "PUBLIC_CONSTANT"] == ["PUBLIC_CONSTANT"] to be truthy but was false
|
90
|
-
fails "Module#define_method converts non-String name to String with #to_str" # NoMethodError: undefined method `foo' for #<#<Class:0x33ce6>:0x33ce4>
|
91
90
|
fails "Module#define_method defines the new method according to the scope visibility when a Method passed and the class/module of the context is equal to the receiver of #define_method" # Expected NoMethodError but no exception was raised (nil was returned)
|
92
91
|
fails "Module#define_method passed { |a,| } creates a method that does not destructure the passed argument" # Expected [1, 2] == 1 to be truthy but was false
|
93
|
-
fails "Module#define_method raises TypeError
|
94
|
-
fails "Module#define_method raises TypeError when #to_str called on non-String name returns non-String value" # Expected TypeError (/can't convert Object to String/) but no exception was raised (#<Class:0x33d52> was returned)
|
95
|
-
fails "Module#define_method raises a TypeError when a Method from a singleton class is defined on another class" # Expected TypeError (/can't bind singleton method to a different class/) but no exception was raised (#<Class:0x33cdc> was returned)
|
96
|
-
fails "Module#define_method raises a TypeError when a Method from one class is defined on an unrelated class" # Expected TypeError but no exception was raised (#<Class:0x33d6c> was returned)
|
97
|
-
fails "Module#define_method raises a TypeError when an UnboundMethod from a child class is defined on a parent class" # Expected TypeError (/bind argument must be a subclass of ChildClass/) but no exception was raised ("foo" was returned)
|
98
|
-
fails "Module#define_method raises a TypeError when an UnboundMethod from a singleton class is defined on another class" # Expected TypeError (/can't bind singleton method to a different class/) but no exception was raised (#<Class:0x33cac> was returned)
|
99
|
-
fails "Module#define_method raises a TypeError when an UnboundMethod from one class is defined on an unrelated class" # Expected TypeError (/bind argument must be a subclass of ModuleSpecs::InstanceMeth/) but no exception was raised (DestinationClass was returned)
|
100
|
-
fails "Module#define_method raises a TypeError when the given method is no Method/Proc" # Expected TypeError (wrong argument type String (expected Proc/Method/UnboundMethod)) but got: TypeError (wrong argument type NilClass (expected Proc/Method))
|
101
|
-
fails "Module#define_method uses provided Method/Proc even if block is specified" # Expected "block_is_called" == "method_is_called" to be truthy but was false
|
92
|
+
fails "Module#define_method raises a TypeError when the given method is no Method/Proc" # Expected TypeError (wrong argument type Integer (expected Proc/Method/UnboundMethod)) but got: TypeError (wrong argument type Number (expected Proc/Method/UnboundMethod))
|
102
93
|
fails "Module#deprecate_constant accepts multiple symbols and strings as constant names" # NoMethodError: undefined method `deprecate_constant' for #<Module:0x3bf08>
|
103
94
|
fails "Module#deprecate_constant raises a NameError when given an undefined name" # NoMethodError: undefined method `deprecate_constant' for #<Module:0x3bf04>
|
104
95
|
fails "Module#deprecate_constant returns self" # NoMethodError: undefined method `deprecate_constant' for #<Module:0x3bf0c>
|
data/spec/filters/bugs/range.rb
CHANGED
@@ -50,22 +50,12 @@ opal_filter "Range" do
|
|
50
50
|
fails "Range#bsearch with endless ranges and Integer values with a block returning negative, zero, positive numbers returns nil if the block returns less than zero for every element" # NotImplementedError: Can't #bsearch an infinite range
|
51
51
|
fails "Range#bsearch with endless ranges and Integer values with a block returning true or false returns minimum element if the block returns true for every element" # NotImplementedError: Can't #bsearch an infinite range
|
52
52
|
fails "Range#bsearch with endless ranges and Integer values with a block returning true or false returns the smallest element for which block returns true" # NotImplementedError: Can't #bsearch an infinite range
|
53
|
-
fails "Range#cover?
|
54
|
-
fails "Range#cover? accepts endless range argument" # Expected false to be true
|
55
|
-
fails "Range#cover? allows self to be a beginless range" # Expected false to be true
|
56
|
-
fails "Range#cover? allows self to be a endless range" # Expected false to be true
|
57
|
-
fails "Range#cover? range argument accepts range argument" # Expected false to be true
|
58
|
-
fails "Range#cover? range argument honors exclusion of right boundary (:exclude_end option)" # Expected false to be true
|
59
|
-
fails "Range#cover? range argument supports boundaries of different comparable types" # Expected false to be true
|
53
|
+
fails "Range#cover? range argument honors exclusion of right boundary (:exclude_end option)" # Expected true to be false
|
60
54
|
fails "Range#eql? returns false if the endpoints are not eql?" # Expected 0..1 not to have same value or type as 0..1
|
61
55
|
fails "Range#first raises a TypeError if #to_int does not return an Integer" # Expected TypeError but no exception was raised ([2] was returned)
|
62
56
|
fails "Range#frozen? is true for Range.new" # Expected 1..2.frozen? to be truthy but was false
|
63
57
|
fails "Range#frozen? is true for literal ranges" # Expected 1..2.frozen? to be truthy but was false
|
64
58
|
fails "Range#include? does not include U+9995 in the range U+0999..U+9999" # Expected true to be false
|
65
|
-
fails "Range#include? on string elements returns false if other is not matched by element.succ" # Expected true to be false
|
66
|
-
fails "Range#include? with weird succ when excluded end value returns false if other is not matched by element.succ" # Expected true to be false
|
67
|
-
fails "Range#include? with weird succ when included end value returns false if other is equal as last element but not matched by element.succ" # Expected true to be false
|
68
|
-
fails "Range#include? with weird succ when included end value returns false if other is not matched by element.succ" # Expected true to be false
|
69
59
|
fails "Range#initialize raises a FrozenError if called on an already initialized Range" # Expected FrozenError but got: NameError ('initialize' called twice)
|
70
60
|
fails "Range#inspect works for nil ... nil ranges" # Expected ".." == "nil..nil" to be truthy but was false
|
71
61
|
fails "Range#last raises a TypeError if #to_int does not return an Integer" # Expected TypeError but no exception was raised ([3] was returned)
|
@@ -75,10 +65,6 @@ opal_filter "Range" do
|
|
75
65
|
fails "Range#max raises TypeError when called on an exclusive range and a non Integer value" # Expected TypeError but no exception was raised (907.1111 was returned)
|
76
66
|
fails "Range#max raises for an exclusive beginless range" # Expected TypeError (cannot exclude end value with non Integer begin value) but no exception was raised (0 was returned)
|
77
67
|
fails "Range#max returns the maximum value in the range when called with no arguments" # Expected NaN == "e" to be truthy but was false
|
78
|
-
fails "Range#member? on string elements returns false if other is not matched by element.succ" # Expected true to be false
|
79
|
-
fails "Range#member? with weird succ when excluded end value returns false if other is not matched by element.succ" # Expected true to be false
|
80
|
-
fails "Range#member? with weird succ when included end value returns false if other is equal as last element but not matched by element.succ" # Expected true to be false
|
81
|
-
fails "Range#member? with weird succ when included end value returns false if other is not matched by element.succ" # Expected true to be false
|
82
68
|
fails "Range#min given a block calls #> and #< on the return value of the block" # Mock 'obj' expected to receive >("any_args") exactly 2 times but received it 0 times
|
83
69
|
fails "Range#minmax on an exclusive range raises TypeError if the end value is not an integer" # Expected TypeError (cannot exclude non Integer end value) but got: TypeError (can't iterate from Float)
|
84
70
|
fails "Range#minmax on an exclusive range should raise RangeError on a beginless range" # Expected RangeError (/cannot get the maximum of beginless range with custom comparison method|cannot get the minimum of beginless range/) but got: TypeError (can't iterate from NilClass)
|
@@ -99,7 +85,7 @@ opal_filter "Range" do
|
|
99
85
|
fails "Range#to_a works with Ranges of 64-bit integers" # Expected [256, 257] == [1099511627776, 1099511627777] to be truthy but was false
|
100
86
|
fails "Range#to_s can show beginless ranges" # Expected "...1" == "...1.0" to be truthy but was false
|
101
87
|
fails "Range#to_s can show endless ranges" # Expected "1..." == "1.0..." to be truthy but was false
|
102
|
-
fails "Range.new beginless/endless range creates a frozen range if the class is Range.class" # Expected 1..2.frozen? to be truthy but was false
|
88
|
+
fails "Range.new beginless/endless range creates a frozen range if the class is Range.class" # Expected 1..2.frozen? to be truthy but was false
|
103
89
|
fails_badly "Range#min given a block raises RangeError when called with custom comparison method on an endless range" # Expected RangeError but got: Opal::SyntaxError (undefined method `type' for nil)
|
104
90
|
fails_badly "Range#minmax on an exclusive range should return the minimum and maximum values for a numeric range without iterating the range"
|
105
91
|
fails_badly "Range#step with an endless range and String values raises a TypeError when passed a Float step" # Expected TypeError but got: Opal::SyntaxError (undefined method `type' for nil)
|
@@ -7,8 +7,8 @@ opal_filter "Ruby 3.2" do
|
|
7
7
|
fails "Kernel#sprintf other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
8
8
|
fails "Kernel.printf formatting io is not specified other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
9
9
|
fails "Kernel.printf formatting io is not specified other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
10
|
-
fails "Kernel.printf formatting io is specified other formats c displays no characters if argument is an empty string" #
|
11
|
-
fails "Kernel.printf formatting io is specified other formats c displays only the first character if argument is a string of several characters" #
|
10
|
+
fails "Kernel.printf formatting io is specified other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
11
|
+
fails "Kernel.printf formatting io is specified other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
12
12
|
fails "Kernel.sprintf other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
13
13
|
fails "Kernel.sprintf other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
14
14
|
fails "Keyword arguments delegation does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" # Expected [[], {}] == [[{}], {}] to be truthy but was false
|
@@ -21,8 +21,4 @@ opal_unsupported_filter "Kernel" do
|
|
21
21
|
fails "Kernel#warn is a private method" # Expected Kernel to have private instance method 'warn' but it does not
|
22
22
|
fails "Kernel.Float raises a TypeError if #to_f returns an Integer" # Expected TypeError but no exception was raised (123 was returned)
|
23
23
|
fails "Kernel.lambda when called without a literal block warns when proc isn't a lambda" # Expected warning: "ruby/core/kernel/lambda_spec.rb:142: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n" but got: ""
|
24
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with width and precision" # Exception: format_string.indexOf is not a function
|
25
|
-
fails "Kernel.printf formatting io is specified other formats s formats string with width and precision" # Exception: format_string.indexOf is not a function
|
26
|
-
fails "Kernel.printf formatting io is specified other formats s formats string with width" # Exception: format_string.indexOf is not a function
|
27
|
-
fails "Kernel.printf formatting io is specified other formats s substitutes '' for nil" # Exception: format_string.indexOf is not a function
|
28
24
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe 'duplicated underscore parameter' do
|
2
|
+
it 'assigns the first arg' do
|
3
|
+
klass = Class.new {
|
4
|
+
def req_req(_, _) = _
|
5
|
+
def req_rest_req(_, *, _) = _
|
6
|
+
def rest_req(*_, _) = _
|
7
|
+
def req_opt(_, _ = 0) = _
|
8
|
+
def opt_req(_ = 0, _) = _
|
9
|
+
def req_kwopt(_, _: 0) = _
|
10
|
+
def req_kwrest(_, **_) = _
|
11
|
+
def req_block(_, &_) = _
|
12
|
+
def req_mlhs(_, (_)) = _
|
13
|
+
def mlhs_req((_), _) = _
|
14
|
+
def rest_kw(*_, _:) = _
|
15
|
+
def nested_mlhs(((_), _)) = _
|
16
|
+
def nested_mlhs_rest(((*_, _))) = _
|
17
|
+
}
|
18
|
+
o = klass.new
|
19
|
+
|
20
|
+
o.req_req(1, 2).should == 1
|
21
|
+
o.req_rest_req(1, 2, 3, 4).should == 1
|
22
|
+
o.rest_req(1, 2, 3).should == [1, 2]
|
23
|
+
o.req_opt(1).should == 1
|
24
|
+
o.req_opt(1, 2).should == 1
|
25
|
+
o.opt_req(1).should == 0
|
26
|
+
o.opt_req(1, 2).should == 1
|
27
|
+
o.req_kwopt(1, _: 2).should == 1
|
28
|
+
o.req_kwrest(1, a: 2).should == 1
|
29
|
+
o.req_block(1).should == 1
|
30
|
+
o.req_block(1) {}.should == 1
|
31
|
+
o.req_mlhs(1, [2]).should == 1
|
32
|
+
o.mlhs_req([1], 2).should == 1
|
33
|
+
o.rest_kw(1, 2, _: 3).should == [1, 2]
|
34
|
+
o.nested_mlhs([[1], 2]).should == 1
|
35
|
+
o.nested_mlhs_rest([[1, 2, 3]]).should == [1, 2]
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'in block parameters' do
|
39
|
+
it 'assignes the first arg' do
|
40
|
+
proc { |_, _| _ }.call(1, 2).should == 1
|
41
|
+
proc { |_, *_| _ }.call(1, 2, 3).should == 1
|
42
|
+
proc { |*_, _| _ }.call(1, 2, 3).should == [1, 2]
|
43
|
+
proc { |_, _:| _ }.call(1, _: 2).should == 1
|
44
|
+
proc { |**_, &_| _ }.call(a: 1) {}.should == {a: 1}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'distinguishes two arguments starting with _' do
|
49
|
+
klass = Class.new {
|
50
|
+
def foo(_a, _a, _b, _b) = [_a, _b]
|
51
|
+
}
|
52
|
+
o = klass.new
|
53
|
+
o.foo(1, 2, 3, 4).should == [1, 3]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'works with yield' do
|
57
|
+
klass = Class.new {
|
58
|
+
def foo(_, &_) = yield * 2
|
59
|
+
}
|
60
|
+
o = klass.new
|
61
|
+
o.foo(1) { 2 }.should == 4
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'works with block_given?' do
|
65
|
+
klass = Class.new {
|
66
|
+
def foo(_, &_) = block_given?
|
67
|
+
}
|
68
|
+
o = klass.new
|
69
|
+
|
70
|
+
o.foo(1).should == false
|
71
|
+
o.foo(1) {}.should == true
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'works with zsuper' do
|
75
|
+
parent = Class.new {
|
76
|
+
def foo(*args, **kwargs, &blk)
|
77
|
+
[args, kwargs, blk.call]
|
78
|
+
end
|
79
|
+
}
|
80
|
+
child = Class.new(parent) {
|
81
|
+
def foo(_, _ = 0, *_, _, _:, **_, &_)
|
82
|
+
super
|
83
|
+
end
|
84
|
+
}
|
85
|
+
o = child.new
|
86
|
+
|
87
|
+
o.foo(1, 2, 3, 4, _: 5, a: 6) { 7 }.should == [[1, 2, 3, 4], {_: 5, a: 6}, 7]
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Module#define_method" do
|
4
|
+
describe "when passed an UnboundMethod object" do
|
5
|
+
it "defines a method taking a block" do
|
6
|
+
klass = Class.new do
|
7
|
+
def foo = yield :bar
|
8
|
+
end
|
9
|
+
klass.define_method(:baz, klass.instance_method(:foo))
|
10
|
+
klass.new.baz { |a| a }.should == :bar
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "when called inside a def" do
|
15
|
+
it "returns correctly" do
|
16
|
+
klass = Class.new do
|
17
|
+
def self.my_method_definer
|
18
|
+
define_method(:a) do
|
19
|
+
return :foo
|
20
|
+
:bar
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
klass.my_method_definer
|
26
|
+
klass.new.a.should == :foo
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/ruby_specs
CHANGED
data/stdlib/cgi/util.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# backtick_javascript: true
|
2
|
+
|
3
|
+
# This file contains parts of https://github.com/ruby/ruby/blob/master/lib/cgi/util.rb
|
4
|
+
# licensed under a Ruby license.
|
5
|
+
|
6
|
+
class CGI
|
7
|
+
module Util
|
8
|
+
# URL-encode a string into application/x-www-form-urlencoded.
|
9
|
+
# Space characters (+" "+) are encoded with plus signs (+"+"+)
|
10
|
+
# url_encoded_string = CGI.escape("'Stop!' said Fred")
|
11
|
+
# # => "%27Stop%21%27+said+Fred"
|
12
|
+
def escape(c)
|
13
|
+
`encodeURI(c)`
|
14
|
+
end
|
15
|
+
|
16
|
+
# URL-decode an application/x-www-form-urlencoded string with encoding(optional).
|
17
|
+
# string = CGI.unescape("%27Stop%21%27+said+Fred")
|
18
|
+
# # => "'Stop!' said Fred"
|
19
|
+
def unescape(c)
|
20
|
+
`decodeURI(c)`
|
21
|
+
end
|
22
|
+
|
23
|
+
# URL-encode a string following RFC 3986
|
24
|
+
# Space characters (+" "+) are encoded with (+"%20"+)
|
25
|
+
# url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred")
|
26
|
+
# # => "%27Stop%21%27%20said%20Fred"
|
27
|
+
def escapeURIComponent(c)
|
28
|
+
`encodeURIComponent(c)`
|
29
|
+
end
|
30
|
+
|
31
|
+
# URL-decode a string following RFC 3986 with encoding(optional).
|
32
|
+
# string = CGI.unescapeURIComponent("%27Stop%21%27+said%20Fred")
|
33
|
+
# # => "'Stop!'+said Fred"
|
34
|
+
def unescapeURIComponent(c)
|
35
|
+
`decodeURIComponent(c)`
|
36
|
+
end
|
37
|
+
|
38
|
+
# The set of special characters and their escaped values
|
39
|
+
TABLE_FOR_ESCAPE_HTML__ = {
|
40
|
+
"'" => ''',
|
41
|
+
'&' => '&',
|
42
|
+
'"' => '"',
|
43
|
+
'<' => '<',
|
44
|
+
'>' => '>',
|
45
|
+
}
|
46
|
+
|
47
|
+
# Escape special characters in HTML, namely '&\"<>
|
48
|
+
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
49
|
+
# # => "Usage: foo "bar" <baz>"
|
50
|
+
def escapeHTML(string)
|
51
|
+
string.gsub(/['&"<>]/, TABLE_FOR_ESCAPE_HTML__)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Unescape a string that has been HTML-escaped
|
55
|
+
# CGI.unescapeHTML("Usage: foo "bar" <baz>")
|
56
|
+
# # => "Usage: foo \"bar\" <baz>"
|
57
|
+
def unescapeHTML(string)
|
58
|
+
string.gsub(/&(apos|amp|quot|gt|lt|\#[0-9]+|\#[xX][0-9A-Fa-f]+);/) do
|
59
|
+
match = ::Regexp.last_match(1)
|
60
|
+
case match
|
61
|
+
when 'apos' then "'"
|
62
|
+
when 'amp' then '&'
|
63
|
+
when 'quot' then '"'
|
64
|
+
when 'gt' then '>'
|
65
|
+
when 'lt' then '<'
|
66
|
+
when /\A#0*(\d+)\z/
|
67
|
+
n = ::Regexp.last_match(1).to_i
|
68
|
+
n.chr('utf-8')
|
69
|
+
when /\A#x([0-9a-f]+)\z/i
|
70
|
+
n = ::Regexp.last_match(1).hex
|
71
|
+
n.chr('utf-8')
|
72
|
+
else
|
73
|
+
"&#{match};"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Synonym for CGI.escapeHTML(str)
|
79
|
+
alias escape_html escapeHTML
|
80
|
+
|
81
|
+
# Synonym for CGI.unescapeHTML(str)
|
82
|
+
alias unescape_html unescapeHTML
|
83
|
+
|
84
|
+
alias h escapeHTML
|
85
|
+
end
|
86
|
+
|
87
|
+
include Util
|
88
|
+
extend Util
|
89
|
+
end
|
data/stdlib/cgi.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ast
|
@@ -602,6 +602,7 @@ files:
|
|
602
602
|
- lib/opal/rewriters/base.rb
|
603
603
|
- lib/opal/rewriters/binary_operator_assignment.rb
|
604
604
|
- lib/opal/rewriters/block_to_iter.rb
|
605
|
+
- lib/opal/rewriters/deduplicate_arg_name.rb
|
605
606
|
- lib/opal/rewriters/dot_js_syntax.rb
|
606
607
|
- lib/opal/rewriters/dump_args.rb
|
607
608
|
- lib/opal/rewriters/for_rewriter.rb
|
@@ -706,6 +707,7 @@ files:
|
|
706
707
|
- spec/filters/bugs/basicobject.rb
|
707
708
|
- spec/filters/bugs/bigdecimal.rb
|
708
709
|
- spec/filters/bugs/binding.rb
|
710
|
+
- spec/filters/bugs/cgi.rb
|
709
711
|
- spec/filters/bugs/class.rb
|
710
712
|
- spec/filters/bugs/complex.rb
|
711
713
|
- spec/filters/bugs/date.rb
|
@@ -908,6 +910,7 @@ files:
|
|
908
910
|
- spec/opal/core/language/DATA/multiple___END___crlf_spec.rb
|
909
911
|
- spec/opal/core/language/DATA/multiple___END___spec.rb
|
910
912
|
- spec/opal/core/language/arguments/mlhs_arg_spec.rb
|
913
|
+
- spec/opal/core/language/arguments/underscore_arg_spec.rb
|
911
914
|
- spec/opal/core/language/case_spec.rb
|
912
915
|
- spec/opal/core/language/forward_args_spec.rb
|
913
916
|
- spec/opal/core/language/if_spec.rb
|
@@ -924,6 +927,7 @@ files:
|
|
924
927
|
- spec/opal/core/language_spec.rb
|
925
928
|
- spec/opal/core/marshal/dump_spec.rb
|
926
929
|
- spec/opal/core/marshal/load_spec.rb
|
930
|
+
- spec/opal/core/module/define_method_spec.rb
|
927
931
|
- spec/opal/core/module_spec.rb
|
928
932
|
- spec/opal/core/number/to_i_spec.rb
|
929
933
|
- spec/opal/core/number/to_s_spec.rb
|
@@ -1013,6 +1017,7 @@ files:
|
|
1013
1017
|
- stdlib/buffer/array.rb
|
1014
1018
|
- stdlib/buffer/view.rb
|
1015
1019
|
- stdlib/cgi.rb
|
1020
|
+
- stdlib/cgi/util.rb
|
1016
1021
|
- stdlib/console.rb
|
1017
1022
|
- stdlib/date.rb
|
1018
1023
|
- stdlib/date/date_time.rb
|
@@ -1225,10 +1230,10 @@ licenses:
|
|
1225
1230
|
metadata:
|
1226
1231
|
homepage_uri: https://opalrb.com/
|
1227
1232
|
bug_tracker_uri: https://github.com/opal/opal/issues
|
1228
|
-
changelog_uri: https://github.com/opal/opal/blob/v1.8.
|
1229
|
-
readme_uri: https://github.com/opal/opal/blob/v1.8.
|
1230
|
-
api_documentation_uri: http://opalrb.com/docs/api/v1.8.
|
1231
|
-
guides_uri: http://opalrb.com/docs/guides/v1.8.
|
1233
|
+
changelog_uri: https://github.com/opal/opal/blob/v1.8.1/CHANGELOG.md
|
1234
|
+
readme_uri: https://github.com/opal/opal/blob/v1.8.1/README.md
|
1235
|
+
api_documentation_uri: http://opalrb.com/docs/api/v1.8.1/index.html
|
1236
|
+
guides_uri: http://opalrb.com/docs/guides/v1.8.1/index.html
|
1232
1237
|
chat_uri: https://gitter.im/opal/opal
|
1233
1238
|
source_code_uri: https://github.com/opal/opal
|
1234
1239
|
post_install_message:
|
@@ -1242,9 +1247,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
1242
1247
|
version: '2.3'
|
1243
1248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1244
1249
|
requirements:
|
1245
|
-
- - "
|
1250
|
+
- - ">="
|
1246
1251
|
- !ruby/object:Gem::Version
|
1247
|
-
version:
|
1252
|
+
version: '0'
|
1248
1253
|
requirements: []
|
1249
1254
|
rubygems_version: 3.4.5
|
1250
1255
|
signing_key:
|
@@ -1598,6 +1603,7 @@ test_files:
|
|
1598
1603
|
- lib/opal/rewriters/base.rb
|
1599
1604
|
- lib/opal/rewriters/binary_operator_assignment.rb
|
1600
1605
|
- lib/opal/rewriters/block_to_iter.rb
|
1606
|
+
- lib/opal/rewriters/deduplicate_arg_name.rb
|
1601
1607
|
- lib/opal/rewriters/dot_js_syntax.rb
|
1602
1608
|
- lib/opal/rewriters/dump_args.rb
|
1603
1609
|
- lib/opal/rewriters/for_rewriter.rb
|
@@ -1707,6 +1713,7 @@ test_files:
|
|
1707
1713
|
- stdlib/buffer/array.rb
|
1708
1714
|
- stdlib/buffer/view.rb
|
1709
1715
|
- stdlib/cgi.rb
|
1716
|
+
- stdlib/cgi/util.rb
|
1710
1717
|
- stdlib/console.rb
|
1711
1718
|
- stdlib/date.rb
|
1712
1719
|
- stdlib/date/date_time.rb
|