From c34ef93e10d01956d9906970c330855214d891be Mon Sep 17 00:00:00 2001 From: Jb Aviat Date: Tue, 13 Mar 2018 18:31:00 -0700 Subject: [PATCH] Change method name from function_call to call This makes wording coherent with ExecJS and TheRubyRacer. --- README.md | 2 +- .../mini_racer_extension.cc | 8 +++---- lib/mini_racer.rb | 6 ++--- test/function_test.rb | 22 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 87cb5b9..d3fe26a 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ This calls the function passed as first argument: ```ruby context = MiniRacer::Context.new context.eval('function hello(name) { return "Hello, " + name + "!" }') -context.function_call('hello', 'George') +context.call('hello', 'George') # "Hello, George!" ``` diff --git a/ext/mini_racer_extension/mini_racer_extension.cc b/ext/mini_racer_extension/mini_racer_extension.cc index e7b1d4c..c23f8e6 100644 --- a/ext/mini_racer_extension/mini_racer_extension.cc +++ b/ext/mini_racer_extension/mini_racer_extension.cc @@ -1090,7 +1090,7 @@ rb_context_dispose(VALUE self) { } static void* -nogvl_context_function_call(void *args) { +nogvl_context_call(void *args) { FunctionCall *call = (FunctionCall *) args; if (!call) { @@ -1132,7 +1132,7 @@ static void unblock_function(void *args) { } static VALUE -rb_context_function_call_unsafe(int argc, VALUE *argv, VALUE self) { +rb_context_call_unsafe(int argc, VALUE *argv, VALUE self) { ContextInfo* context_info; FunctionCall call; @@ -1191,7 +1191,7 @@ rb_context_function_call_unsafe(int argc, VALUE *argv, VALUE self) { } } - rb_thread_call_without_gvl(nogvl_context_function_call, &call, unblock_function, &call); + rb_thread_call_without_gvl(nogvl_context_call, &call, unblock_function, &call); free(call.argv); if (!call.error) { @@ -1235,7 +1235,7 @@ extern "C" { rb_define_method(rb_cContext, "dispose_unsafe", (VALUE(*)(...))&rb_context_dispose, 0); rb_define_method(rb_cContext, "heap_stats", (VALUE(*)(...))&rb_heap_stats, 0); rb_define_private_method(rb_cContext, "eval_unsafe",(VALUE(*)(...))&rb_context_eval_unsafe, 2); - rb_define_private_method(rb_cContext, "function_call_unsafe", (VALUE(*)(...))&rb_context_function_call_unsafe, -1); + rb_define_private_method(rb_cContext, "call_unsafe", (VALUE(*)(...))&rb_context_call_unsafe, -1); rb_define_alloc_func(rb_cContext, allocate); rb_define_alloc_func(rb_cSnapshot, allocate_snapshot); diff --git a/lib/mini_racer.rb b/lib/mini_racer.rb index 2e04400..5c72ec4 100644 --- a/lib/mini_racer.rb +++ b/lib/mini_racer.rb @@ -186,13 +186,13 @@ module MiniRacer @eval_thread = nil end - def function_call(function_name, *arguments) - raise(ContextDisposedError, 'attempted to call function_call on a disposed context!') if @disposed + def call(function_name, *arguments) + raise(ContextDisposedError, 'attempted to call function on a disposed context!') if @disposed @eval_thread = Thread.current isolate.with_lock do timeout do - function_call_unsafe(function_name, *arguments) + call_unsafe(function_name, *arguments) end end ensure diff --git a/test/function_test.rb b/test/function_test.rb index 6de3ed3..68e86d4 100644 --- a/test/function_test.rb +++ b/test/function_test.rb @@ -9,11 +9,11 @@ class MiniRacerFunctionTest < Minitest::Test assert_equal context.eval('f(10)'), "I need 10 foos" assert_raises(ArgumentError) do - context.function_call + context.call end count = 4 - res = context.function_call('f', count) + res = context.call('f', count) assert_equal "I need #{count} foos", res end @@ -23,7 +23,7 @@ class MiniRacerFunctionTest < Minitest::Test # f is defined, let's call g assert_raises(MiniRacer::RuntimeError) do - context.function_call('g') + context.call('g') end end @@ -33,7 +33,7 @@ class MiniRacerFunctionTest < Minitest::Test # f should throw assert_raises(MiniRacer::RuntimeError) do - context.function_call('f', 1) + context.call('f', 1) end end @@ -43,7 +43,7 @@ class MiniRacerFunctionTest < Minitest::Test # f is defined, let's call g assert_raises(MiniRacer::RuntimeError) do - context.function_call('g') + context.call('g') end end @@ -53,7 +53,7 @@ class MiniRacerFunctionTest < Minitest::Test # f is defined, let's call g assert_raises(MiniRacer::RuntimeError) do - context.function_call('f', 1) + context.call('f', 1) end end @@ -61,13 +61,13 @@ class MiniRacerFunctionTest < Minitest::Test context = MiniRacer::Context.new context.eval("function f(x, y) { return 'I need ' + x + ' ' + y }") - res = context.function_call('f', 3, "bars") + res = context.call('f', 3, "bars") assert_equal "I need 3 bars", res - res = context.function_call('f', {a: 1}, "bars") + res = context.call('f', {a: 1}, "bars") assert_equal "I need [object Object] bars", res - res = context.function_call('f', [1,2,3], "bars") + res = context.call('f', [1,2,3], "bars") assert_equal "I need 1,2,3 bars", res end @@ -76,7 +76,7 @@ class MiniRacerFunctionTest < Minitest::Test context.eval("function f(x, y) { return { vx: x, vy: y, array: [x, y] } }") h = { "vx" => 3, "vy" => "bars", "array" => [3, "bars"] } - res = context.function_call('f', 3, "bars") + res = context.call('f', 3, "bars") assert_equal h, res end @@ -91,7 +91,7 @@ class MiniRacerFunctionTest < Minitest::Test thread_count.times do threads << Thread.new do 10.times do |i| - context.function_call("f", i) + context.call("f", i) end end end