Module: RubyGaurden::Bridging

Extended by:
ActiveSupport::Concern
Included in:
Bed
Defined in:
lib/ruby_gaurden/bridging.rb

Instance Method Summary collapse

Instance Method Details

#call(method_name, *args) ⇒ Object

Directly invokes a Ruby method defined inside the sandbox. This bypasses the Ruby-to-JS compilation step for the call itself.

Parameters:

  • method_name (Symbol, String)

    The name of the method to call.

  • args (Array)

    Arguments to pass to the method.

Returns:

  • (Object)

    The result of the method call.

Raises:

  • (BedError)

    if the method raises an exception inside the sandbox.



123
124
125
126
127
128
129
# File 'lib/ruby_gaurden/bridging.rb', line 123

def call(method_name, *args)
  # We use JSON to move data across the bridge to avoid V8/Ruby object mapping overhead
  # and to ensure Opal objects are correctly initialized.
  serialized_args = args.to_json
  result = context.call('__rb_bridge_invoke', method_name.to_s, serialized_args)
  handle_bridge_result(result)
end

#reset_io!Object

Clears the IO buffers (stdout and stderr).



112
113
114
115
# File 'lib/ruby_gaurden/bridging.rb', line 112

def reset_io!
  @stdout = []
  @stderr = []
end

#stderrArray<String>

Returns the accumulated stderr produced by the sandbox.

Returns:

  • (Array<String>)


107
108
109
# File 'lib/ruby_gaurden/bridging.rb', line 107

def stderr
  @stderr ||= []
end

#stdoutArray<String>

Returns the accumulated stdout produced by the sandbox.

Returns:

  • (Array<String>)


101
102
103
# File 'lib/ruby_gaurden/bridging.rb', line 101

def stdout
  @stdout ||= []
end