Skip to content

Commit

Permalink
Code Cache references improved
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Aug 31, 2024
1 parent 20cc5e5 commit 74f87a7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions YantraJS.Core/Core/Function/JSFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,14 @@ public static JSValue InvokeSuperConstructor(JSValue newTarget, JSValue super, i

var bodyText = body is JSString @string ? @string.value : body.ToString();
string location = null;
JSContext.Current.DispatchEvalEvent(ref bodyText, ref location);
var context = JSContext.Current;
context.DispatchEvalEvent(ref bodyText, ref location);

var fx = new JSFunction(JSFunction.empty, "internal", bodyText);


// parse and create method...
var fx1 = CoreScript.Compile(bodyText, "internal", sargs);
var fx1 = CoreScript.Compile(bodyText, "internal", sargs, codeCache: context.CodeCache);
fx.f = fx1;
return fx;
}
Expand Down
10 changes: 5 additions & 5 deletions YantraJS.Core/Core/JSContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using YantraJS.Debugger;
using YantraJS.Core.Clr;
using YantraJS.Core.Core;
using YantraJS.Emit;

namespace YantraJS.Core
{
Expand Down Expand Up @@ -678,6 +679,7 @@ internal long SetInterval(int delay, JSFunction f, in Arguments a)

}

public ICodeCache CodeCache = DictionaryCodeCache.Current;

internal ConcurrentDictionary<long, JSPromise> PendingPromises
= new ConcurrentDictionary<long, JSPromise>();
Expand All @@ -692,17 +694,15 @@ public JSValue Eval(string code, string codeFilePath = null, JSValue @this = nul
{
if (Debugger == null)
{


var fx = CoreScript.Compile(code, codeFilePath);
var fx = CoreScript.Compile(code, codeFilePath, codeCache: CodeCache);
return @this == null
? fx(in Arguments.Empty)
: fx(new Arguments(@this));
}

try
{
var f = CoreScript.Compile(code, codeFilePath);
var f = CoreScript.Compile(code, codeFilePath, codeCache: CodeCache);
Debugger.ScriptParsed(this.ID, code, codeFilePath);
return @this == null
? f(in Arguments.Empty)
Expand All @@ -724,7 +724,7 @@ public JSValue Eval(string code, string codeFilePath = null, JSValue @this = nul
/// <returns></returns>
public async Task<JSValue> ExecuteAsync(string code, string codeFilePath = null)
{
var r = CoreScript.Evaluate(code, codeFilePath);
var r = CoreScript.Evaluate(code, codeFilePath, codeCache: CodeCache);
var wt = this.WaitTask;
if (wt != null)
await wt;
Expand Down
2 changes: 1 addition & 1 deletion YantraJS.Core/Core/Module/JSModuleContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ internal protected virtual async Task CompileModuleAsync(JSModule module)
"import",
"__fileame",
"__dirname"
});
}, codeCache: CodeCache);

var result = factory(new Arguments(module, new JSValue[]
{
Expand Down
6 changes: 3 additions & 3 deletions YantraJS.Core/CoreScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ internal static JSFunctionDelegate Compile(in StringSpan code, string location =

public static JSValue EvaluateWithTasks(string code, string location = null)
{
var fx = Compile(code, location);
var result = JSUndefined.Value;
var ctx = JSContext.Current;
var fx = Compile(code, location, codeCache: ctx.CodeCache);
AsyncPump.Run(() =>
{
result = fx(new Arguments(ctx));
Expand All @@ -67,9 +67,9 @@ public static JSValue EvaluateWithTasks(string code, string location = null)

public static JSValue Evaluate(string code, string location = null, ICodeCache codeCache = null)
{
var fx = Compile(code, location, null, codeCache);
var result = JSUndefined.Value;
var ctx = JSContext.Current;
var fx = Compile(code, location, null, codeCache ?? ctx.CodeCache);
result = fx(new Arguments(ctx));
return result;
}
Expand All @@ -79,9 +79,9 @@ public static async Task<JSValue> EvaluateAsync(
string location = null,
ICodeCache codeCache = null)
{
var fx = Compile(code, location, null, codeCache);
var result = JSUndefined.Value;
var ctx = JSContext.Current;
var fx = Compile(code, location, null, codeCache ?? ctx.CodeCache);
result = fx(new Arguments(ctx));
if (ctx.WaitTask != null)
{
Expand Down
2 changes: 1 addition & 1 deletion YantraJS.Core/Debugger/V8Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public V8ReturnValue CallFunctionOn(CallFunctionOnParams a)

try {

var fx = CoreScript.Compile(a.FunctionDeclaration);
var fx = CoreScript.Compile(a.FunctionDeclaration, codeCache: c.CodeCache);
var previous = JSContext.Current;
try {
JSContext.Current = c;
Expand Down
2 changes: 1 addition & 1 deletion YantraJS/REPL/YantraRepl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Run()
string result;
try
{
result = CoreScript.Evaluate(command).ToString();
result = CoreScript.Evaluate(command, codeCache: CodeCache).ToString();
}
catch (JSException ex1) {
result = ex1.Error[KeyStrings.stack].ToString();
Expand Down

0 comments on commit 74f87a7

Please sign in to comment.