Skip to content

Commit

Permalink
Improved connection to weakly bound document
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Dec 26, 2015
1 parent ea6f190 commit c4520bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 0 additions & 1 deletion AngleSharp/Dom/Html/HtmlLinkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using AngleSharp.Network;
using AngleSharp.Services.Styling;
using System;
using System.Threading.Tasks;

/// <summary>
/// Represents the HTML link element.
Expand Down
22 changes: 12 additions & 10 deletions AngleSharp/Dom/Html/HtmlScriptElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ void RunFromSource()
/// More information available at:
/// http://www.w3.org/TR/html5/scripting-1.html#prepare-a-script
/// </summary>
internal Boolean Prepare()
internal Boolean Prepare(Document document)
{
var options = Owner.Options;
var options = document.Options;
var eventAttr = this.GetOwnAttribute(AttributeNames.Event);
var forAttr = this.GetOwnAttribute(AttributeNames.For);
var src = Source;
Expand Down Expand Up @@ -231,14 +231,14 @@ internal Boolean Prepare()
{
if (src.Length != 0)
{
return InvokeLoadingScript(this.HyperReference(src));
return InvokeLoadingScript(document, this.HyperReference(src));
}
Owner.QueueTask(FireErrorEvent);

document.QueueTask(FireErrorEvent);
}
else
{
if (_parserInserted && Owner.GetStyleSheetDownloads().Any())
if (_parserInserted && document.GetStyleSheetDownloads().Any())
{
_runScript = RunFromSource;
return true;
Expand All @@ -250,10 +250,9 @@ internal Boolean Prepare()
return false;
}

Boolean InvokeLoadingScript(Url url)
Boolean InvokeLoadingScript(Document document, Url url)
{
var fromParser = true;
var document = Owner;

//Just add to the (end of) set of scripts
if (!_parserInserted || IsDeferred || IsAsync)
Expand Down Expand Up @@ -304,10 +303,13 @@ void FireAfterScriptExecuteEvent()

ScriptOptions CreateOptions()
{
var document = Owner;
var context = document != null ? document.DefaultView : null;

return new ScriptOptions
{
Context = Owner.DefaultView,
Document = Owner,
Context = context,
Document = document,
Element = this,
Encoding = TextEncoding.Resolve(CharacterSet)
};
Expand Down
7 changes: 6 additions & 1 deletion AngleSharp/Network/Default/BaseLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ protected virtual IDownload DownloadAsync(Request request, INode originator)
/// <returns>The enumerable over all active downloads.</returns>
public IEnumerable<IDownload> GetDownloads()
{
return _downloads.ToArray();
lock (this)
{
return _downloads.ToArray();
}
}

/// <summary>
Expand All @@ -115,7 +118,9 @@ protected async Task<IResponse> LoadAsync(Request request, CancellationToken can
var evt = new RequestStartEvent(requester, request);

if (events != null)
{
events.Publish(evt);
}

var result = await requester.RequestAsync(request, cancel).ConfigureAwait(false);
evt.FireEnd();
Expand Down
2 changes: 1 addition & 1 deletion AngleSharp/Parser/Html/HtmlDomBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,7 @@ void HandleScript(HtmlScriptElement script)
CloseCurrentNode();
_currentMode = _previousMode;

if (script.Prepare())
if (script.Prepare(_document))
{
_waiting = RunScript(script);
}
Expand Down

0 comments on commit c4520bb

Please sign in to comment.