Code Monkey home page Code Monkey logo

Comments (3)

mathieujobin avatar mathieujobin commented on August 17, 2024 1

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.

tisba avatar tisba commented on August 17, 2024

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.

mathieujobin avatar mathieujobin commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.