Permalink
Browse files

Project init

  • Loading branch information...
0 parents commit 87cacd99528ed70209514a09247daf703de1a780 @eriwen committed Nov 12, 2012
@@ -0,0 +1,7 @@
+.idea
+node_modules
+.DS_STORE
+*.log
+target
+build
+
@@ -0,0 +1,6 @@
+/node_modules/
+/.idea/
+/npm-debug.log
+/target/
+/build/
+
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Eric Wendelin
+
+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.
@@ -0,0 +1,21 @@
+BROWSER_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
+
+browser:
+ open spec/SpecRunner.html
+
+phantom:
+ /usr/bin/env DISPLAY=:1 phantomjs spec/lib/run-jasmine.js spec/SpecRunner.html
+
+jstd:
+ /usr/bin/env DISPLAY=:1 java -jar spec/JsTestDriver-1.3.5.jar --config spec/jsTestDriver.conf --browser ${BROWSER_PATH} --port 4224 --tests 'all' --testOutput './target'
+
+build: components smap
+ @component build --dev
+
+components: component.json
+ @component install --dev
+
+clean:
+ rm -fr build components template.js
+
+.PHONY: clean
@@ -0,0 +1,37 @@
+# es6-map-shim - A polyfill for ES6 Maps
+
+
+```js
+var map = new Map();
+map.set('foo', 'bar');
+map.set(0, 42);
+
+// Remove all items
+map.clear();
+map.items();
+=> []
+```
+
+## Installation
+In browsers, include [es6-map-shim.js](https://github.com/eriwen/es6-map-shim/downloads) in your page:
+
+```html
+<script type="text/javascript" src="https://raw.github.com/eriwen/es6-map-shim/master/es6-map-shim.js"></script>
+```
+
+You can install this via:
+
+ * npm for [node.js](http://nodejs.org) v0.8+: `npm install es6-map-shim`
+ * [component(1)](https://github.com/component/component): `component install eriwen/es6-map-shim`
+ * [bower](http://twitter.github.com/bower/): `bower install es6-map-shim`
+
+### Environment Support
+If you also use the [es5-shim](https://github.com/kriskowal/es5-shim), you can use this in:
+
+ * IE9+
+ * Firefox 15+
+ * Google Chrome 21+
+ * Safari 4+
+ * Opera 12+
+ * Node.js 0.8+
+ * PhantomJS
@@ -0,0 +1,15 @@
+{
+ "name": "es6-map-shim",
+ "repo": "eriwen/es6-map-shim",
+ "description": "A forward polyfill for ES6 Maps",
+ "author": "Eric Wendelin",
+ "homepage": "http://eriwen.github.com/es6-map-shim/",
+ "version": "0.1.1",
+ "keywords": ["es6", "harmony", "map", "shim", "polyfill"],
+ "dependencies": {},
+ "development": {},
+ "license": "MIT",
+ "scripts": [
+ "es6-map-shim.js"
+ ]
+}
@@ -0,0 +1,134 @@
+//! Copyright 2012 Eric Wendelin - MIT License
+
+/**
+ * es6-map-shim.js is a DESTRUCTIVE shim that follows the latest Map specification as closely as possible.
+ * It is destructive in the sense that it overrides native implementations.
+ *
+ * This library assumes ES5 functionality: Object.create, Object.defineProperty, Array.indexOf, Function.bind
+ */
+function Map() {
+ var _items = [];
+ var _keys = [];
+ var _values = [];
+ var is = Object.is || function(a, b) {
+ return a === b ?
+ a !== 0 || 1 / a == 1 / b :
+ a != a && b != b;
+ };
+
+ // a more reliable indexOf
+ var betterIndexOf = function(value) {
+ if(value != value || value === 0) {
+ for(var i = this.length; i-- && !is(this[i], value););
+ } else {
+ i = [].indexOf.call(this, value);
+ }
+ return i;
+ };
+
+ // TODO: look at other shims for this
+ var MapIterator = function MapIterator(kind) {
+ var _m;
+ var _itemKind = kind;
+ var _index = 0;
+
+ return Object.create({}, {
+ next: {
+ value: function() {
+ // check if index is within bounds
+
+ }
+ },
+ iterator: {
+ value: this
+ },
+ toString: {
+ value: function() {
+ return '[Object Map Iterator]';
+ }
+ }
+ });
+ };
+
+ // TODO: allow construction with arrays
+
+ return Object.create({}, {
+ items:{
+ value:function() {
+ return [].slice.call(_items);
+ }
+ },
+ keys:{
+ value:function() {
+ return [].slice.call(_keys);
+ }
+ },
+ values:{
+ value:function() {
+ return [].slice.call(_values);
+ }
+ },
+ has:{
+ value:function(key) {
+ // TODO: check how spec reads about null values
+ var index = betterIndexOf.call(_keys, key);
+ return index > -1;
+ }
+ },
+ get:{
+ value:function(key) {
+ var index = betterIndexOf.call(_keys, key);
+ return index > -1 ? _values[index] : undefined;
+ }
+ },
+ set:{
+ value:function(key, value) {
+ // check if key exists and overwrite
+ var index = betterIndexOf.call(_keys, key);
+ if (index > -1) {
+ _items[index] = value;
+ _values[index] = value;
+ } else {
+ _items.push([key, value]);
+ _keys.push(key);
+ _values.push(value);
+ }
+ }
+ },
+ size:{
+ get:function() {
+ return _items.length;
+ }
+ },
+ clear:{
+ value:function() {
+ _keys.length = _values.length = _items.length = 0;
+ }
+ },
+ 'delete':{
+ value:function(key) {
+ var index = betterIndexOf.call(_keys, key);
+ if (index > -1) {
+ _keys.splice(index, 1);
+ _values.splice(index, 1);
+ _items.splice(index, 1);
+ return true;
+ }
+ return false;
+ }
+ },
+ forEach:{
+ value:function(callbackfn/*, thisArg*/) {
+ // TODO: implement me
+ }
+ },
+ iterator:{
+ value: new MapIterator(this, 'keys+values')
+ },
+ toString:{
+ value: function() {
+ return '[Object Map]';
+ }
+ }
+ });
+}
@@ -0,0 +1,26 @@
+{
+ "name": "es6-map-shim",
+ "description": "A polyfill ES6 Map that closely follows the latest spec",
+ "author": "Eric Wendelin <me@eriwen.com> (http://eriwen.com)",
+ "version": "0.1.0",
+ "keywords": ["es6", "harmony", "map", "shim", "polyfill"],
+ "homepage": "http://eriwen.github.com/es6-map-shim/",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/eriwen/es6-map-shim.git"
+ },
+ "bugs": {
+ "url": "https://github.com/eriwen/es6-map-shim/issues"
+ },
+ "licenses": [{
+ "type": "MIT",
+ "url": "https://github.com/eriwen/es6-map-shim/blob/master/LICENSE"
+ }],
+ "main": "./es6-map-shim.js",
+ "engines": {
+ "node": ">= 0.8.0"
+ },
+ "scripts": {
+ "test": "make jstd"
+ }
+}
Binary file not shown.
@@ -0,0 +1,46 @@
+<!doctype html>
+<html>
+<head>
+ <title>Jasmine Spec Runner</title>
+
+ <link rel="stylesheet" type="text/css" href="lib/jasmine.css">
+
+ <script type="text/javascript" src="lib/jasmine.js"></script>
+ <script type="text/javascript" src="lib/jasmine-html.js"></script>
+ <script type="text/javascript" src="lib/es5-shim.js"></script>
+
+ <script type="text/javascript" src="../es6-map-shim.js"></script>
+
+ <script type="text/javascript" src="es6-map-shim-test.js"></script>
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if(currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+ })();
+ </script>
+</head>
+<body>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 87cacd9

Please sign in to comment.