Skip to content

extensibleweb/webidl.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

An implementation of WebIDL in ECMAScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages