ClosestStorm / v8cgi

Automatically exported from code.google.com/p/v8cgi
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Unreliable loading of required files #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want to show the problem with the function (or perhaps it is
intentional?) on some samples. 

the required module is loaded with var x = required('x').x; (for x.js)

exports.x = function () {...}
string.prototype.y = function {}

works

exports.x = function () {
    y(); 
    //...
}

var y = function () {
 //...
}

will not load the x.js - no error is thrown.

y = require ('y');

exports.x = function () {
    y(); 
    //...
}

and the same with

exports.x = function () {
  var y = require('sprintf').sprintf;
}

wont load the x-function. Moreover the sometimes it appears do be either
way unreliable. sometimes file is loaded or not... the same phenomenon
appears after I changed from require to include - one of the included
files/functions cannot be loaded. after restart/refresh (with include) the
problem disappears and the files was loaded correctly. (perhaps the is a
problem with the cache/buffer?)

Original issue reported on code.google.com by bienmano...@googlemail.com on 3 Nov 2009 at 12:23

GoogleCodeExporter commented 9 years ago
I cannot confirm this. What I tested:

x.js:
=====
exports.x = function () {
        y();
}
var y = function () {
        system.stdout("y called \n");
}

main.js
=======
var x = require("./x").x;
x();

output:
=======
y called

This is obviously a correct behavior. If you are still having troubles using 
require,
it is necessary to post the files which demonstrate your issues.

Original comment by ondrej.zara on 3 Nov 2009 at 7:20

GoogleCodeExporter commented 9 years ago
To provide some more assistance, I just created a wikipage describing how 
modules
work and how to use them: http://code.google.com/p/v8cgi/wiki/Modules

Original comment by ondrej.zara on 3 Nov 2009 at 1:15

GoogleCodeExporter commented 9 years ago
ondrey, sorry for the delay. ok, ich have the problem in the weblib. tryied 
also with
the var n = require('n').n the effect is the same like require('n')? 

i reconstruct the test. require opens the function (works also with three 
files). 

Original comment by bienmano...@googlemail.com on 9 Nov 2009 at 12:51

GoogleCodeExporter commented 9 years ago
No, those are of course different things! It looks like you still do not get how
require works. By doing "var x = require('somestuff')", you assign the 
*exports* of
somestuff to variable x. By doing "var y = require('somestuff').z", you assign 
one
concrete part of exports (named "z") to variable y.

Using names mentioned above, one can achieve the same with
var x = require('somestuff');
var y = x.z;

Original comment by ondrej.zara on 9 Nov 2009 at 7:16

GoogleCodeExporter commented 9 years ago
Problem solved.

Original comment by ondrej.zara on 10 Nov 2009 at 8:48