Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Problem using gauss with NODE_MODULE_CONTEXTS=0 #6

Closed
rafaparafernalia opened this Issue Mar 12, 2012 · 5 comments

Comments

Projects
None yet
2 participants

Hello,

I am using your library and I detected a problem. When I use your library in a file, it automatically modify the prototype of built-in Array object, without my permission ;)

I was researching and I found that the problem is that NODE_MODULE_CONTEXTS is zero for default so, your library overwrite Array built-in.

If you put the following content in a file, for example prueba.js:
var gauss = require("gauss");

var arreglo=[1,2];
for(var i in arreglo){
console.log(i);
}

You will see that shows the properties that you add to Array. If you put the lines in the REPL, the program will be ok, this happen because the variable NODE_MODULE_CONTEXTS is set different in both cases. See: joyent/node#771

I fixed the problem adding,
In vector.js, line 6:
var Array=function () {};

In timeseries.js, line 6:
var Array = require('./vector');

Best regards,

Hello,

Sorry, I don't fix the problem, clone and copy are not running correctly.

Best regards,

Owner

fredrick commented Mar 12, 2012

I am aware of this and will investigate, some of this is beyond the control of the module, and is in the nature of node/JavaScript being a dynamic language. A temporary fix would be to force NODE_MODULE_CONTEXTS=1: NODE_MODULE_CONTEXTS=1 node my_gauss_client.js.

However, this is less than ideal. The key thing I want to maintain is the ability to access members of the Vector like an array (For example: new gauss.Vector(1, 2, 3)[0] will return 1), regardless if we are monkey patching or not.

Owner

fredrick commented Mar 12, 2012

Also, what version of Node are you using? As of 0.6, I believe NODE_MODULE_CONTEXTS=0 across the board. Starting the REPL with NODE_MODULE_CONTEXTS=1 disables the use of any CommonJS external modules, so using Gauss or any module for that matter from the REPL won't work.

`v0.6.10
fredricks-macbook-pro:Desktop Fredrick$ NODE_MODULE_CONTEXTS=1 node

require
ReferenceError: require is not defined
at repl:1:2
at REPLServer.eval (repl.js:80:21)
at Interface. (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream. (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
at ReadStream._emitKey (tty.js:327:10)
`

I am using 0.6.8 version, but I always use "node" through files and I never use the REPL interface.

If you use NODE_MODULE_CONTEXTS=1 through files the "require" keyword functions.

Best regards,

Owner

fredrick commented May 2, 2012

This issue has been fixed as of v0.2.4. Can you confirm @rafaparafernalia?

@fredrick fredrick closed this May 2, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment