Skip to content

Commit

Permalink
feat(collections): add weak map and set
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Mar 2, 2016
1 parent e513b75 commit 59d58dc
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/collections.js
Expand Up @@ -2,12 +2,26 @@ import {PLATFORM} from 'aurelia-pal';

(function (global) {
//shared pointer
let i;
var i;
//shortcuts
let defineProperty = Object.defineProperty;
let is = function(a,b) { return (a === b) || (a !== a && b !== b) };
var defineProperty = Object.defineProperty, is = function(a,b) { return (a === b) || (a !== a && b !== b) };

//Polyfill global objects
if (typeof WeakMap == 'undefined') {
global.WeakMap = createCollection({
// WeakMap#delete(key:void*):boolean
'delete': sharedDelete,
// WeakMap#clear():
clear: sharedClear,
// WeakMap#get(key:void*):void*
get: sharedGet,
// WeakMap#has(key:void*):boolean
has: mapHas,
// WeakMap#set(key:void*, value:void*):void
set: sharedSet
}, true);
}

if (typeof Map == 'undefined' || typeof ((new Map).values) !== 'function' || !(new Map).values().next) {
global.Map = createCollection({
// WeakMap#delete(key:void*):boolean
Expand Down Expand Up @@ -53,6 +67,19 @@ import {PLATFORM} from 'aurelia-pal';
});
}

if (typeof WeakSet == 'undefined') {
global.WeakSet = createCollection({
// WeakSet#delete(key:void*):boolean
'delete': sharedDelete,
// WeakSet#add(value:void*):boolean
add: sharedAdd,
// WeakSet#clear():
clear: sharedClear,
// WeakSet#has(value:void*):boolean
has: setHas
}, true);
}

/**
* ES6 collection constructor
* @return {Function} a collection class
Expand Down

0 comments on commit 59d58dc

Please sign in to comment.