Coder Social home page Coder Social logo

Simulate/Emulate DOM? about v8js HOT 7 CLOSED

phpv8 avatar phpv8 commented on August 21, 2024
Simulate/Emulate DOM?

from v8js.

Comments (7)

yllierop avatar yllierop commented on August 21, 2024

@stutteringp0et — hmm I'll need to think about what would be the best way to accomplish this. Anyone else have any ideas?

from v8js.

stutteringp0et avatar stutteringp0et commented on August 21, 2024

I also found envjs, but that's geared toward rhino, and again - I'm not sure how to load it other than stringing all of the files together and introducing it as a string.

I'll start with a overview of what I was trying to accomplish (done now), followed by what I did in V8Js to accomplish it.

The CSS interpreter less.js has only one official parser - their javascript interpreter. Unofficial interpreters exist for PHP and .net - but neither can fully realize the full feature set of less.js because they can't interpret JS directly - so if an input file uses JS in any of the settings - that file will fail in the unofficial interpreters.

So, my goal was to use V8Js to give less.js the environment it requires to execute serverside. The problem was that less.js, upon load, scans the DOM for scripts to process - halting operation in V8Js immediately - because there's no DOM.

So, in V8Js, I executed this string first:
window = this;window.location={href:"file://",port:""};document={getElementsByTagName:function(){return []}};

less.js gets the responses it's expecting (even though there is still no DOM), allowing me to call it as a class to process strings instead of the content of dom elements.

Still, I'm sure it would be beneficial to have a full DOM in V8Js, I'm just not guru enough to figure out how to do it.

from v8js.

beest avatar beest commented on August 21, 2024

If you only need LESS compilation then it should be possible without any DOM.

LESS can be used with node.js and without DOM support. However, it seems to "require" other files in order to initialise the compiler.

I've just submitted a pull request that will add CommonJS "require" support to V8Js. I think this will get you a step closer to having LESS work in V8Js.

from v8js.

stutteringp0et avatar stutteringp0et commented on August 21, 2024

I already have it running. I used the line of code I posted earler to
fool less into thinking it had a DOM.

The LESS server side script has specific detection for nodejs, rhino and
one other that I can't remember offhand. I spent some time looking up
the objects that rhino and node make available and it was less trouble
to go back to the client script and fake a DOM.

from v8js.

beest avatar beest commented on August 21, 2024

Sorry, my bad - I didn't pick up that you had this working. Great to hear that you found a solution.

from v8js.

christiaan avatar christiaan commented on August 21, 2024

@stutteringp0et You might also want to check out https://github.com/andreasgal/dom.js/ it emulates the DOM in plain JS.

from v8js.

cscott avatar cscott commented on August 21, 2024

@stutteringp0et, @christiaan https://github.com/fgnass/domino is a fork of dom.js that removes mozilla-specific proxy support, and is better maintained in general. I'll probably try to add this to v8js at some point (or else expose the PHP.dom package to JS, haven't decided yet).

from v8js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.