context.call: does not support non-global function names
See original GitHub issueWhen calling a function, only global function names are supported. Functions which are properties of an object, or otherwise nested/scoped, are not supported: e.g. object.fn
.
This works:
context = MiniRacer::Context.new
context.eval('bare = () => 1')
# => #<MiniRacer::JavaScriptFunction:0x00007f96e8acf798>
context.call('bare')
# => 1
This breaks:
context = MiniRacer::Context.new
context.eval('object = {}')
context.eval('object.nested = () => 1')
# => #<MiniRacer::JavaScriptFunction:0x00007f96e899d5a0>
context.call('object.nested')
# => Unknown JavaScript method invoked (MiniRacer::RuntimeError)
Environment:
- ruby:
3.0.2
- mini_racer:
0.5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How can I set a (non-global) variable in a jinja context function?
I have many situations where I don't have just one but up to 20 variables that are being set and then a macro...
Read more >26. Global vs. Local Variables and Namespaces
So, we would have s both as a global and a local variable in the same scope, i.e. the body of the function....
Read more >UpdateContext function in Power Apps - Microsoft Learn
Context variables are implicitly created by using the UpdateContext or Navigate function. There is no explicit declaration required.
Read more >482 Function call blocks and local variable/function names
Function call parameters are local to the function and are not injected into the calling context. That is, given a definition of foo(x)=......
Read more >C Programming Course Notes - Functions
Any variable changes made within a function are local to that function. A calling function's variables are not affected by the actions of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s a good point, @gi, thx!
For reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const:
But what surprises me then is that the defined constant is still visible on subsequent invocations:
Since I can also use
foo
in subsequent#eval
calls, it looks like the same scope is used every time. I think these issues are related after all and it feels like a similar lookup issue 🤔The original issue here is that the string used to identify the function to call is not evaluated to lookup the function:
In Ruby,
is interpreted in JavaScript as
instead of