Skip to content

Commit cc527b0

Browse files
authored
FIX: MultiLangString.prototype.set throws call stack exceeded error (#120)
closes #120
1 parent 4915e0c commit cc527b0

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/models/MultiLangString.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,6 @@
44

55
import isLanguageTag from '../utilities/validate/isLanguageTag.js';
66

7-
/**
8-
* Proxy traps for the MultiLangString class
9-
* @type {Object}
10-
*/
11-
const classTraps = {
12-
construct(Target, args) {
13-
14-
const map = Reflect.construct(Target, args);
15-
16-
Object.defineProperty(map, `set`, {
17-
configurable: true,
18-
enumerable: false,
19-
get() {
20-
return function(key, val) { // eslint-disable-line func-names
21-
validateLanguageTag(key);
22-
validateString(val);
23-
return map.set.apply(this, [key, val]); // eslint-disable-line no-invalid-this
24-
};
25-
},
26-
});
27-
28-
return map;
29-
30-
},
31-
};
32-
337
/**
348
* Validates a language tag. Throws a type error if the input is not a valid IETF language tag.
359
* @param {Any} input The input to validate
@@ -104,10 +78,16 @@ class MultiLangString extends Map {
10478

10579
}
10680

81+
set(key, val) {
82+
validateLanguageTag(key);
83+
validateString(val);
84+
return super.set(key, val);
85+
}
86+
10787
toJSON() {
10888
return Object.fromEntries(this);
10989
}
11090

11191
}
11292

113-
export default new Proxy(MultiLangString, classTraps);
93+
export default MultiLangString;

src/models/MultiLangString.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ describe(modelName, () => {
9292

9393
});
9494

95+
it(`MultiLangString.prototype.set()`, () => {
96+
const mls = new MultiLangString;
97+
const setData = () => mls.set(`hello`, `world`);
98+
expect(setData).not.toThrow();
99+
});
100+
95101
it(`MultiLangString.prototype.toJSON()`, () => {
96102

97103
const mls = new MultiLangString(sampleData);

0 commit comments

Comments
 (0)