GithubHelp home page GithubHelp logo

tevren / env-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smparkes/env-js

1.0 1.0 0.0 7.91 MB

A pure-JavaScript browser environment with early rubygem support.

Home Page: http://github.com/smparkes/env-js

Java 0.73% Ruby 0.75% Shell 0.13% JavaScript 98.39%

env-js's Introduction

THIS FORK OF ENV.JS IS MOTHBALLED

The Johnson fork of env.js is pretty much mothballed (which is already pretty much true of Johnson, given the rise of v8 and the difficulty moving Johnson to 1.9.*). The current best practices seem to be based on a headless webkit.

env.js

Description

A browser environment for javascript interpreters.

This is a fork of the env.js project (github.com/thatcher/env-js/). See that link for env.js details. This fork is based on the Johnson Ruby gem (github.com/jbarnette/johnson).

Installation

For now, you can install the envjs gem by installing Johnson:

gem install johnson --prerelease

and then installing the envjs gem with

gem install envjs

Using envjs interactively

The envjs gem provides the envjsrb command, which functions as an extended version of the Johnson javascript shell. For example:

 mbp:env-js smparkes$ envjsrb
 js> this
 => [object Window 0]
 js> window.location
 => about:blank
 js> document.innerHTML
 => "<html><head><title></title></head><body></body></html>"
js>

Embedding envjs

It’s also possible to embed the envjs interpreter similar to the way it’s done in Johnson, e.g.,

require 'rubygems' # if necessary
require 'johnson/tracemonkey'
require 'envjs/runtime'

envjs = Johnson::Runtime.new
envjs.extend Envjs::Runtime
window = envjs.evaluate("window")
puts window.location.to_s # == "about:blank"
puts window.document.innerHTML # == "<html><head><title></title></head><body></body></html>"
envjs.wait

You need the Runtime#wait at the end to give env.js’s event loop a chance to execute queued events and timers. You may need to do this at other times as well, depending on the asynchronous nature of your application.

License

See github.com/smparkes/env-js/blob/envjsrb/licenses/MIT-LICENSE.txt and github.com/smparkes/env-js/blob/envjsrb/licenses/GPL-LICENSE.txt.

env-js's People

Contributors

chrisroos avatar fiann avatar gleneivey avatar h-lame avatar jeresig avatar jganetsk avatar smparkes avatar thatcher avatar timcowlishaw avatar youngnh avatar

Stargazers

 avatar

Watchers

 avatar

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.