Module: Ferrum::Evaluatable
- Included in:
- Node, RemoteObject
- Defined in:
- lib/ferrum/evaluatable.rb,
sig/ferrum/evaluatable.rbs
Overview
Shared by Node and RemoteObject: runs JavaScript with this bound to
the handle, on the runtime that returned it. Takes the same script shapes
and arguments as Frame::Runtime#evaluate. Arrow functions don't get
this, so use a function declaration when the script needs it.
Instance Method Summary collapse
-
#evaluate(expression, *positional, **keywords) ⇒ Object
Evaluates JavaScript with
thisbound to the handle, and returns the result serialized into Ruby. -
#evaluate_handle(expression, *positional, **keywords) ⇒ RemoteObject, ...
Same as #evaluate, but returns a RemoteObject that stays in the browser instead of being serialized.
-
#execute(expression, *positional, **keywords) ⇒ self
Runs JavaScript with
thisbound to the handle, for its side effects.
Instance Method Details
#evaluate(expression, *positional, **keywords) ⇒ Object
Evaluates JavaScript with this bound to the handle, and returns the
result serialized into Ruby.
27 28 29 |
# File 'lib/ferrum/evaluatable.rb', line 27 def evaluate(expression, *positional, **keywords) @runtime.evaluate_in(self, expression, positional, keywords, mode: :value) end |
#evaluate_handle(expression, *positional, **keywords) ⇒ RemoteObject, ...
Same as #evaluate, but returns a RemoteObject that stays in the browser instead of being serialized.
47 48 49 |
# File 'lib/ferrum/evaluatable.rb', line 47 def evaluate_handle(expression, *positional, **keywords) @runtime.evaluate_in(self, expression, positional, keywords, mode: :handle) end |
#execute(expression, *positional, **keywords) ⇒ self
Runs JavaScript with this bound to the handle, for its side effects.
The script is used as a function body, so multiple statements need no
wrapping.
66 67 68 69 |
# File 'lib/ferrum/evaluatable.rb', line 66 def execute(expression, *positional, **keywords) @runtime.evaluate_in(self, expression, positional, keywords, mode: :none) self end |