Skip to content

Commit 8345587

Browse files
committed
Fix and standardize handling of boolean parameters during Construction.
1 parent 7fea06d commit 8345587

1 file changed

Lines changed: 16 additions & 32 deletions

File tree

stackframe.js

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,28 @@
1717
}
1818

1919
function _capitalize(str) {
20-
if (str.length > 0) {
21-
return str[0].toUpperCase() + str.substring(1);
22-
} else {
23-
return str;
24-
}
20+
return str[0].toUpperCase() + str.substring(1);
21+
}
22+
23+
function _getter(p) {
24+
return function () {
25+
return this[p];
26+
};
2527
}
2628

27-
var booleanProps = ['constructor', 'eval', 'native', 'toplevel'];
29+
var booleanProps = ['isConstructor', 'isEval', 'isNative', 'isToplevel'];
2830
var numericProps = ['columnNumber', 'lineNumber'];
2931
var stringProps = ['fileName', 'functionName', 'source'];
3032
var arrayProps = ['args'];
3133

3234
function StackFrame(obj) {
3335
if (obj instanceof Object) {
34-
var props = numericProps.concat(stringProps.concat(arrayProps));
36+
var props = booleanProps.concat(numericProps.concat(stringProps.concat(arrayProps)));
3537
for (var i = 0; i < props.length; i++) {
3638
if (obj.hasOwnProperty(props[i])) {
3739
this['set' + _capitalize(props[i])](obj[props[i]]);
3840
}
3941
}
40-
41-
for (var j = 0; j < booleanProps.length; j++) {
42-
if (obj.hasOwnProperty(booleanProps[j])) {
43-
this['setIs' + _capitalize(booleanProps[j])](obj[booleanProps[j]]);
44-
}
45-
}
4642
}
4743
}
4844

@@ -81,40 +77,28 @@
8177
};
8278

8379
for (var i = 0; i < booleanProps.length; i++) {
84-
StackFrame.prototype['getIs' + _capitalize(booleanProps[i])] = (function (p) {
85-
return function () {
86-
return this['is' + p];
87-
};
88-
})(_capitalize(booleanProps[i]));
89-
StackFrame.prototype['setIs' + _capitalize(booleanProps[i])] = (function (p) {
80+
StackFrame.prototype['get' + _capitalize(booleanProps[i])] = _getter(booleanProps[i]);
81+
StackFrame.prototype['set' + _capitalize(booleanProps[i])] = (function (p) {
9082
return function (v) {
91-
this['is' + p] = !!v;
83+
this[p] = Boolean(v);
9284
};
93-
})(_capitalize(booleanProps[i]));
85+
})(booleanProps[i]);
9486
}
9587

9688
for (var j = 0; j < numericProps.length; j++) {
97-
StackFrame.prototype['get' + _capitalize(numericProps[j])] = (function (p) {
98-
return function () {
99-
return this[p];
100-
};
101-
})(numericProps[j]);
89+
StackFrame.prototype['get' + _capitalize(numericProps[j])] = _getter(numericProps[j]);
10290
StackFrame.prototype['set' + _capitalize(numericProps[j])] = (function (p) {
10391
return function (v) {
10492
if (!_isNumber(v)) {
10593
throw new TypeError(p + ' must be a Number');
10694
}
10795
this[p] = Number(v);
10896
};
109-
})(numericProps[j], j);
97+
})(numericProps[j]);
11098
}
11199

112100
for (var k = 0; k < stringProps.length; k++) {
113-
StackFrame.prototype['get' + _capitalize(stringProps[k])] = (function (p) {
114-
return function () {
115-
return this[p];
116-
};
117-
})(stringProps[k]);
101+
StackFrame.prototype['get' + _capitalize(stringProps[k])] = _getter(stringProps[k]);
118102
StackFrame.prototype['set' + _capitalize(stringProps[k])] = (function (p) {
119103
return function (v) {
120104
this[p] = String(v);

0 commit comments

Comments
 (0)