0

We have a module that allows users to create some scripts.

I would like to determine if user has used correct properties etc.

For example user has wrote:

var test = session;

I can do:

var something = eval("session");
if (!something){
    // Throw error here
}

But i'm facing issues with this:

var test = session.id; // session id property is "id123456"

I thought i can do:

var something = eval("session.id");
if (!something){
    // Throw error here
}

But it seems it really does this:

var something = eval("id123456");

Any suggestions how can i determine wheter property exist in this object, also property in property and further?

As i said, i'm not trying to determine some certain object for some certain property, the strcture can be:

session.id.toString().name ... and further

In addition, i have just tried this:

session.hasOwnProperty("id"); // returned false

session.id // returned "id123456"
Developer
  • 4,158
  • 5
  • 34
  • 66
  • what is wrong with simply using `session[id][name]...`? I really don't see why eval would be needed here – Icepickle May 13 '17 at 10:10

1 Answers1

0

Try code below:

eval('var session = {id:"id1234"}');
var x = eval("session")
console.warn(eval("x.id"))
console.error(eval("x.id.toString()"))
console.log(x.id)
Yashar Aliabbasi
  • 2,663
  • 1
  • 23
  • 35