What is the method for invoking C++ from Javascript in Mozilla Rhino?

Currently, I am incorporating Mozilla Rhino in my application and I require the use of a C/C++ library. Are there any alternative methods available to access this library apart from directly calling on c/C++ functions through Java?

Answer №1

Directly calling C / C++ functions from Javascript is not possible.

One workaround is to create a Java wrapper class that can communicate with C / C++ native code, and then call methods on this wrapper class from Javascript. If you choose this route, look for tutorials on using JNA or JNI for seamless interoperability between Java and C / C++.

However, there are some challenges associated with this approach:

  • The C / C++ code will run within the same memory space as the JVM. Errors in the C / C++ code may cause the JVM to crash abruptly, posing difficulties in identifying and fixing such issues.

  • Most C / C++ code is not designed to be thread-safe. Calling it from multi-threaded Java code can lead to unexpected outcomes, as mentioned earlier.

  • The sequence of calls from Javascript to Java and then to C++ may introduce performance overheads. It's common for individuals to turn to C / C++ for better performance, only to find that it actually slows down their application.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on initiating a $http.get request every second using a service

I am working on an angular application that includes a $http.get request. While it currently functions properly, I need it to be executed every second in order to retrieve new data. Service: angular.module('adf.widget.liveCharts') .service(&a ...

Using the section :export in the SCSS :root declaration

In the file test.module.scss, I store all my variables for colors, typography, and more. I want to be able to use these variables in my react components. However, the file starts with :root to define the variables: :root{ --color-white: #fff; --color-b ...

Invoke an AngularJS directive from a controller when clicked

Hey there! I'm currently utilizing the tg-dynamic-directive to loop through a JSON file and display the tree structure shown in the attached image. https://i.sstatic.net/Ph6Cs.png One major issue I'm facing is performance degradation when the " ...

Constructing a JSON schema for a dynamic aggregate query

Looking to create a query that matches fields with data in them. Here is an attempt: var matchStr = {}; if (received.user) { matchStr = { "_id": { "$regex": received.user, "$options": "i" } }; } if (received.name) { matchStr += { "name": { " ...

Is there a way to determine if a parent of my HTML element possesses a CSS class?

Looking at this HTML code snippet - <div id="parent" class="foo"> <div id="child"> </div> </div> Is there a way to create a test to verify if the child element is utilizing the foo class? I attempted: element .children("#chi ...

What is the best approach for organizing JavaScript/CoffeeScript in a Rails 5 project for optimal efficiency?

I am currently working on a web application with Rails 5.0.2 and I have a set of JS files for the project: https://i.stack.imgur.com/WYB23.png Each of my own JS files follows a similar pattern, like this: $(function () { var init = function () { ...

Remove properties that are not part of a specific Class

Is there a way to remove unnecessary properties from the Car class? class Car { wheels: number; model: string; } const obj = {wheels:4, model: 'foo', unwanted1: 'bar', unwantedn: 'kuk'}; const goodCar = filterUnwant ...

Guide to uploading a file into a MongoDB database with the help of Mongoose

Currently, I am working on a database application using Node-Express and mongoose. My goal is to enable users to upload various file types such as photos or documents directly into the database. Despite searching extensively for information online, I hav ...

Preventing the opening of a past event's modal dialog in jQuery

I am having trouble with setting up the jquery full calendar. Whenever I click on a past event, the modal opens when it shouldn't. Only current and future events should trigger the opening of a modal. eventRender: function(event, element, view) { ...

How to change a CSS 'left' property using Jquery or Javascript

Upon examining my DOM, I found the following element: <div id="itemEditor" class="quoteItemEditorView partType_MATERIAL editMode selectorEnabled" style="left: -1px; right: 0px; width: auto; min-width: 480px; display: block;" > I have b ...

Failed CMake build for SDL project

I am encountering an issue while setting up an SDL project using CMake. It seems like the executable is not properly linked. Below is the CMakeLists.txt that I am using: cmake_minimum_required(VERSION 3.0) project(MuspellsheimR) # includes cmake/FindSDL ...

Error: Unable to render followers list due to incorrect data type

I have embarked on creating a unique Github user card generator that retrieves user data and their followers' information from the GitHub API, then displays them on a personalized user card. The follower's data received is in the form of an array ...

Print the information obtained from a synchronous AJAX request in the console

I'm struggling to wrap my head around this issue. I am attempting to save the data from a synchronous ajax call in a variable and then log it to the console. However, the final console log is executing before the synchronous call has completed, so it ...

Unable to send an HTTP request using intent

I'm currently facing an issue where an intent triggers an HTTP request, but I keep encountering errors. Whenever the intent is triggered, the following code is executed: const https = require('https'); https.get('*************' ...

Is there a way to access and view the compiled shader code of a material in THREE.js?

Whenever I'm working on a custom shader in THREE.js and encounter an error, the console provides me with a helpful error message containing the compiled GLSL code. This includes my own code along with additional lines automatically added by Three.js: ...

I am experiencing an issue wherein after using jquery's hover() function, the CSS :hover state is not

Following the jquery hover function, the css hover feature ceases to work. In my html, there are multiple svg elements. A jquery script is applied where hovering over a button at the bottom triggers all svg elements to change color to yellow (#b8aa85). S ...

Combination of two character arrays in C

int main(int argc, char *argv[]) { char *s = argv[1]; *(s + (strlen(argv[1]))) = argv[2]; printf("%s \n", s); return 0; } Upon running the command: ./concat hello, world, the resulting output is: hello,Mworld. However, the expected output s ...

If viewed on a mobile device, separate the array (indexed list) into two rows

Currently, I am working on my Ionic project where I am trying to implement an indexed list horizontally instead of vertically. While the list looks good as it is now, I want to make sure it supports smaller screen devices too by splitting the list into two ...

Is it possible to iterate through HTML form data using JSON arrays or objects?

I've been searching this website and the internet for a while now, trying to figure out how to save multiple arrays to my localStorage. I asked a question earlier which helped me progress a bit, but I'm still struggling to grasp the concept. I c ...

Link the Sass variable to Vue props

When working on creating reusable components in Vue.js, I often utilize Sass variables for maintaining consistency in colors, sizes, and other styles. However, I recently encountered an issue with passing Sass variables using props in Vue.js. If I directly ...