mirror of
https://github.com/rubyjs/mini_racer
synced 2023-03-27 23:21:28 -04:00
return a special ruby object when we have a function
This commit is contained in:
parent
eb826ae48a
commit
b2473d7dc0
4 changed files with 20 additions and 2 deletions
|
@ -34,8 +34,8 @@ LIBV8_COMPATIBILITY = '~> 5.0.71.35.0'
|
|||
#
|
||||
# Libv8.configure_makefile
|
||||
|
||||
NODE_PATH = "/home/sam/Source/libv8"
|
||||
#NODE_PATH = "/Users/sam/Source/libv8"
|
||||
#NODE_PATH = "/home/sam/Source/libv8"
|
||||
NODE_PATH = "/Users/sam/Source/libv8"
|
||||
#
|
||||
NODE_LIBS = NODE_PATH + "/vendor/v8/out/x64.release"
|
||||
NODE_INCLUDE = NODE_PATH + "/vendor/v8/include"
|
||||
|
|
|
@ -43,6 +43,7 @@ typedef struct {
|
|||
static VALUE rb_eScriptTerminatedError;
|
||||
static VALUE rb_eParseError;
|
||||
static VALUE rb_eScriptRuntimeError;
|
||||
static VALUE rb_cJavaScriptFunction;
|
||||
|
||||
static Platform* current_platform = NULL;
|
||||
|
||||
|
@ -165,6 +166,10 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Handle<Value> &value) {
|
|||
return rb_array;
|
||||
}
|
||||
|
||||
if (value->IsFunction()){
|
||||
return rb_funcall(rb_cJavaScriptFunction, rb_intern("new"), 0);
|
||||
}
|
||||
|
||||
if (value->IsObject()) {
|
||||
VALUE rb_hash = rb_hash_new();
|
||||
Local<Context> context = Context::New(isolate);
|
||||
|
@ -510,6 +515,7 @@ extern "C" {
|
|||
rb_eScriptTerminatedError = rb_define_class_under(rb_mMiniRacer, "ScriptTerminatedError", rb_eEvalError);
|
||||
rb_eParseError = rb_define_class_under(rb_mMiniRacer, "ParseError", rb_eEvalError);
|
||||
rb_eScriptRuntimeError = rb_define_class_under(rb_mMiniRacer, "RuntimeError", rb_eEvalError);
|
||||
rb_cJavaScriptFunction = rb_define_class_under(rb_mMiniRacer, "JavaScriptFunction", rb_cObject);
|
||||
|
||||
VALUE rb_cExternalFunction = rb_define_class_under(rb_cContext, "ExternalFunction", rb_cObject);
|
||||
rb_define_method(rb_cContext, "stop", (VALUE(*)(...))&rb_context_stop, 0);
|
||||
|
|
|
@ -32,6 +32,13 @@ module MiniRacer
|
|||
|
||||
end
|
||||
|
||||
# helper class returned
|
||||
class JavaScriptFunction
|
||||
def to_s
|
||||
"JavaScript Function"
|
||||
end
|
||||
end
|
||||
|
||||
# eval is defined in the C class
|
||||
class Context
|
||||
|
||||
|
|
|
@ -75,6 +75,11 @@ class MiniRacerTest < Minitest::Test
|
|||
end
|
||||
end
|
||||
|
||||
def test_returns_javascript_function
|
||||
context = MiniRacer::Context.new
|
||||
assert_equal MiniRacer::JavaScriptFunction, context.eval("a = function(){}").class
|
||||
end
|
||||
|
||||
def test_it_handles_malformed_js
|
||||
context = MiniRacer::Context.new
|
||||
assert_raises MiniRacer::ParseError do
|
||||
|
|
Loading…
Reference in a new issue