Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions src/SimpleCrawler.Js.Jint/JintFunctionSourceTagger.cs

This file was deleted.

25 changes: 5 additions & 20 deletions src/SimpleCrawler.Js.Jint/JintJsEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Acornima.Ast;
using Jint;
using Jint.Runtime;
using SimpleCrawler.Js.Abstractions;
Expand Down Expand Up @@ -30,12 +29,9 @@ public JintJsEngine(JintModuleCache moduleCache, JintScriptCache scriptCache, IM
.EnableModules(loader)
.CatchClrExceptions();

// Jint's default Function.prototype.toString() is "function name() { [native code] }" for every
// ordinary script function, not real source — unlike V8/real browsers. That made every bundle
// function look native to jQuery/Sizzle's native-code sniff (see browser/native.ts), not just the
// host DOM methods it deliberately marks. Scripts/modules are tagged with their own source text at
// prepare time (JintFunctionSourceTagger) so this can slice the real text back out.
options.Host.FunctionToStringHandler = static (_, node) => JintFunctionSourceTagger.TryGetSlice(node);
// Preserves correctness after 4.11 change https://github.com/sebastienros/jint/issues/2560
// https://github.com/sebastienros/jint/pull/2562
options.RetainFunctionSourceText = true;
});
}

Expand Down Expand Up @@ -63,9 +59,7 @@ public void Execute(string script)
{
try
{
var prepared = Engine.PrepareScript(script);
JintFunctionSourceTagger.Tag(prepared.Program, script);
_engine.Execute(in prepared);
_engine.Execute(script);
}
catch (JavaScriptException ex)
{
Expand All @@ -92,16 +86,7 @@ public void EvaluateModule(string specifier, string source, bool cache)
{
// An inline module's specifier is the page URL — unique per page, so caching its parsed form
// would retain one AST per crawled page; only stable-URL modules go through the shared cache.
Prepared<Module> prepared;
if (cache)
{
prepared = _moduleCache.GetOrPrepare(specifier, source);
}
else
{
prepared = Engine.PrepareModule(source, specifier);
JintFunctionSourceTagger.Tag(prepared.Program, source);
}
var prepared = cache ? _moduleCache.GetOrPrepare(specifier, source) : Engine.PrepareModule(source, specifier);
_engine.Modules.Add(specifier, builder => builder.AddModule(in prepared));
_engine.Modules.Import(specifier);
}
Expand Down
8 changes: 2 additions & 6 deletions src/SimpleCrawler.Js.Jint/JintModuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ private static Prepared<Module> PrepareOrEmpty(string source, string location)
{
try
{
var prepared = Engine.PrepareModule(source, location);
JintFunctionSourceTagger.Tag(prepared.Program, source);
return prepared;
return Engine.PrepareModule(source, location);
}
catch (ScriptPreparationException)
{
var prepared = Engine.PrepareModule(_emptyModule, location);
JintFunctionSourceTagger.Tag(prepared.Program, _emptyModule);
return prepared;
return Engine.PrepareModule(_emptyModule, location);
}
}
}
7 changes: 1 addition & 6 deletions src/SimpleCrawler.Js.Jint/JintScriptCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ internal sealed class JintScriptCache

public Prepared<Script> GetOrPrepare(string key, string source)
{
return _scripts.GetOrAdd(key, source, static (location, code) =>
{
var prepared = Engine.PrepareScript(code, location);
JintFunctionSourceTagger.Tag(prepared.Program, code);
return prepared;
});
return _scripts.GetOrAdd(key, source, static (location, code) => Engine.PrepareScript(code, location));
}
}
Loading