Skip to content

Commit

Permalink
Work around Safari 7.1/8's busted Map by using array storage there.
Browse files Browse the repository at this point in the history
Also Addresses @arv's comments on Map arity.
  • Loading branch information
slightlyoff committed Apr 27, 2015
1 parent a7b2e53 commit 0df3d6c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions bin/c.js

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions src/HashSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,17 @@

// FIXME(slightlyoff): now that Set is in v8 and has iteration, migratpue

if (typeof Map != "undefined" &&
typeof Map.prototype.forEach != "undefined") {

if (c._functionalMap) {

c.HashSet = c.inherit({
_t: "c.HashSet",

initialize: function(hs) {
this.hashCode = c._inc();
this._store = new Map();
if (hs instanceof c.HashSet) {
if (Map.length) {
this._store = new Map(hs._store);
} else { // Hacking around Safari 8's limitations
var that = this._store;
hs._store.forEach(function(item) {
that.add(item);
});
}
this._store = new Map(hs._store);
} else {
this._store = new Map();
}
},

Expand Down
15 changes: 4 additions & 11 deletions src/HashTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,16 @@
(function(c) {
"use strict";

if (typeof Map != "undefined" &&
typeof Map.prototype.forEach != "undefined") {
if (c._functionalMap) {

c.HashTable = c.inherit({

initialize: function(ht) {
this.hashCode = c._inc();
this._store = new Map();
if (ht instanceof c.HashTable) {
if (Map.length) {
this._store = new Map(ht._store);
} else { // Hacking around Safari 8's limitations
var that = this._store;
ht._store.forEach(function(v, k) {
that.set(k, v);
});
}
this._store = new Map(ht._store);
} else {
this._store = new Map();
}
},

Expand Down
18 changes: 18 additions & 0 deletions src/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,31 @@ var walkForMethod = function(ctor, name) {
}
};

var functionalMap = false;
try {
var m = new Map();
m.set("foo", "bar");
var vi = m.values();
var rec = vi.next();
m.forEach(function() {});
var m2 = new Map(m);
if (m2.get("foo") != m.get("foo")) {
throw "ctor fail";
}
functionalMap = true;
} catch(e) {
// Squelch
}

// Global
var c = scope.c = function() {
if(c._api) {
return c._api.apply(this, arguments);
}
};

c._functionalMap = functionalMap;

//
// Constants
//
Expand Down

0 comments on commit 0df3d6c

Please sign in to comment.