Skip to content

Commit f8993ff

Browse files
authored
Merge pull request #2027 from dpvc/issue1996
Use hasOwnProperty() to check for object properties. #1996
2 parents 9ad6a9b + b2a9975 commit f8993ff

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

unpacked/extensions/TeX/begingroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
5050
//
5151
// Find a macro or environment by name
5252
//
53-
Find: function (name,type) {if (this[type][name]) {return this[type][name]}},
53+
Find: function (name,type) {if (this[type].hasOwnProperty(name)) {return this[type][name]}},
5454
//
5555
// Define or remove a macro or environment
5656
//

unpacked/extensions/TeX/color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ MathJax.Extension["TeX/color"] = {
183183
* Get a named value
184184
*/
185185
get_named: function (name) {
186-
if (this.colors[name]) {return this.colors[name]}
186+
if (this.colors.hasOwnProperty(name)) {return this.colors[name]}
187187
return name;
188188
},
189189

unpacked/extensions/TeX/newcommand.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
120120
name = this.GetCSname(name);
121121
macro = this.csFindMacro(name);
122122
if (!macro) {
123-
if (TEXDEF.mathchar0mi[name]) {macro = ["csMathchar0mi",TEXDEF.mathchar0mi[name]]} else
124-
if (TEXDEF.mathchar0mo[name]) {macro = ["csMathchar0mo",TEXDEF.mathchar0mo[name]]} else
125-
if (TEXDEF.mathchar7[name]) {macro = ["csMathchar7",TEXDEF.mathchar7[name]]} else
126-
if (TEXDEF.delimiter["\\"+name] != null) {macro = ["csDelimiter",TEXDEF.delimiter["\\"+name]]} else
123+
if (TEXDEF.mathchar0mi.hasOwnProperty(name)) {macro = ["csMathchar0mi",TEXDEF.mathchar0mi[name]]} else
124+
if (TEXDEF.mathchar0mo.hasOwnProperty(name)) {macro = ["csMathchar0mo",TEXDEF.mathchar0mo[name]]} else
125+
if (TEXDEF.mathchar7.hasOwnProperty(name)) {macro = ["csMathchar7",TEXDEF.mathchar7[name]]} else
126+
if (TEXDEF.delimiter.hasOwnProperty("\\"+name)) {macro = ["csDelimiter",TEXDEF.delimiter["\\"+name]]} else
127127
return;
128128
}
129129
} else {macro = ["Macro",c]; this.i++}

unpacked/jax/input/TeX/jax.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@
10821082
while (this.i < this.string.length) {
10831083
c = this.string.charAt(this.i++); n = c.charCodeAt(0);
10841084
if (n >= 0xD800 && n < 0xDC00) {c += this.string.charAt(this.i++)}
1085-
if (TEXDEF.special[c]) {this[TEXDEF.special[c]](c)}
1085+
if (TEXDEF.special.hasOwnProperty(c)) {this[TEXDEF.special[c]](c)}
10861086
else if (TEXDEF.letter.test(c)) {this.Variable(c)}
10871087
else if (TEXDEF.digit.test(c)) {this.Number(c)}
10881088
else {this.Other(c)}
@@ -1109,17 +1109,19 @@
11091109
if (!isArray(macro)) {macro = [macro]}
11101110
var fn = macro[0]; if (!(fn instanceof Function)) {fn = this[fn]}
11111111
fn.apply(this,[c+name].concat(macro.slice(1)));
1112-
} else if (TEXDEF.mathchar0mi[name]) {this.csMathchar0mi(name,TEXDEF.mathchar0mi[name])}
1113-
else if (TEXDEF.mathchar0mo[name]) {this.csMathchar0mo(name,TEXDEF.mathchar0mo[name])}
1114-
else if (TEXDEF.mathchar7[name]) {this.csMathchar7(name,TEXDEF.mathchar7[name])}
1115-
else if (TEXDEF.delimiter["\\"+name] != null) {this.csDelimiter(name,TEXDEF.delimiter["\\"+name])}
1116-
else {this.csUndefined(c+name)}
1112+
} else if (TEXDEF.mathchar0mi.hasOwnProperty(name)) {this.csMathchar0mi(name,TEXDEF.mathchar0mi[name])}
1113+
else if (TEXDEF.mathchar0mo.hasOwnProperty(name)) {this.csMathchar0mo(name,TEXDEF.mathchar0mo[name])}
1114+
else if (TEXDEF.mathchar7.hasOwnProperty(name)) {this.csMathchar7(name,TEXDEF.mathchar7[name])}
1115+
else if (TEXDEF.delimiter.hasOwnProperty("\\"+name)) {this.csDelimiter(name,TEXDEF.delimiter["\\"+name])}
1116+
else {this.csUndefined(c+name)}
11171117
},
11181118
//
11191119
// Look up a macro in the macros list
11201120
// (overridden in begingroup extension)
11211121
//
1122-
csFindMacro: function (name) {return TEXDEF.macros[name]},
1122+
csFindMacro: function (name) {
1123+
return (TEXDEF.macros.hasOwnProperty(name) ? TEXDEF.macros[name] : null);
1124+
},
11231125
//
11241126
// Handle normal mathchar (as an mi)
11251127
//
@@ -1295,7 +1297,7 @@
12951297
Other: function (c) {
12961298
var def, mo;
12971299
if (this.stack.env.font) {def = {mathvariant: this.stack.env.font}}
1298-
if (TEXDEF.remap[c]) {
1300+
if (TEXDEF.remap.hasOwnProperty(c)) {
12991301
c = TEXDEF.remap[c];
13001302
if (isArray(c)) {def = c[1]; c = c[0]}
13011303
mo = MML.mo(MML.entity('#x'+c)).With(def);
@@ -1874,7 +1876,9 @@
18741876
}
18751877
this.Push(mml);
18761878
},
1877-
envFindName: function (name) {return TEXDEF.environment[name]},
1879+
envFindName: function (name) {
1880+
return (TEXDEF.environment.hasOwnProperty(name) ? TEXDEF.environment[name] : null);
1881+
},
18781882

18791883
Equation: function (begin,row) {return row},
18801884

@@ -1931,7 +1935,7 @@
19311935
* Convert delimiter to character
19321936
*/
19331937
convertDelimiter: function (c) {
1934-
if (c) {c = TEXDEF.delimiter[c]}
1938+
if (c) {c = (TEXDEF.delimiter.hasOwnProperty(c) ? TEXDEF.delimiter[c] : null)}
19351939
if (c == null) {return null}
19361940
if (isArray(c)) {c = c[0]}
19371941
if (c.length === 4) {c = String.fromCharCode(parseInt(c,16))}
@@ -2043,7 +2047,7 @@
20432047
this.i--;
20442048
c = this.GetArgument(name).replace(/^\s+/,'').replace(/\s+$/,'');
20452049
}
2046-
if (TEXDEF.delimiter[c] != null) {return this.convertDelimiter(c)}
2050+
if (TEXDEF.delimiter.hasOwnProperty(c)) {return this.convertDelimiter(c)}
20472051
}
20482052
TEX.Error(["MissingOrUnrecognizedDelim",
20492053
"Missing or unrecognized delimiter for %1",name]);

0 commit comments

Comments
 (0)