# Eval and Webclient

**URL:** https://forum.servoy.com/t/eval-and-webclient/10763
**Category:** Classic Servoy
**Created:** [June 10, 2009, 9:44am UTC](https://forum.servoy.com/t/eval-and-webclient/10763 "2009-06-10T09:44:00Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)
#### Post date: [June 10, 2009, 9:44am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/1 "2009-06-10T09:44:00Z")

</div>

the eval in webclient procude different behaviour between two servers:

**Server Dev**  
JDK Information  
java.vm.name=Java HotSpot™ Client VM  
java.vm.version=11.0-b16  
java.vm.info=mixed mode, sharing  
java.vm.vendor=Sun Microsystems Inc.  
Operating System Information  
os.name=Windows 2003  
os.version=5.2  
os.arch=x86  
Everything is ok

**Prod Server**  
JDK Information  
java.vm.name=Java HotSpot™ Client VM  
java.vm.version=11.3-b02  
java.vm.info=mixed mode, sharing  
java.vm.vendor=Sun Microsystems Inc.  
Operating System Information  
os.name=Windows 2003  
os.version=5.2  
os.arch=x86  
I’ve got couldn’t eval the string …

Do you have any idea ?

---

<div class="post-metadata">

### Author: ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)
#### Post date: [June 10, 2009, 9:51am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/2 "2009-06-10T09:51:24Z")

</div>

And what is your question?

---

<div class="post-metadata">

### Author: ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)
#### Post date: [June 10, 2009, 9:57am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/3 "2009-06-10T09:57:10Z")

</div>

Sorry the question wasn’t really clear

I’ve got “couldn’t eval the string …” in the prod server log

Did you already have any strange eval behaviour between two java version ?

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [June 10, 2009, 3:28pm UTC](https://forum.servoy.com/t/eval-and-webclient/10763/4 "2009-06-10T15:28:47Z")

</div>

I noticed also a problem with eval()

I already created an issue in the support database. Case 217097

In Eclipse I get the following error:

> Source not found for module [C:/Users/Martin/servoy\_workspace\_development/MOD\_RSS\_HTMLTree/globals.js#645(eval): 1]

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 7:54am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/5 "2009-06-11T07:54:37Z")

</div>

what are you trying to eval?

---

<div class="post-metadata">

### Author: ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)
#### Post date: [June 11, 2009, 8:07am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/6 "2009-06-11T08:07:42Z")

</div>

Ive got mostly the error when i try to eval  
myvariable = globals.myfunction()  
or  
myvariable = globals.myfunction(‘arg1’,‘arg2’)

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [June 11, 2009, 8:15am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/7 "2009-06-11T08:15:14Z")

</div>

Johan,

See my case 217097. I added some coding how I tried to eval.

I use eval() in several ways:

```auto
str = 'globals.myMethod'
if (eval(str)) // To test if method exists
{
eval(str)(args)
}

```

But also

```auto
str = 'globals.myVar'
if (eval(str) == 1) // To test if this variable has value 1

```

And also

```auto
str = 'globals.myVar'
if (some test)
  str += ' = 1'
else
 str += ' = 2';
eval(str) // Set variable to 1 or 2

```

And also

```auto
str = 'globals.myVar'
if (some test)
  str += ' [1]'
else
 str += ' [2]';
str += ' = 3'
eval(str) // Give some array value the value 3

```

Of course these example are quite simple, but it shows the way eval() is used. I worked fine in 3.5 and some of the coding was originally written in 2.2!

By the way, I tried also the following and that is working, so it looks like it is perhaps eval() in combination with if-statement

```auto
str = 'globals.myVar'
val = eval(str)
if (val == 1) // To test if this variable has value 1

```

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 8:23am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/8 "2009-06-11T08:23:48Z")

</div>

> erdione:  
> Ive got mostly the error when i try to eval  
> myvariable = globals.myfunction()  
> or  
> myvariable = globals.myfunction(‘arg1’,‘arg2’)

so you are doing

eval(“myvariable = globals.myfunction()”);

why would you eval that?

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 8:26am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/9 "2009-06-11T08:26:06Z")

</div>

> martinh:  
> Johan,
> 
> See my case 217097. I added some coding how I tried to eval.
> 
> I use eval() in several ways:

why are you evalling that kind of stuff like that?

why not just

if (globals[‘mymethod’])  
{  
globals’mymethod’  
}

way faster then evalling.

---

<div class="post-metadata">

### Author: ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)
#### Post date: [June 11, 2009, 8:30am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/10 "2009-06-11T08:30:00Z")

</div>

I eval that because for example myfunction can be dynamically change (in my case database driven)

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 9:01am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/11 "2009-06-11T09:01:57Z")

</div>

```auto
myvariable = globals[dynamicname]();

```

should work fine and even better/faster.

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [June 11, 2009, 9:03am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/12 "2009-06-11T09:03:35Z")

</div>

> jcompagner:
> 
> > martinh:  
> > Johan,
> > 
> > See my case 217097. I added some coding how I tried to eval.
> > 
> > I use eval() in several ways:
> 
> why are you evalling that kind of stuff like that?
> 
> why not just
> 
> if (globals[‘mymethod’])  
> {  
> globals’mymethod’  
> }
> 
> way faster then evalling.

Because mymethod is a variable name (callback method)

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 9:27am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/13 "2009-06-11T09:27:23Z")

</div>

```auto
globals[variableHoldingTheNameOfTheMethodYouWantToCall]()

```

really guys, eval is almost never needed…

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [June 11, 2009, 9:55am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/14 "2009-06-11T09:55:48Z")

</div>

OK, I’ll see if I can change my code, but how about the following:

```auto
var _method = arguments[0];

if (eval(_method))
{
   eval(_method)()
}

```

And the argument that I get, is a method on a form

So Arguments 0 = forms.myForm.myMethod

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [June 11, 2009, 10:02am UTC](https://forum.servoy.com/t/eval-and-webclient/10763/15 "2009-06-11T10:02:53Z")

</div>

```auto
function test()
{
	var name = "called"; // arguments[0];
	var argument = "from test";
	this[name](argument);
}

function called()
{
	application.output("called with argument: " + arguments[0])
}

```
