Package: node-hashish / 0.0.4+git34dfe43-4

drop-__proto__-calls.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Description: drop __proto__ calls
Author: Yadd <yadd@debian.org>
Forwarded: no
Last-Update: 2022-12-01

--- a/index.js
+++ b/index.js
@@ -15,8 +15,10 @@
     
     var self = {
         map : function (f) {
-            var acc = { __proto__ : hash.__proto__ };
+            var acc = new Object();
+            Object.setPrototypeOf(acc, Object.getPrototypeOf(hash));
             Object.keys(hash).forEach(function (key) {
+                if (key !== '__proto__')
                 acc[key] = f.call(self, hash[key], key);
             });
             return Hash(acc);
@@ -28,9 +30,10 @@
             return self;
         },
         filter : function (f) {
-            var acc = { __proto__ : hash.__proto__ };
+            var acc = new Object();
+            Object.setPrototypeOf(acc, Object.getPrototypeOf(hash));
             Object.keys(hash).forEach(function (key) {
-                if (f.call(self, hash[key], key)) {
+                if (key !== '__proto__' && f.call(self, hash[key], key)) {
                     acc[key] = hash[key];
                 }
             });
@@ -170,8 +173,10 @@
 
 // shallow copy
 Hash.copy = function (ref) {
-    var hash = { __proto__ : ref.__proto__ };
+    var hash = new Object();
+    Object.setPrototypeOf(hash, Object.getPrototypeOf(ref));
     Object.keys(ref).forEach(function (key) {
+        if (key !== '__proto__')
         hash[key] = ref[key];
     });
     return hash;
--- a/test/property.js
+++ b/test/property.js
@@ -20,10 +20,13 @@
     var Hash_ = context.module.exports;
     
     var times = 0;
-    Hash_.__proto__.__proto__.__defineGetter__ = function () {
+    let tmp = { __defineGetter__: function() {
         times ++;
         return Object.__defineGetter__.apply(this, arguments);
-    };
+    }};
+    let tmp2 = new Object();
+    Object.setPrototypeOf(tmp2, tmp);
+    Object.setPrototypeOf(Hash_, tmp2);
     
     assert.equal(vm.runInNewContext('Object.defineProperty', context), null);
     
@@ -54,11 +57,14 @@
     vm.runInNewContext('(function () {' + src + '})()', context);
     var Hash_ = context.module.exports;
     
-    Hash_.__proto__.__proto__.__defineGetter__ = function () {
+    let tmp = { __defineGetter__: function() {
         assert.fail('getter called when a perfectly good'
             + ' defineProperty was available'
         );
-    };
+    }};
+    let tmp2 = new Object();
+    Object.setPrototypeOf(tmp2, tmp);
+    Object.setPrototypeOf(Hash_, tmp2);
     
     assert.deepEqual(
         Hash_({ a : 1, b : 2, c : 3 }).values,