nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Strict mode fails silently in async callback (fs)

Open suns-echoes opened this issue 10 years ago • 2 comments

Hello.

First things first: NWJS: 0.13.0 x64 DEV and 0.13.2 x64 DEV OS: Win 10 Home x64

I've found that console don't show any error nor warning (script just breaks silently) when I use strict mode and try to use undeclared variable inside a function that is fired asynchronously (in my case it is fired by fs.readFile).

Test case:

INDEX.HTML

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>BDCFF converter</title>
</head>

<body>
</body>

<script type="text/javascript" src="BDCFF.js"></script>
<script type="text/javascript">
'use strict';

window.onload = function () {

    BDCFF2.convert('BDCFF/levels.bd', function () {
        console.log('done.');
    });

};
</script>

</html>

BDCFF.JS

var BDCFF2 = (function () {
    'use strict'; // STRICT MODE ...
    var fs = require('fs');
    //im_undeclared_variable_0 = false; // I THROW ERROR :)
    function convert ( file, callback ) {
        //im_undeclared_variable_1 = false; // I THROW ERROR :)
        fs.readFile ( file, 'utf8', function ( err, data ) {
            im_undeclared_variable_2 = false; // I SHOULD THROW ERROR BUT I DON'T :( !!
            /*... some more code - not relevant here...*/
            callback();
        });
    }
    return {
        convert: convert
    }
}());

Note that this will not throw any error even if callback function is not declared inline.

suns-echoes avatar Apr 02 '16 17:04 suns-echoes

I never thought that could be because of strict mode, I am having the same prob. I hope this gets fixed asap!

MehmetKursat avatar Apr 04 '16 09:04 MehmetKursat

I tried the case and it works for me -- the error is thrown and you can see it on the console and devtools (inspect background page because the callback is running in Node context).

rogerwang avatar Apr 04 '16 09:04 rogerwang