eval

Setting variables by name in Java

别等时光非礼了梦想. 提交于 2019-11-26 23:09:31
问题 I'm looking to implement something in Java along the lines of: class Foo{ private int lorem; // private int ipsum; public setAttribute(String attr, int val){ //sets attribute based on name } public static void main(String [] args){ Foo f = new Foo(); f.setAttribute("lorem",1); f.setAttribute("ipsum",2); } public Foo(){} } ...where a variable is set based on the variable name without the variable names hard-coded and without using any other data structures. Is this possible? 回答1: Here's how

Doing math in vb.net like Eval in javascript

我只是一个虾纸丫 提交于 2019-11-26 23:04:14
Is there any way to parse a string in vb.net (like, built in methods), that can do math like Eval can? For example, 3+(7/3.5) as a string would return 2. I am not asking for you to code this for me, I just want to know if there is a built in way to do this, if there is not I will code it myself. I can wager that it would not be able to parse stuff like Sin(90) on its own, and I understand that would need to be replaced by Math.Sin(90). If there is a built in method, how do you use it? Ahmad Mageed There's a shortcut for limited (ie. simple) math expressions by using the DataTable.Compute

Is Javascript eval() so dangerous? [duplicate]

若如初见. 提交于 2019-11-26 22:56:17
Possible Duplicate: When is JavaScript’s eval() not evil? I am writing a script in which users have to write in a currency amount, some examples could be (user input >> converts to), with USD as default currency: 50 >> 50.0 USD 50.5 >> 50.5 USD 50+1 USD >> 51.0 USD 50 GBP >> 50.0 GBP I want to make this as smooth as possible, therefore I want to use JavaScript (it's a web app based on PHP/MySql + JavaScript). I want to use regex to filter the input, run it through eval() and return it. Is this a bad idea? I've read some topics about eval() being a security issue. I just don't see how. A user

JSinDeep1:探索执行环境 (Execution Context)-ES3篇

情到浓时终转凉″ 提交于 2019-11-26 22:48:27
JSinDeep1: 探索执行环境 (Execution Context)-ES3 篇 声明 JSinDeep 系列文章主要内容为作者对 ECMA-262 标准 中一些概念的理解和探究,同时意在帮助大家快速理解。本着严谨的态度,同时又需避免 API 式的枯燥细节罗列。文章会以适当插图、例子去诠释概念,致力于通俗易懂。更具体、严谨、完整的描述建议阅读 ECMA262 文档。碍于作者水平有限,文中若有错误,欢迎大家批评指正。 *其它版本: English-Blog , English-PDF , Chinese-Blog , Chinese-PDF 概要 在我们写JavaScript代码时会定义一些变量、函数等。解释器在执行这些代码时是如何处理并找到我们定义的这些数据的?在程序执行时,引用这些变量等操作的背后都发生了什么?本文主要探讨 ECMA-262-3 标准 中的执行环境 (Execution Context) 及与之相关的一些内部机制和模型。 定义 当程序执行的控制权转移至ECMAScript可执行代码时,会进入到一个执行环境中 (Execution Context,缩写为EC) 。在一个EC内也可能进入到一个新的EC,这些EC逻辑上 1 会形成一个栈 (Stack) 。 EC 是程序运行时动态创建的。例如:每一个函数在被调用时都会创建一个EC,重复调用函数 (包含递归调用的情形

Note for Strict Mode in ECMA-262-5

萝らか妹 提交于 2019-11-26 22:48:18
Reason 1. provide more thorough error checking 2. avoid error-prone constructs 3. clarifies many ambiguities in the 3rd edition specification 4. others make ECMAScript code more robust Common ways 1. strict script // before any code "use strict" ; var v = "I'm a strict code" ; 2. strict function function foo() { "use strict" ; return "I'm a strict function" ; } Changes 1. impossible to accidentally create global variables "use strict" ; mistypedVariable = 1; // throws a ReferenceError 2. makes assignments which would otherwise silently fail throw an exception "use strict" ; NaN = true ; //

eval的两组性能测试数据

喜夏-厌秋 提交于 2019-11-26 22:48:09
引发了最近对eval火爆的讨论,刚好之前也做过类似的测试,我也跟风凑个热闹,提供两组数据供大家参考。 测试环境: a. 机器:Intel(R) Corei7-2720 2.2Ghz (4核心8线程)、内存8Gb b. OS:Windows 7 Enterprise SP1 64-bit c. 浏览器: b.1 Google Chrome 21.0.1180.79 m b.2 Firefox 14.0.1 b.3 IE9.0.8112.16421 d. 测试方法 d.1 每个用例测试5次,耗时取最小值。 d.2 测试过程中 没有 开启Firebug或Chrome Console,开启这些工具会使时间倍增,很难在有效时间内得到该用例结果 用例A1: 我们在内联函数中调用空的eval("") ! function () { var a = 1, b = 2, c = true ; function func() { var d = 2; e = !c; eval(""); } for ( var i = 0; i < 2999999; i++) { func(i, i + 1, i + 2); } }(); 用例A2: 注释掉内联函数中的eval("") !function() { var a = 1 , b = 2 , c = true ; function func() { var

When is `eval` in Ruby justified?

浪尽此生 提交于 2019-11-26 22:29:50
" Is 'eval' supposed to be nasty? " inspired this one: Mostly everybody agrees that eval is bad, and in most cases there is more elegant/safer replacement. So I wanted to ask: if eval is misused that often, is it really needed as a language feature? Is it doing more evil than good? Personally, the only place I find it useful is to interpolate strings provided in config file. Edit: The intention of this question is to get as many real-life cases as possible when eval is the only or the best solution. So please, don't go into "should a language limit a programmer's creativity" direction. Edit2:

Eval script for server side control's ID property?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 22:11:29
问题 Using the following Eval script for setting ID property causes error. Error message: the server tag is not well formed. <asp:Panel runat="server" ID="<%# Eval("RENTER_ID") %>" Visible="false"> Even replacing "" with '' of ID property generates error. While using '', its error message "The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat="server" id="Button1" /> " Any ideas to solve this? 回答1: You can't do it. Why do you

How to run php code from file_get_contents or file in a function

妖精的绣舞 提交于 2019-11-26 21:34:11
问题 I am designing my own MVC pattern to ease the process of creating homepages. My templating system needs my controller class to output my views. This means I have to output the file through a php function. I have been searching for some a while now and can't seem to find a solution. How can I, through a PHP function, run a string representing some source code ("< ?", "< ?php", "? >" and so on) as php? Eval would not take my < ? signs (and I read that function is crap for some reason). 回答1: You

How to run a string as a command in VBA

安稳与你 提交于 2019-11-26 21:22:53
问题 I have this simple VBA code below, and I don't know why is not working. Sub Run() test = "MsgBox" & """" & "Job Done!" & """" Application.Run test End Sub What I want to do is to put the VBA Command into a variable as text and run it as a command. In this case, I want to run like MsgBox "Job Done!" and print just: Job Done! 回答1: You may be tempted by adding your own string "Executer": Sub StringExecute(s As String) Dim vbComp As Object Set vbComp = ThisWorkbook.VBProject.VBComponents.Add(1)