In my .cpp file I have a line:
emscripten_run_script("callOut();console.error('Hello');");
This function callOut just writes a message to the console so that I know it has been called.
This all works fine when building with -g4, but doesn't do anything when compiled with the recommended for release -O2. I can't even find the text "hello" in the javascript output.
Is it supposed to work like this? Is there any way I can get this call in the release build?
The problem was that I wasn't waiting for the emscripten code to be fully initialized before calling in to it. You should wait until the emscripten main() function gets called, then you know it is ready.
The problem is made worse when using -O2 as emcc creates a separate memory initialization file that must be loaded before the is emscripten code is ready.
An alternative to emscripten_run_script is to use the EM_ASM macros. I've never had trouble with these disappearing in optimized builds.
So your example would be equivalent to
EM_ASM({
callOut();
console.error("Hello");
});
Related
In my HTML I load a Javascript module like this:
<script type="text/javascript" src="static/js/mymodule.js"></script>
But mymodule.js contains console.log commands inside so I can see their outputs every time when I reload the page. How can I prevent it?
Of course, I could remove all console.log calls, but what if I deal with external library that I can't modify? Maybe there's a way to prevent logging in a particular script-tag.
I don't think there is a way to do that (I hope I'm wrong). If an external library has console.logs in their production code, you should consider using an alternative one.
Because you have control of the file where the console.log exists, you should delete it or comment it out.
try this :
console.log = function () {}
You can do that by: stripping out the console.log statements using build tool settings. Enable the build tool settings to strip console.log for production build whereas you can still keep them for development build.
Most of the build tools have support for this. e.g webpack, gulp etc.
I am working on a projet in Testcomplete 12.0.122 with javascript. I have a problem when I read an XML file and create a CSV file with the needed data.
Reading xml with Msxml2.DOMDocument.6.0
Write in CSV with aqFile.OpenTextFile
When the XML file is quite huge (above 200Mo) the execution start to take long (since the project need to be execute on a vm with 1 processor and 4Go RAM.
To speed up my execution someone told me to change all the call from the object Sys.OleObject.
Example : I got a call like xmlDoc.item(0); I change it for xmlDoc.$call("item", 0);
same thing for the attribute : I got xmlDoc.length change to xmlDoc.$get("length");
This increase speed, but i would like to know why exactly, the person who told me to do it didn't know really why.
Because i got a problem since I made my change, when the file are big, sometime I got error like Log.Error or Log.PopLogFolder doesn't exist. And those function are Testcomplete function for logging.
Any thought on the reason of those errors? Cause since the new call are faster I would like to keep them.
TestComplete 12.0 was the first version that has JavaScript and, perhaps, there were some issues with it. Install the latest version which is 12.10 by the moment and, perhaps, these issues will gone.
As for the reason of the better speed with the changed calls, I think that the reason is that these methods are lower level methods comparing to the usual methods which produces some overhead.
Today, I moved all my javascript code into pure dojo modules, so I could build them and all the modules they use into a single dojo.js file to reduce my page requests from hundreds down to just a handful. This is a wonderful improvement in my code and I need to keep doing this.
BUT:
Since I'm calling my javascript libraries through require() now, I'm having a heck of a time figuring out how to debug them. I can't just place a breakpoint in the .js file anymore and expect it to be hit. The breakpoint is a little empty circle that says
"this breakpoint will not be hit, no symbols have been loaded for this document"
To illustrate what I mean, suppose you have a library file named library.js
//this is library.js
define(["dojo/query"], function(query){
function LibraryFuncA(a, b)
{
return "" a + b;
}
return {LibraryFuncA: LibraryFuncA};
});
In my main cshtml file, I have to call it this way now:
<script>
require(["app/library"], function(lib){
var help = lib.LibraryFuncA("how do I ", "debug this?");
});
</script>
Anyway, this require call will fetch the app/library module from the cache if its in the built dojo file or it will fetch it from the server if I'm using the normal dojo file. But if I wanted to set a breakpoint in library.js to see what was going on in the VS2013 debugger when using IE, how would I do it?
Is there a way I can call LibraryFuncA without using require when it's concealed in the anonymous function that way?
I'm writing a test using a LiveServerTestCase, django-casper, and casperjs for a view that includes javascript. Half way through a client side script I have a jQuery.post(url, callback_function(r){}) line.
When callback_function is called during a test r is null. However, when I run the application normally and step through the same javascript when callback_function is called r has the expected value.
This makes me think that there is a detail about LiveServerTestCase I'm missing to get jQuery.post to work with it. Can anybody please shed light on what I should do next to debug this problem?
I'm guessing it's because the static files aren't around. In Django 1.7, LiveServerTestCase no longer supported serving up the static files. It was moved into testing.StaticLiveServerTestCase
Try changing your test classes to subclass StaticLiveServerTestCase.
I am trying to write a program in C++ and wxWidgets that accesses YouTube and start the video with JavaScript.
It uses the YouTube JavaScript API, documentation for which is found here.
I wrote the following piece of code to play ‘O, Canada’, specifically the one here.
wxWebView *webview = wxWebView::New(this, wxID_ANY, "http://www.youtube.com/watch?v=zwDvF0NtgdU");
webview->RunScript("function onYouTubePlayerReady(playerId) {document.getElementById('watch-player').playVideo();}");
Running the above code fails to fulfill its intended purpose, giving me the following error and a crash:
....\src\msw\wxwebview_ie.cpp(762): "assert "document" failed in wxWebViewIE::GetDocument().
I know that my code successfully LOADS the page, but running the JavaScript (the RunScript() function) seems to result in the error.
I am using wxWidgets 2.9.3 on Windows.
This should have been fixed in revision 71030 which is more recent than the 2.9.3 build that you are using. You can get the updated code either through SVN or a daily snapshot. If that still doesn't fix it please file a bug on the wxWidgets Trac.
The problem is actually because I call the JavaScript too early, before the page is loaded. If I call it a bit later, it works.