Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
c8536d97
Commit
c8536d97
authored
Jan 18, 2017
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jan 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3362 from ksss/proc
Proc shouldn't have `initialize` method
parents
c8306986
a68b5689
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
44 deletions
+21
-44
mrbgems/mruby-proc-ext/test/proc.rb
mrbgems/mruby-proc-ext/test/proc.rb
+0
-11
src/proc.c
src/proc.c
+9
-6
test/t/proc.rb
test/t/proc.rb
+12
-27
No files found.
mrbgems/mruby-proc-ext/test/proc.rb
View file @
c8536d97
...
@@ -58,17 +58,6 @@ assert('Proc#parameters') do
...
@@ -58,17 +58,6 @@ assert('Proc#parameters') do
assert_equal
([[
:req
,
:a
],
[
:req
,
:b
],
[
:opt
,
:c
],
[
:opt
,
:d
],
[
:rest
,
:e
],
[
:req
,
:f
],
[
:req
,
:g
],
[
:block
,
:h
]],
lambda
{
|
a
,
b
,
c
=
:c
,
d
=
:d
,
*
e
,
f
,
g
,
&
h
|
}.
parameters
)
assert_equal
([[
:req
,
:a
],
[
:req
,
:b
],
[
:opt
,
:c
],
[
:opt
,
:d
],
[
:rest
,
:e
],
[
:req
,
:f
],
[
:req
,
:g
],
[
:block
,
:h
]],
lambda
{
|
a
,
b
,
c
=
:c
,
d
=
:d
,
*
e
,
f
,
g
,
&
h
|
}.
parameters
)
end
end
assert
(
'Proc#parameters with uninitialized Proc'
)
do
begin
Proc
.
alias_method
(
:original_initialize
,
:initialize
)
Proc
.
remove_method
(
:initialize
)
assert_equal
[],
Proc
.
new
{
|
a
,
b
,
c
|
1
}.
parameters
ensure
Proc
.
alias_method
(
:initialize
,
:original_initialize
)
Proc
.
remove_method
(
:original_initialize
)
end
end
assert
(
'Proc#to_proc'
)
do
assert
(
'Proc#to_proc'
)
do
proc
=
Proc
.
new
{}
proc
=
Proc
.
new
{}
assert_equal
proc
,
proc
.
to_proc
assert_equal
proc
,
proc
.
to_proc
...
...
src/proc.c
View file @
c8536d97
...
@@ -148,19 +148,22 @@ mrb_proc_copy(struct RProc *a, struct RProc *b)
...
@@ -148,19 +148,22 @@ mrb_proc_copy(struct RProc *a, struct RProc *b)
}
}
static
mrb_value
static
mrb_value
mrb_proc_
initialize
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_proc_
s_new
(
mrb_state
*
mrb
,
mrb_value
proc_class
)
{
{
mrb_value
blk
;
mrb_value
blk
;
mrb_value
proc
;
struct
RProc
*
p
;
mrb_get_args
(
mrb
,
"&"
,
&
blk
);
mrb_get_args
(
mrb
,
"&"
,
&
blk
);
if
(
mrb_nil_p
(
blk
))
{
if
(
mrb_nil_p
(
blk
))
{
/* Calling Proc.new without a block is not implemented yet */
/* Calling Proc.new without a block is not implemented yet */
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"tried to create Proc object without a block"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"tried to create Proc object without a block"
);
}
}
else
{
p
=
(
struct
RProc
*
)
mrb_obj_alloc
(
mrb
,
MRB_TT_PROC
,
mrb_class_ptr
(
proc_class
));
mrb_proc_copy
(
mrb_proc_ptr
(
self
),
mrb_proc_ptr
(
blk
));
mrb_proc_copy
(
p
,
mrb_proc_ptr
(
blk
));
}
proc
=
mrb_obj_value
(
p
);
return
self
;
mrb_funcall_with_block
(
mrb
,
proc
,
mrb_intern_lit
(
mrb
,
"initialize"
),
0
,
NULL
,
blk
);
return
proc
;
}
}
static
mrb_value
static
mrb_value
...
@@ -268,7 +271,7 @@ mrb_init_proc(mrb_state *mrb)
...
@@ -268,7 +271,7 @@ mrb_init_proc(mrb_state *mrb)
call_irep
->
iseq
=
call_iseq
;
call_irep
->
iseq
=
call_iseq
;
call_irep
->
ilen
=
1
;
call_irep
->
ilen
=
1
;
mrb_define_
method
(
mrb
,
mrb
->
proc_class
,
"initialize"
,
mrb_proc_initialize
,
MRB_ARGS_NONE
());
mrb_define_
class_method
(
mrb
,
mrb
->
proc_class
,
"new"
,
mrb_proc_s_new
,
MRB_ARGS_ANY
());
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"initialize_copy"
,
mrb_proc_init_copy
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"initialize_copy"
,
mrb_proc_init_copy
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"arity"
,
mrb_proc_arity
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"arity"
,
mrb_proc_arity
,
MRB_ARGS_NONE
());
...
...
test/t/proc.rb
View file @
c8536d97
...
@@ -46,17 +46,6 @@ assert('Proc#arity', '15.2.17.4.2') do
...
@@ -46,17 +46,6 @@ assert('Proc#arity', '15.2.17.4.2') do
assert_equal
(
-
1
,
g
)
assert_equal
(
-
1
,
g
)
end
end
assert
(
'Proc#arity with unitialized Proc'
)
do
begin
Proc
.
alias_method
(
:original_initialize
,
:initialize
)
Proc
.
remove_method
(
:initialize
)
assert_equal
0
,
Proc
.
new
{
|
a
,
b
,
c
|
1
}.
arity
ensure
Proc
.
alias_method
(
:initialize
,
:original_initialize
)
Proc
.
remove_method
(
:original_initialize
)
end
end
assert
(
'Proc#call'
,
'15.2.17.4.3'
)
do
assert
(
'Proc#call'
,
'15.2.17.4.3'
)
do
a
=
0
a
=
0
b
=
Proc
.
new
{
a
+=
1
}
b
=
Proc
.
new
{
a
+=
1
}
...
@@ -147,6 +136,18 @@ assert('Proc#return_does_not_break_self') do
...
@@ -147,6 +136,18 @@ assert('Proc#return_does_not_break_self') do
assert_equal
c
,
c
.
block
.
call
assert_equal
c
,
c
.
block
.
call
end
end
assert
(
'call Proc#initialize if defined'
)
do
a
=
[]
c
=
Class
.
new
(
Proc
)
do
define_method
(
:initialize
)
do
a
<<
:ok
end
end
assert_kind_of
c
,
c
.
new
{}
assert_equal
[
:ok
],
a
end
assert
(
'&obj call to_proc if defined'
)
do
assert
(
'&obj call to_proc if defined'
)
do
pr
=
Proc
.
new
{}
pr
=
Proc
.
new
{}
def
mock
(
&
b
)
def
mock
(
&
b
)
...
@@ -163,19 +164,3 @@ assert('&obj call to_proc if defined') do
...
@@ -163,19 +164,3 @@ assert('&obj call to_proc if defined') do
assert_raise
(
TypeError
){
mock
(
&
(
Object
.
new
))
}
assert_raise
(
TypeError
){
mock
(
&
(
Object
.
new
))
}
end
end
assert
(
'initialize_copy works when initialize is removed'
)
do
begin
Proc
.
alias_method
(
:old_initialize
,
:initialize
)
Proc
.
remove_method
(
:initialize
)
a
=
Proc
.
new
{}
b
=
Proc
.
new
{}
assert_nothing_raised
do
a
.
initialize_copy
(
b
)
end
ensure
Proc
.
alias_method
(
:initialize
,
:old_initialize
)
Proc
.
remove_method
(
:old_initialize
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment