Comments (3)
Looks like I found the solution to my last problem... reading #224 I realize I now need to make the call to the context, but my functions don't have names as shown... so I am creating anonymous names... such like this.
set_callback :initialize, :after do
@fn_name = "custom_#{SecureRandom.hex(5)}"
@function_ref = js_context.eval("#{@fn_name} = (#{body})")
end
then I am able to make calls like this
def call(environment, args)
initialize_js_context(environment)
js_context.call(@fn_name, *args)
end
very happy ! Thank you
from mini_racer.
Hey @mathieujobin. Could you provide a bit more context? Ideally something that is reproducible. With just this three lines of code you provided, it's difficult to help.
from mini_racer.
Right, thank you for getting back to me... I don't master the code base yet.
We are creating the context in such a way, ...
v8_context ||= MiniRacer::Context.new.tap do |context|
context.load(LibDSL.root.join("vendor/underscore.js"))
end
it used to be V8::Context from TheRubyRacer.
This is kept in a class instance var, which we .dup
for each instance.
It used to work fine, but for some reason, I get the above-mentioned error.
I found out I can skip that error by creating a fresh object for each instance. It's unclear why it makes a difference, .dup
should start fresh as well for each instance. It is a micro-optimization I can live without.
This moves me to the next problem I have, migrating to mini_racer. Which isn't exactly related to the previous error. But I'll continue here instead of creating a separate issue for now.
It appears TheRubyRacer's V8::Context had the ability to store attributes via a []=
method.
I could do
V8:Context.new['rocket'] = 'science'
MiniRacer does not appear to have it, don't think its a big deal, I can store it elsewhere. but if that rings a bell. Feel free to comment.
Next, I do
js_function_ref = V8::Context.new.eval("(function(a,b,c) { return a + '-' + b + '-' + c; })")
which appears to work fine, it returns me a MiniRacer::JavaScriptFunction
object.
but I cannot call the function, with TheRubyRacer I could do...
js_function_ref.call(*_args)
now I get
undefined method `call' for #<MiniRacer::JavaScriptFunction:0x000055aca580eb00>
any idea what can I do about this one ?
Thanks
from mini_racer.
Related Issues (20)
- sq_mini_racer Ruby 3.1 incompatibility (`Psych::DisallowedClass`) HOT 2
- After MacOS Ventura upgrade. gem install works, bundle install does not HOT 2
- bundler install error HOT 5
- Installing mini_racer 0.6 on docker M1 fails with "make: printf: Argument list too long" HOT 4
- Update default branch to `main` HOT 3
- Unexpected token p in JSON at position HOT 2
- Gem::Ext::BuildError: ERROR: Failed to build gem native extension (Ruby 2.7.4) HOT 3
- Discuss: Release version 1.0.0 and manage consumer breaking version expectations HOT 3
- Node release catch-up plan HOT 42
- CI Improvements HOT 1
- `Isolate::low_memory_notification` fails to lock Isolate HOT 5
- Error installing mini_racer: ERROR: Failed to build gem native extension HOT 7
- Undefined Conversion
- Segmentation fault when application stops (Ruby 3.2.2, tcmalloc or jemalloc) HOT 17
- mini_racer not starting: `ZSt28__throw_bad_array_new_lengthv: symbol not found (LoadError)` HOT 9
- Suggestions for context defaults for server side rendering HOT 4
- Security guarantees? HOT 1
- mini_racer 0.12.0 Segmentation fault on x86_64-linux with libv8-node 21.7.2.0 HOT 101
- Using IO or rescuing exceptions when setting a timeout HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini_racer.