AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.
https://anglesharp.github.io
MIT License
103 stars 22 forks source link

Fixes in scripting library to enable jQuery to parse and execute #1

Closed miroslav22 closed 9 years ago

miroslav22 commented 9 years ago

Hi,

I've made a few fixes and improvements to the scripting library, which in conjunction with the changes I made in the Core library allow jQuery to parse and execute over the DOM

FlorianRappl commented 9 years ago

Definitely good changes. I will happily accept the PR once the new project settings have been discussed.

One remark though: I am currently working on the generation of a set of classes to wrap the AngleSharp "native" types for Jint. That way reflection is not needed as heavily as currently. Also the DOM represented in JavaScript will behave as in the browser (with the prototype chain as seen in any browser). Once I finished the generation the current method of exposing DOM objects to Jint will be completely replaced.

miroslav22 commented 9 years ago

Sounds great! Really loving this project.

I've found that this code still has an issue that prevents the scope of functions and properties surviving outside of the script tag they're declared in. ie If you have 2 script tags and the second references a function that's declared in the first then it can't find it.

I'll submit another change to fix this too.

FlorianRappl commented 9 years ago

Yes the 2 script thing is definitely something worth having. The GetEngine from the IScriptingService is thought to return the same engine for any request (if the underlying service is the same). So the way to implement this is possibly by using the Context property of the ScriptOptions. I would suggest making a list that contains created contexts (which wrap the IWindow).

If an IWindow does not have a context, a new one is created and the script is evaluated. Otherwise the script is evaluated in the existing context.