Skip to content

Commit 0775a9c

Browse files
committed
Fix EvilBeaver#575: ThisObject.
1 parent 5326c38 commit 0775a9c

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/ScriptEngine.HostedScript/HostedScriptEngine.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ This Source Code Form is subject to the terms of the
1010
using ScriptEngine.Machine;
1111
using ScriptEngine.Machine.Contexts;
1212
using System.Collections.Generic;
13-
using System.Linq;
1413

15-
using OneScript.DebugProtocol;
1614

1715
namespace ScriptEngine.HostedScript
1816
{
@@ -174,7 +172,7 @@ public CompilerService GetCompilerService()
174172
InitializeDirectiveResolver();
175173

176174
var compilerSvc = _engine.GetCompilerService();
177-
compilerSvc.DefineVariable("ЭтотОбъект", SymbolType.ContextProperty);
175+
compilerSvc.DefineVariable("ЭтотОбъект", "ThisObject", SymbolType.ContextProperty);
178176
return compilerSvc;
179177
}
180178

src/ScriptEngine.HostedScript/LibraryLoader.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This Source Code Form is subject to the terms of the
1111
using System.Collections.Generic;
1212
using System.IO;
1313
using System.Linq;
14-
using System.Text;
1514

1615
namespace ScriptEngine.HostedScript
1716
{
@@ -57,7 +56,7 @@ public static LibraryLoader Create(ScriptingEngine engine, RuntimeEnvironment en
5756
{
5857
var code = engine.Loader.FromFile(processingScript);
5958
var compiler = engine.GetCompilerService();
60-
compiler.DefineVariable("ЭтотОбъект", SymbolType.ContextProperty);
59+
compiler.DefineVariable("ЭтотОбъект", "ThisObject", SymbolType.ContextProperty);
6160

6261
for (int i = 0; i < _methods.Count; i++)
6362
{
@@ -135,6 +134,10 @@ protected override int FindOwnProperty(string name)
135134
{
136135
return 0;
137136
}
137+
if(StringComparer.OrdinalIgnoreCase.Compare(name, "ThisObject") == 0)
138+
{
139+
return 0;
140+
}
138141

139142
return base.FindOwnProperty(name);
140143
}

src/ScriptEngine/Machine/Contexts/AttachedScriptsFactory.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ This Source Code Form is subject to the terms of the
66
----------------------------------------------------------*/
77
using System;
88
using System.Collections.Generic;
9-
using System.Linq;
109
using System.Text;
1110
using ScriptEngine.Environment;
1211
using System.Security.Cryptography;
@@ -156,12 +155,12 @@ private IRuntimeContextInstance LoadAndCreate(CompilerService compiler, Environm
156155

157156
public ScriptModuleHandle CreateModuleFromSource(CompilerService compiler, Environment.ICodeSource code, ExternalContextData externalContext)
158157
{
159-
compiler.DefineVariable("ЭтотОбъект", SymbolType.ContextProperty);
158+
compiler.DefineVariable("ЭтотОбъект", "ThisObject", SymbolType.ContextProperty);
160159
if (externalContext != null)
161160
{
162161
foreach (var item in externalContext)
163162
{
164-
compiler.DefineVariable(item.Key, SymbolType.ContextProperty);
163+
compiler.DefineVariable(item.Key, null, SymbolType.ContextProperty);
165164
}
166165
}
167166

@@ -190,7 +189,7 @@ public static IRuntimeContextInstance ScriptFactory(string typeName, IValue[] ar
190189
var module = _instance._loadedModules[typeName];
191190

192191
var newObj = new UserScriptContextInstance(module, typeName, arguments);
193-
newObj.AddProperty("ЭтотОбъект", newObj);
192+
newObj.AddProperty("ЭтотОбъект", "ThisObject", newObj);
194193
newObj.InitOwnData();
195194
newObj.Initialize(_instance._engine.Machine);
196195

src/ScriptEngine/ScriptingEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public LoadedModuleHandle LoadModuleImage(ScriptModuleHandle moduleImage)
100100
internal IRuntimeContextInstance NewObject(LoadedModule module, ExternalContextData externalContext = null)
101101
{
102102
var scriptContext = new Machine.Contexts.UserScriptContextInstance(module, "Сценарий");
103-
scriptContext.AddProperty("ЭтотОбъект", scriptContext);
103+
scriptContext.AddProperty("ЭтотОбъект", "ThisObject", scriptContext);
104104
if (externalContext != null)
105105
{
106106
foreach (var item in externalContext)

0 commit comments

Comments
 (0)