Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit e13b408

Browse files
authored
Merge pull request #81 from rightfold/master
Fix hasOwnProperty bug again and forever
2 parents e08029b + 3379032 commit e13b408

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/Data/StrMap.js

+8-18
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33

44
// module Data.StrMap
55

6-
exports._copy = function (m) {
7-
var r = {};
8-
for (var k in m) {
9-
if (m.hasOwnProperty(k)) {
10-
r[k] = m[k];
11-
}
12-
}
13-
return r;
14-
};
15-
166
exports._copyEff = function (m) {
177
return function () {
188
var r = {};
199
for (var k in m) {
20-
if (m.hasOwnProperty(k)) {
10+
if (hasOwnProperty.call(m, k)) {
2111
r[k] = m[k];
2212
}
2313
}
@@ -35,7 +25,7 @@ exports.runST = function (f) {
3525
exports._fmapStrMap = function (m0, f) {
3626
var m = {};
3727
for (var k in m0) {
38-
if (m0.hasOwnProperty(k)) {
28+
if (hasOwnProperty.call(m0, k)) {
3929
m[k] = f(m0[k]);
4030
}
4131
}
@@ -46,7 +36,7 @@ exports._fmapStrMap = function (m0, f) {
4636
exports._mapWithKey = function (m0, f) {
4737
var m = {};
4838
for (var k in m0) {
49-
if (m0.hasOwnProperty(k)) {
39+
if (hasOwnProperty.call(m0, k)) {
5040
m[k] = f(k)(m0[k]);
5141
}
5242
}
@@ -65,7 +55,7 @@ exports._foldM = function (bind) {
6555
};
6656
}
6757
for (var k in m) {
68-
if (m.hasOwnProperty(k)) {
58+
if (hasOwnProperty.call(m, k)) {
6959
acc = bind(acc)(g(k));
7060
}
7161
}
@@ -78,7 +68,7 @@ exports._foldM = function (bind) {
7868
// jshint maxparams: 4
7969
exports._foldSCStrMap = function (m, z, f, fromMaybe) {
8070
for (var k in m) {
81-
if (m.hasOwnProperty(k)) {
71+
if (hasOwnProperty.call(m, k)) {
8272
var maybeR = f(z)(k)(m[k]);
8373
var r = fromMaybe(null)(maybeR);
8474
if (r === null) return z;
@@ -92,7 +82,7 @@ exports._foldSCStrMap = function (m, z, f, fromMaybe) {
9282
exports.all = function (f) {
9383
return function (m) {
9484
for (var k in m) {
95-
if (m.hasOwnProperty(k) && !f(k)(m[k])) return false;
85+
if (hasOwnProperty.call(m, k) && !f(k)(m[k])) return false;
9686
}
9787
return true;
9888
};
@@ -101,7 +91,7 @@ exports.all = function (f) {
10191
exports.size = function (m) {
10292
var s = 0;
10393
for (var k in m) {
104-
if (m.hasOwnProperty(k)) {
94+
if (hasOwnProperty.call(m, k)) {
10595
++s;
10696
}
10797
}
@@ -130,7 +120,7 @@ function _collect(f) {
130120
return function (m) {
131121
var r = [];
132122
for (var k in m) {
133-
if (m.hasOwnProperty(k)) {
123+
if (hasOwnProperty.call(m, k)) {
134124
r.push(f(k)(m[k]));
135125
}
136126
}

src/Data/StrMap.purs

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ import Data.Unfoldable (class Unfoldable)
5656
-- | `StrMap a` represents a map from `String`s to values of type `a`.
5757
foreign import data StrMap :: * -> *
5858

59-
foreign import _copy :: forall a. StrMap a -> StrMap a
60-
6159
foreign import _copyEff :: forall a b h r. a -> Eff (st :: ST.ST h | r) b
6260

6361
-- | Convert an immutable map into a mutable map

test/Test/Data/StrMap.purs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Partial.Unsafe (unsafePartial)
1919

2020
import Test.QuickCheck ((<?>), quickCheck, quickCheck', (===))
2121
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)
22+
import Test.QuickCheck.Gen as Gen
2223

2324
newtype TestStrMap v = TestStrMap (M.StrMap v)
2425

@@ -34,7 +35,8 @@ instance showInstruction :: (Show k, Show v) => Show (Instruction k v) where
3435
instance arbInstruction :: (Arbitrary v) => Arbitrary (Instruction String v) where
3536
arbitrary = do
3637
b <- arbitrary
37-
k <- arbitrary
38+
k <- Gen.frequency (Tuple 10.0 (pure "hasOwnProperty"))
39+
(Tuple 50.0 arbitrary `Cons` Nil)
3840
case b of
3941
true -> do
4042
v <- arbitrary

0 commit comments

Comments
 (0)