Home Notices Documents Classes Download Others Rice
Classes  >  jsexecutor  >  Execute(string)
jsexecutor class : Execute(string) method

Description

Executes JavaScript code passed by the argument.

Syntax

jsexecutorInstance.Execute(string jsCode)

Arguments

ClassNameDescription
stringjsCodeJavaScript code.

Return value

ClassDescription
int,real,string, or boolIt has stored a return value from the JavaScript code.

Sample code

1:

jsexecutor jse = new jsexecutor();

2:

string jsCode = "(function (){return 100;})();";

3:

int retInt = jse.Execute(jsCode); // The retInt is 100.

Notes

The return value from JavaScript must be evaluable as the int, real, string, or bool.

If the return value from JavaScript function can not evaluate as the above classes, an empty proxy is returned.Fixed in Ver 1.0.0.1.

If the return value from the JavaScript function can be evaluated as the above class, the corresponding Rice class is returned. Otherwise, the void class is returned.

Note for Ver 1.0.0.1

Escape sequences may not work properly in strings of the JavaScript code given as arguments.

Note for Ver 1.0.0.2

Above escape sequences problem is fixed.

To get the return value from JavaScript using this method, please write javascript in the form of immediate function as follows.

string oh = Execute("(function (){return 'www';}());");

An exception is raised if you give the return statement directly as follows.

string oh = Execute("return 'www';"); // Exception!

Links for reference

None.

Copyright © Rice All rights reserved.