progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
103
AspClassic.Scripting/Hosting/CompiledCode.cs
Normal file
103
AspClassic.Scripting/Hosting/CompiledCode.cs
Normal file
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace AspClassic.Scripting.Hosting;
|
||||
|
||||
public sealed class CompiledCode : MarshalByRefObject
|
||||
{
|
||||
private readonly ScriptEngine _engine;
|
||||
|
||||
private readonly ScriptCode _code;
|
||||
|
||||
private ScriptScope _defaultScope;
|
||||
|
||||
internal ScriptCode ScriptCode => _code;
|
||||
|
||||
public ScriptEngine Engine => _engine;
|
||||
|
||||
public ScriptScope DefaultScope
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_defaultScope == null)
|
||||
{
|
||||
Interlocked.CompareExchange(ref _defaultScope, new ScriptScope(_engine, _code.CreateScope()), null);
|
||||
}
|
||||
return _defaultScope;
|
||||
}
|
||||
}
|
||||
|
||||
internal CompiledCode(ScriptEngine engine, ScriptCode code)
|
||||
{
|
||||
_engine = engine;
|
||||
_code = code;
|
||||
}
|
||||
|
||||
public dynamic Execute()
|
||||
{
|
||||
return _code.Run(DefaultScope.Scope);
|
||||
}
|
||||
|
||||
public dynamic Execute(ScriptScope scope)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(scope, "scope");
|
||||
return _code.Run(scope.Scope);
|
||||
}
|
||||
|
||||
public T Execute<T>()
|
||||
{
|
||||
return _engine.Operations.ConvertTo<T>((object)Execute());
|
||||
}
|
||||
|
||||
public T Execute<T>(ScriptScope scope)
|
||||
{
|
||||
return _engine.Operations.ConvertTo<T>((object)Execute(scope));
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap()
|
||||
{
|
||||
return new ObjectHandle((object)Execute());
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap(ScriptScope scope)
|
||||
{
|
||||
return new ObjectHandle((object)Execute(scope));
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap(out ObjectHandle exception)
|
||||
{
|
||||
exception = null;
|
||||
try
|
||||
{
|
||||
return new ObjectHandle((object)Execute());
|
||||
}
|
||||
catch (Exception o)
|
||||
{
|
||||
exception = new ObjectHandle(o);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap(ScriptScope scope, out ObjectHandle exception)
|
||||
{
|
||||
exception = null;
|
||||
try
|
||||
{
|
||||
return new ObjectHandle((object)Execute(scope));
|
||||
}
|
||||
catch (Exception o)
|
||||
{
|
||||
exception = new ObjectHandle(o);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
|
||||
public override object InitializeLifetimeService()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue