Skip to content

Commit

Permalink
Avoid infinite loops in \mathchoice Get() calls. Resolves problems re…
Browse files Browse the repository at this point in the history
…ported in issue mathjax#373.
  • Loading branch information
dpvc committed Apr 30, 2013
1 parent 23edb8c commit 6b43f76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
12 changes: 8 additions & 4 deletions unpacked/extensions/TeX/mathchoice.js
Expand Up @@ -43,11 +43,15 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
});

MML.TeXmathchoice = MML.mbase.Subclass({
type: "TeXmathchoice",
type: "TeXmathchoice", notParent: true,
choice: function () {
var values = this.getValues("displaystyle","scriptlevel");
if (values.scriptlevel > 0) {return Math.min(3,values.scriptlevel + 1)}
return (values.displaystyle ? 0 : 1);
if (this.selection == null) {
this.selection = 0;
var values = this.getValues("displaystyle","scriptlevel");
if (values.scriptlevel > 0) {this.selection = Math.min(3,values.scriptlevel+1)}
else {this.selection = (values.displaystyle ? 0 : 1)}
}
return this.selection;
},
selected: function () {return this.data[this.choice()]},
setTeXclass: function (prev) {return this.selected().setTeXclass(prev)},
Expand Down
30 changes: 16 additions & 14 deletions unpacked/jax/element/mml/jax.js
Expand Up @@ -241,7 +241,7 @@ MathJax.ElementJax.mml.Augment({
Init: function () {
this.data = [];
if (this.inferRow && !(arguments.length === 1 && arguments[0].inferred))
{this.Append(MML.mrow().With({inferred: true}))}
{this.Append(MML.mrow().With({inferred: true, notParent: true}))}
this.Append.apply(this,arguments);
},
With: function (def) {
Expand All @@ -267,17 +267,18 @@ MathJax.ElementJax.mml.Augment({
},
Parent: function () {
var parent = this.parent;
while (parent && parent.inferred) {parent = parent.parent}
while (parent && parent.notParent) {parent = parent.parent}
return parent;
},
Get: function (name,nodefault) {
Get: function (name,nodefault,skipadjust) {
if (this[name] != null) {return this[name]}
if (this.attr && this.attr[name] != null) {return this.attr[name]}
// FIXME: should cache these values and get from cache
// (clear cache when appended to a new object?)
var parent = this.Parent();
if (parent && parent["adjustChild_"+name] != null)
{return (parent["adjustChild_"+name])(parent.childPosition(this))}
if (parent && parent["adjustChild_"+name] != null && !skipadjust) {
return (parent["adjustChild_"+name])(this.childPosition(),nodefault);
}
var obj = this.inherit; var root = obj;
while (obj) {
var value = obj[name]; if (value == null && obj.attr) {value = obj.attr[name]}
Expand All @@ -302,12 +303,13 @@ MathJax.ElementJax.mml.Augment({
{values[arguments[i]] = this.Get(arguments[i])}
return values;
},
adjustChild_scriptlevel: function (i) {return this.Get("scriptlevel")}, // always inherit from parent
adjustChild_displaystyle: function (i) {return this.Get("displaystyle")}, // always inherit from parent
adjustChild_texprimestyle: function (i) {return this.Get("texprimestyle")}, // always inherit from parent
childPosition: function (child) {
if (child.parent.inferred) {child = child.parent}
for (var i = 0, m = this.data.length; i < m; i++) {if (this.data[i] === child) {return i}}
adjustChild_scriptlevel: function (i,nodef) {return this.Get("scriptlevel",nodef,true)}, // always inherit from parent
adjustChild_displaystyle: function (i,nodef) {return this.Get("displaystyle",nodef,true)}, // always inherit from parent
adjustChild_texprimestyle: function (i,nodef) {return this.Get("texprimestyle",nodef,true)}, // always inherit from parent
childPosition: function () {
var child = this, parent = child.parent;
while (parent.notParent) {child = parent; parent = child.parent}
for (var i = 0, m = parent.data.length; i < m; i++) {if (parent.data[i] === child) {return i}}
return null;
},
setInherit: function (obj) {
Expand Down Expand Up @@ -680,7 +682,7 @@ MathJax.ElementJax.mml.Augment({
MML.mrow = MML.mbase.Subclass({
type: "mrow",
isSpacelike: MML.mbase.childrenSpacelike,
inferred: false,
inferred: false, notParent: false,
isEmbellished: function () {
var isEmbellished = false;
for (var i = 0, m = this.data.length; i < m; i++) {
Expand Down Expand Up @@ -1161,7 +1163,7 @@ MathJax.ElementJax.mml.Augment({
});

MML.semantics = MML.mbase.Subclass({
type: "semantics",
type: "semantics", notParent: true,
isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO,
Expand Down Expand Up @@ -1302,7 +1304,7 @@ MathJax.ElementJax.mml.Augment({

MML.TeXAtom = MML.mbase.Subclass({
type: "texatom",
inferRow: true,
inferRow: true, notParent: true,
texClass: MML.TEXCLASS.ORD,
Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO,
Expand Down

0 comments on commit 6b43f76

Please sign in to comment.