GithubHelp home page GithubHelp logo

alexxnica / webidl.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from extensibleweb/webidl.js

0.0 1.0 0.0 46.17 MB

An implementation of WebIDL in ECMAScript

ApacheConf 0.19% JavaScript 96.82% HTML 0.63% CSS 2.36%

webidl.js's Introduction

webidl.js

Build Status NPM version Dependency Status npm

An implementation of WebIDL in ECMAScript.

Installation

# If you depend on this in production, install with --save flag
npm install --save webidl

# Otherwise, install with --save-dev
npm install --save-dev webidl

Goals and Scope

The initial goal of this project is to implement a "prollyfill" code generator based on the WebIDL specification in ECMAScript (i.e., implement the WebIDL ECMAScript bindings).

For the first version, webidl.js will take as input well-formed Web IDL and generate JavaScript code that:

  1. Implements the given WebIDL in conformance to WebIDL's WebIDL ECMAScript bindings.
  2. can be eval'ed immediately to implement a noop object.
  3. can be used indepedently of webidl.js.

The generated code will not depend on any external libraries.

#Proposed Architecture (in WebIDL) WebIDLCompiler will be based on Robin Berjon's WebIDL Parser,

interface WebIDLCompiler : WebIDL{
  static DOMString compile(DOMString dataFragment);
  static DOMString compile(object dataTree);
}

interface WebIDL{
    static object parse(); 
}

Where WebIDL is and instance of https://github.com/darobin/webidl2.js

##Examples of what we want to do (The following examples are hypothetical, as we don't actually have any running code yet! :) )

Given some WebIDL, like:

interface Vehicle {
  attribute DOMString make;
  attribute DOMString model;
  void move();
}

[Constructor, Constructor(DOMString make, optional DOMString model)]
interface Car : Vehicle {
  const octet maxspeed = 200;
  void drive([Clamp] octet speed);
};

webidl.js will implement the following in the browser:

var webIDL = new WebIDLCompiler();

//convert to javascript
var script = webIDL.compile(carIDLString);
eval(script); // noop methods by default

// interfaces are added to the global scope
console.log(window.Car);
console.log(window.Vehicle);
console.log(window.Car.prototype.drive);
console.log(Car.maxspeed === 200); 

// instances are valid and inheritance works properly
var car = new Car(); 
console.log(car instanceof window.Car === true); 
console.log(car instanceof window.Vehicle === true); 
console.log("make" in car === true); 
console.log("move" in car === true); 

// methods can be called on instances
car.drive();
window.Car.prototype.drive.call(car)

// methods can't be called on other objects (throws a type error)
try{ 
    window.Car.prototype.drive.call({}); 
}catch(e){
  console.log(e);
} 

// type checking is built-in (throws a type error)
try{ 
  car.drive({});
}catch(e){
  console.log(e);
} 

// type conversion is also buit-in
car.drive("100"); 

Contributing

We welcome code contributions in the form of pull requests. All pull requests are reviewed prior to being integrated.

To retain a high level of quality, we require that all contributed code include:

  • appropriate unit tests,
  • documentation,
  • and the code has been linted.

Linting, beautificaiton, and generation of documentation is handled by grunt..

Coding conventions

We attempt to adhere to the Google JavaScript Style Guide.

We are also moving to us JSDoc to document out code.

Before submitting code, please be sure to run grunt.

License

Copyright © 2013 Extensible Web Community Group

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

webidl.js's People

Contributors

marcoscaceres-remote avatar bkardell avatar amilajack avatar clintjhill avatar marcoscaceres avatar fremycompany avatar wibblymat 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.