jaggery vm.js was implemeted.this class is responsible to compile and load
script to the current scope

Script can be compiled save and run later or can be compiled in this
context and also can compile and run in a new global context.

main functions in vm.js is

     * runInThisContext(fileName, content)
     * runInNewContext(fileName, content)
     * compileScript(fileName, content)
     * runScript(compiledScript, args)
     * isContext().

*Arguments*

# fileName
      scipt filename which content is going to load

# content
      content of a javascript file as a string

# compileScript
      return value from compiledScript method will be a Script Function.if
you
      execute Object.prototype.toString.call(compileScript), output will be
       '[Object Function]'

*examples*

var k = vm.runInNewContext('buddhi.js', 'function(sandbox){ sandbox.count
+= 1; sandbox.name = "kitty"};');
    var sandbox = { animal: "cat",count: 2}
    k(sandbox);
    print(sandbox.count);
output - 3;

in runInThisContext and runInNewContext functions, if u do as above(set
function as a content ) you will get a scriptfunction as a return you can
execute that function as above

if u do as follow.script will be executed.but returns nothing.

var k = vm.runInNewContext('buddhi.js', 'var foo = {age:23};
print(foo.age)')
output - 23;

{ print(Object.prototype.toString.call(k))    // --- print [Object
Undefined] };

*limitations of code*
in compileScript function you cannot use second approach because runScript
method expecting script function to execute.

compileScript and runScript methods will be further developed to bypass
this issue



-- 
Thanks & Best Regards,

*Buddhi Nipun Mihara*
Software Engineer(intern)
WSO2, Inc.:http://wso2.com
lean.enterprise.middleware
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to