Skip to content

Commit

Permalink
turn on cputime_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmakesgames committed Oct 4, 2024
1 parent e9f2ad1 commit c410e78
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/mini_racer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ def initialize(name, callback, parent)
end
end

def initialize(max_memory: nil, timeout: nil, isolate: nil, ensure_gc_after_idle: nil, snapshot: nil, marshal_stack_depth: nil)
def initialize(max_memory: nil, timeout: nil, cputime_limit: nil, isolate: nil, ensure_gc_after_idle: nil, snapshot: nil, marshal_stack_depth: nil)
options ||= {}

check_init_options!(isolate: isolate, snapshot: snapshot, max_memory: max_memory, marshal_stack_depth: marshal_stack_depth, ensure_gc_after_idle: ensure_gc_after_idle, timeout: timeout)
check_init_options!(isolate: isolate, snapshot: snapshot, max_memory: max_memory, marshal_stack_depth: marshal_stack_depth, ensure_gc_after_idle: ensure_gc_after_idle, timeout: timeout, cputime_limit: cputime_limit)

@functions = {}
@timeout = nil
@cputime_limit = nil
@max_memory = nil
@current_exception = nil
@timeout = timeout
@cputime_limit = cputime_limit
@max_memory = max_memory
@marshal_stack_depth = marshal_stack_depth

Expand Down Expand Up @@ -340,7 +342,7 @@ def stop_attached
end

def timeout(&blk)
return blk.call unless @timeout
return blk.call unless @timeout # !!TODO THIS PR need to figure out what this if statement is when adding in cputime_limit

mutex = Mutex.new
done = false
Expand Down Expand Up @@ -388,14 +390,15 @@ def timeout(&blk)
rp.close if rp
end

def check_init_options!(isolate:, snapshot:, max_memory:, marshal_stack_depth:, ensure_gc_after_idle:, timeout:)
def check_init_options!(isolate:, snapshot:, max_memory:, marshal_stack_depth:, ensure_gc_after_idle:, timeout:, cputime_limit:)
assert_option_is_nil_or_a('isolate', isolate, Isolate)
assert_option_is_nil_or_a('snapshot', snapshot, Snapshot)

assert_numeric_or_nil('max_memory', max_memory, min_value: 10_000, max_value: 2**32-1)
assert_numeric_or_nil('marshal_stack_depth', marshal_stack_depth, min_value: 1, max_value: MARSHAL_STACKDEPTH_MAX_VALUE)
assert_numeric_or_nil('ensure_gc_after_idle', ensure_gc_after_idle, min_value: 1)
assert_numeric_or_nil('timeout', timeout, min_value: 1)
assert_numeric_or_nil('cputime_limit', cputime_limit, min_value: 1)

if isolate && snapshot
raise ArgumentError, 'can only pass one of isolate and snapshot options'
Expand Down

0 comments on commit c410e78

Please sign in to comment.