diff --git a/YantraJS.Core/Core/Function/JSFunction.cs b/YantraJS.Core/Core/Function/JSFunction.cs index 80b2ec24..e7abd3cd 100644 --- a/YantraJS.Core/Core/Function/JSFunction.cs +++ b/YantraJS.Core/Core/Function/JSFunction.cs @@ -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; } diff --git a/YantraJS.Core/Core/JSContext.cs b/YantraJS.Core/Core/JSContext.cs index d9eeef2a..bbb31491 100644 --- a/YantraJS.Core/Core/JSContext.cs +++ b/YantraJS.Core/Core/JSContext.cs @@ -25,6 +25,7 @@ using YantraJS.Debugger; using YantraJS.Core.Clr; using YantraJS.Core.Core; +using YantraJS.Emit; namespace YantraJS.Core { @@ -678,6 +679,7 @@ internal long SetInterval(int delay, JSFunction f, in Arguments a) } + public ICodeCache CodeCache = DictionaryCodeCache.Current; internal ConcurrentDictionary PendingPromises = new ConcurrentDictionary(); @@ -692,9 +694,7 @@ 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)); @@ -702,7 +702,7 @@ public JSValue Eval(string code, string codeFilePath = null, JSValue @this = nul 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) @@ -724,7 +724,7 @@ public JSValue Eval(string code, string codeFilePath = null, JSValue @this = nul /// public async Task 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; diff --git a/YantraJS.Core/Core/Module/JSModuleContext.cs b/YantraJS.Core/Core/Module/JSModuleContext.cs index 6a6b33e2..786c953a 100644 --- a/YantraJS.Core/Core/Module/JSModuleContext.cs +++ b/YantraJS.Core/Core/Module/JSModuleContext.cs @@ -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[] { diff --git a/YantraJS.Core/CoreScript.cs b/YantraJS.Core/CoreScript.cs index 59365dba..dc65c915 100644 --- a/YantraJS.Core/CoreScript.cs +++ b/YantraJS.Core/CoreScript.cs @@ -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)); @@ -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; } @@ -79,9 +79,9 @@ public static async Task 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) { diff --git a/YantraJS.Core/Debugger/V8Runtime.cs b/YantraJS.Core/Debugger/V8Runtime.cs index e452c4d7..9888d7e3 100644 --- a/YantraJS.Core/Debugger/V8Runtime.cs +++ b/YantraJS.Core/Debugger/V8Runtime.cs @@ -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; diff --git a/YantraJS/REPL/YantraRepl.cs b/YantraJS/REPL/YantraRepl.cs index 46c235eb..0f584d3c 100644 --- a/YantraJS/REPL/YantraRepl.cs +++ b/YantraJS/REPL/YantraRepl.cs @@ -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();