How to access to functions/variables from GWT code in Javascript? - javascript

I am trying to use some functions from a code that has been obfuscated. So i have an html file that is calling a JS file thru the tag:
<script src="gwt_svg_viewer/gwt_svg_viewer.nocache.js"></script>
that file is defining a function called "onScriptdownloaded" which receives a string like this:
gwt_svg_viewer.onScriptDownloaded(["var $wnd = window.parent;function RE(){}"]);
So my question is how can i access to RE? in another JS file?
It seems that there was a kind of GWT code implemented, but i am not really familiar with that.

Variable names and functions in gwt will be obfuscated every time you compile your project, and variables and functions will be renamed in the process, in order to call a gwt code from javascript in a consistence manner you will need to use jsinterop to export java types. more information can be found in the gwt jsinterop documentation

Related

How can I call a Javascript function from a website? [duplicate]

This question already has an answer here:
How to call external javascript function from jslib plugin Unity webgl
(1 answer)
Closed 1 year ago.
I'm working on a program that will be used by different users and they will individually change the content of the js file to match with their expectation.
On the web I found many tutorials on how to call JS function in unity WEBGL but the Js file was built with the unity project.
I wanted a way to call a JS function which is hosted by the website (incluing it in the index.html of unity WEBGL but without building it).
What you are trying to do is possible. But it is a bit of a hack.
a quick google search turned up this article, from the unity documentation
But it might not be clear how to do it. so here is an example:
example:
Let us say you want to call a js function called foo().
.jslib
The first thing to do is create a file with a .jslib file extension in a folder named "Plugins".
this file tells unity that the function exists and is a just js
mergeInto(LibraryManager.library, {
foo_js: function () {
foo()
},
});
Here I declare a function called foo_js and tell unity that it exists.
This function consists of js, and in this case, all it does is call the js function foo().
Note: the name foo_js is arbitrary, and it can be called anything, Including just foo. but it is the same name as you will be using in c#. so I would recommend making it clear that it is not a native c# function
c#
now in a c# script, you start by declaring the function, which is done by adding
[DllImport("__Internal")]
private static extern void foo_js();
to a class and add
using System.Runtime.InteropServices;
to the top of the file
you can now call the function as foo_js() in your c# script
after built
after you have built the unity project, you need to add a js script. To "index.html" that has a function called foo() for unity to call.
And it should work, for more detail read the article from the beginning.
Edit:
Something I forgot to mention is that it is not going to work in the editor, as the js function is not defined, so you need to export the project and define the function on the website
it should be possible to detect that the game is running in the editor and use a default behaviour instead of the js function, but I am not sure how right now

how to use javascript library in dart

I am learning package:js and the dart file, which is a dart wrapper for chart.js.
I think this file is a bridge which connects dart and javascript. So, in this file, it must tell what javascript library this dart file is trying to connect. Am I right? But I did not find it.
What do the following statements mean? Do the following two statements tell what javascript library this dart file is trying to connect?
#JS('Chart')
library chart.js;
I have no idea how to map functions https://github.com/google/chartjs.dart/blob/master/lib/chartjs.dart to functions in https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js. Anyone can give more tutorials?
You don't need to map to a JavaScript file, you just need to map to JS objects and functions.
You need to add a script tag to index.html that loads the JavaScript file you want to map to, this will make it available globally.
You then need to map
Dart functions to JavaScript functions, so when you call such a Dart function the call will actually be forwarded to the JavaScript function.
Dart classes so that you can use strongly typed Dart classes which will then be converted to and from JavaScript objects when you for example pass them as parameters to mapped functions or get them as return values from such function calls.
#JS('Chart')
library chart.js;
The name chart.js after library is arbitrary. The library directive just needs an unique name.
#JS('Chart') means that the loaded chart.js library is available in JavaScript land under window.Chart (window means global in JS land and is implicit).
#JS()
class Chart {
declares a Dart class Chart and #JS() maps it to a JS class with the same name in the library scope declared above. So the Dart class Chart will map to the JavaScript class window.Chart.Chart.
external factory Chart(
The external ... declarations inside the Dart Chart class map to the JS methods with the same name.
More details can be found in the README.md https://pub.dartlang.org/packages/js.
If you're still stuck you can ask more concrete questions. It's difficult to answer generic questions about how to use a package.

How to wrap a c/c++ file into node.js file

I have a c++ header file. I need to wrap c++ and node.js and use the JS script for my testing. I am new to node.js and I need some help in understanding from where to start. From the analyzing i did so far it seems like we need to manually write the node.js file for calling the function (kind of declaring the functions and use it).
I have created a .js file and declared all my functions and variables in it and called the C++ API.
var testlib = ffi.Library(file.libtest,{ 'Test_pgm': ['int', ['int','string']] });
var result=testlib.test_pgm(20,"name");
Is there anyway to automate this process so that when i pass the C++ header file it should parse the functions and variables like above and should create output file, so that i can call the C++ Api's directly by importing the output node.js wrapper file.
Previously i have did python and c wrapping using CFFI. There i create a customized header file and passed that file to cffi. Is there anything similar to this method in node.js ?
Thanks in advance.

Extend JavaScript Class from separate file

I'm sorry to ask quite a dim question as I'm very new to OOP in JavaScript.
I'm trying to use John Resig's Simple JavaScript Inheritance method, and ideally I'd like to store this within say utils.js, and then use it (using Class.extend), throughout the range of script files that my project uses. Is this possible? I've noticed that if I create a subclass from within my utils.js file, I can then create a new instance of that class from a different script, so that makes me think it might be possible. Does it have something to do with the method being wrapped in an immediately-invoked function expression?
Sure it's possible, just load the util.js file before the rest. ALthough if I were you (seems like you're starting to have several different files in your project) I'd check out http://requirejs.org/ or some other AMD library to break up your project in modules.
Yes, this is possible only thing is you have to include Utils.js file before calling Class.extend, so that browser should be able to find the base class.
Browser works like an interpreter, it loads scripts once it finds the script tag
Does it have something to do with the method being wrapped in an immediately-invoked function expression?
Yes, in the moment in which the utils.js script is loaded, the method executes and returns the object Class to the global scope. From then on, the object can be used in all other files.

Passing data from my razor view to my js file

I'm searching for the best way to pass data from my razor view to my js file. For example, lets say we have a jquery dialog configured in the js file. For buttons text on this dialog, I would like to localize it (through resource files FR/NL/UK). The translations are available with #UserResource.ButtonDelete + #UserResource.ButtonCancel
Below are the different solutions I see:
Using the nice RazorJS nuget package to allows razor code inside my javascript file. It works pretty well. But the question is: is it a bad practice to compile js files in order to use razor syntax inside the scripts?
Declaring global variables in the js script file and assign value from the view like this:
In the view:
<script>
var labelButtonDelete = #UserResource.ButtonDelete;
</script>
In the js file:
alert('The text for my button is ' + labelButtonDelete);
What is the best way to pass data from razor to js file? Do you have another alternative?
Thanks anyway.
I've been using something like your second approach for some time without any issues. The only difference is that I'm using a singleton in my JS file to avoid polluting the global javascript namespace.
But if you will be doing more serious client side stuff, your Javascript code will follow a more object oriented structure, and from there you almost automatically get a single initialization/constructor path where you can pass your localized values.
That RazorJS looks nice, but I'm not sure if I'm comfortable mixing Javascript with Razor. Might do it for a small project, but I can see it becoming really messy if you have lots of Javascript files.
After all, I still consider the resources/localization code to be related to the view. The Javascript should only implement functionality in my opinion.

Categories

Resources