-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run alasql in nodejs vm #451
Comments
Thank you! What is the best replacement for |
So we can replcae with But I dont know if this solves the core of the problem: that we dont know if we can rely on any |
Yes, this does not solve the core problem. The core problem is "require" method is passed from main context to vm context so objects in alasql is not created by vm context. following is implement of instance of in js: function instance_of(L, R) { However, core problem is L and R may be created by different vm, so we do not know if other function have same problem with instanceof . I am still finding better ways. |
sounds good. I cant imagine we are the first library to front this when running in a js vm |
@xlvector Have you found out anything new? |
Sorry, I does not find better solution. I can only restrict my users can only do read operation in vm because write operation will generate new objects. |
:-( |
If we replace everything with named functions for the prototypes, we could just change everything from if(x instanceof yy.Y){
//do something
}else if (x instanceof yy.Z){
//do something else
} to switch(x.constructor.name){
case "Y":
//do something;
break;
case "Z":
//do something else;
break;
default:
//default case
break;
} This would probably be faster/result in less lines of code. function Select(params){
this.name = "Select";
yy.extend(this,params);
} NOTE: Function.prototype.name is immutable if the function is named EDIT vm.runInNewContext("a.constructor.name === 'Array' ", {a:[]}) returns true. |
Sounds interesting - but I dont quite get it. what is it exactly that needs to be replaced with a named function? |
instead of attaching prototypes directly to yy, you "name" them first. function Select(){
} instead of yy.Select = function(){} You then attach Select to yy later, like so yy.Select = Select; The only reason I mention is that a direct consequence of using the syntax
For issue #445 is that all functions become named functions. |
I don't use alasql in nodejs (I have used it a lot in nashorn/rhino, the latter being the main reason I'm pursuing #445 ), I was just saw this ticket and found it interesting. |
Ahh - I get it - so with the ECMA6 way of using |
Yep. You can even keep the if/else if/else structure, I just find switch more expressive. |
We found there is some problems about run alasql in nodejs vm, this is mainly because of this issue.
nodejs/node-v0.x-archive#1277
In alasql, there is many line like (x instanceof Array) to check if x is an array, and the better way is Array.isArray(x). Use (x instanceof Array) will cause some problem when running alasql in vm.
For example, in prepareFromData() function.
The text was updated successfully, but these errors were encountered: