Skip to content

Commit d70939d

Browse files
committed
guard the type of define_function's first arg
1 parent 2e6850f commit d70939d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ext/quickjsrb/quickjsrb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ static VALUE vm_m_defineGlobalFunction(int argc, VALUE *argv, VALUE r_self)
628628
VALUE r_block;
629629
rb_scan_args(argc, argv, "10*&", &r_name, &r_flags, &r_block);
630630

631+
if (!(SYMBOL_P(r_name) || RB_TYPE_P(r_name, T_STRING)))
632+
{
633+
rb_raise(rb_eTypeError, "function's name should be a Symbol or a String");
634+
}
635+
631636
VMData *data;
632637
TypedData_Get_Struct(r_self, VMData, &vm_type, data);
633638

test/quickjs_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ class GlobalFunction < QuickjsVmTest
335335
assert(@vm.eval_code('sym()'))
336336
end
337337

338+
test "function's name can't be others than a symbol nor a string" do
339+
assert_raise_with_message(TypeError, "function's name should be a Symbol or a String") do
340+
@vm.define_function([:sym_in_ary]) { 'never reach' }
341+
end
342+
end
343+
338344
[
339345
["'symsym'", :symsym],
340346
["null", nil],

0 commit comments

Comments
 (0)