mirror of
https://github.com/rubyjs/mini_racer
synced 2023-03-27 23:21:28 -04:00
parent
31ec118628
commit
ff543d24e8
2 changed files with 28 additions and 2 deletions
|
@ -30,6 +30,7 @@ typedef struct {
|
|||
ArrayBufferAllocator* allocator;
|
||||
StartupData* startup_data;
|
||||
bool interrupted;
|
||||
bool has_gvl;
|
||||
|
||||
// how many references to this isolate exist
|
||||
// we can't rely on Ruby's GC for this, because when destroying
|
||||
|
@ -416,6 +417,7 @@ static VALUE rb_isolate_init_with_snapshot(VALUE self, VALUE snapshot) {
|
|||
isolate_info->allocator = new ArrayBufferAllocator();
|
||||
isolate_info->interrupted = false;
|
||||
isolate_info->refs_count = 1;
|
||||
isolate_info->has_gvl = true;
|
||||
|
||||
Isolate::CreateParams create_params;
|
||||
create_params.array_buffer_allocator = isolate_info->allocator;
|
||||
|
@ -513,7 +515,9 @@ static VALUE rb_context_eval_unsafe(VALUE self, VALUE str) {
|
|||
eval_result.message = NULL;
|
||||
eval_result.backtrace = NULL;
|
||||
|
||||
context_info->isolate_info->has_gvl = false;
|
||||
rb_thread_call_without_gvl(nogvl_context_eval, &eval_params, unblock_eval, &eval_params);
|
||||
context_info->isolate_info->has_gvl = true;
|
||||
|
||||
if (eval_result.message != NULL) {
|
||||
Local<Value> tmp = Local<Value>::New(isolate, *eval_result.message);
|
||||
|
@ -558,7 +562,7 @@ static VALUE rb_context_eval_unsafe(VALUE self, VALUE str) {
|
|||
}
|
||||
}
|
||||
|
||||
// New scope for return value
|
||||
// New scope for return value, must release GVL which
|
||||
{
|
||||
Locker lock(isolate);
|
||||
Isolate::Scope isolate_scope(isolate);
|
||||
|
@ -664,7 +668,23 @@ gvl_ruby_callback(void* data) {
|
|||
}
|
||||
|
||||
static void ruby_callback(const FunctionCallbackInfo<Value>& args) {
|
||||
rb_thread_call_with_gvl(gvl_ruby_callback, (void*)(&args));
|
||||
|
||||
bool has_gvl = false;
|
||||
|
||||
{
|
||||
HandleScope scope(args.GetIsolate());
|
||||
Handle<External> external = Handle<External>::Cast(args.Data());
|
||||
VALUE* self_pointer = (VALUE*)(external->Value());
|
||||
ContextInfo* context_info;
|
||||
Data_Get_Struct(*self_pointer, ContextInfo, context_info);
|
||||
has_gvl = context_info->isolate_info->has_gvl;
|
||||
}
|
||||
|
||||
if(has_gvl) {
|
||||
gvl_ruby_callback((void*)&args);
|
||||
} else {
|
||||
rb_thread_call_with_gvl(gvl_ruby_callback, (void*)(&args));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -522,6 +522,12 @@ raise FooError, "I like foos"
|
|||
end
|
||||
end
|
||||
|
||||
def test_thing
|
||||
v8 = MiniRacer::Context.new
|
||||
v8.attach 'print', proc{|x| puts x}
|
||||
puts v8.eval "var o = {get bar() { print(42); }}; o"
|
||||
end
|
||||
|
||||
class TestPlatform < MiniRacer::Platform
|
||||
def self.public_flags_to_strings(flags)
|
||||
flags_to_strings(flags)
|
||||
|
|
Loading…
Add table
Reference in a new issue