Avoid infinite loops in \mathchoice Get() calls. Resolves problems reported in issue #373.

This commit is contained in:
Davide P. Cervone 2013-04-30 10:34:42 -04:00
parent 23edb8c49b
commit 6b43f76e6b
2 changed files with 24 additions and 18 deletions

View File

@ -43,11 +43,15 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
}); });
MML.TeXmathchoice = MML.mbase.Subclass({ MML.TeXmathchoice = MML.mbase.Subclass({
type: "TeXmathchoice", type: "TeXmathchoice", notParent: true,
choice: function () { choice: function () {
var values = this.getValues("displaystyle","scriptlevel"); if (this.selection == null) {
if (values.scriptlevel > 0) {return Math.min(3,values.scriptlevel + 1)} this.selection = 0;
return (values.displaystyle ? 0 : 1); 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()]}, selected: function () {return this.data[this.choice()]},
setTeXclass: function (prev) {return this.selected().setTeXclass(prev)}, setTeXclass: function (prev) {return this.selected().setTeXclass(prev)},

View File

@ -241,7 +241,7 @@ MathJax.ElementJax.mml.Augment({
Init: function () { Init: function () {
this.data = []; this.data = [];
if (this.inferRow && !(arguments.length === 1 && arguments[0].inferred)) 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); this.Append.apply(this,arguments);
}, },
With: function (def) { With: function (def) {
@ -267,17 +267,18 @@ MathJax.ElementJax.mml.Augment({
}, },
Parent: function () { Parent: function () {
var parent = this.parent; var parent = this.parent;
while (parent && parent.inferred) {parent = parent.parent} while (parent && parent.notParent) {parent = parent.parent}
return parent; return parent;
}, },
Get: function (name,nodefault) { Get: function (name,nodefault,skipadjust) {
if (this[name] != null) {return this[name]} if (this[name] != null) {return this[name]}
if (this.attr && this.attr[name] != null) {return this.attr[name]} if (this.attr && this.attr[name] != null) {return this.attr[name]}
// FIXME: should cache these values and get from cache // FIXME: should cache these values and get from cache
// (clear cache when appended to a new object?) // (clear cache when appended to a new object?)
var parent = this.Parent(); var parent = this.Parent();
if (parent && parent["adjustChild_"+name] != null) if (parent && parent["adjustChild_"+name] != null && !skipadjust) {
{return (parent["adjustChild_"+name])(parent.childPosition(this))} return (parent["adjustChild_"+name])(this.childPosition(),nodefault);
}
var obj = this.inherit; var root = obj; var obj = this.inherit; var root = obj;
while (obj) { while (obj) {
var value = obj[name]; if (value == null && obj.attr) {value = obj.attr[name]} var value = obj[name]; if (value == null && obj.attr) {value = obj.attr[name]}
@ -302,12 +303,13 @@ MathJax.ElementJax.mml.Augment({
{values[arguments[i]] = this.Get(arguments[i])} {values[arguments[i]] = this.Get(arguments[i])}
return values; return values;
}, },
adjustChild_scriptlevel: function (i) {return this.Get("scriptlevel")}, // always inherit from parent adjustChild_scriptlevel: function (i,nodef) {return this.Get("scriptlevel",nodef,true)}, // always inherit from parent
adjustChild_displaystyle: function (i) {return this.Get("displaystyle")}, // always inherit from parent adjustChild_displaystyle: function (i,nodef) {return this.Get("displaystyle",nodef,true)}, // always inherit from parent
adjustChild_texprimestyle: function (i) {return this.Get("texprimestyle")}, // always inherit from parent adjustChild_texprimestyle: function (i,nodef) {return this.Get("texprimestyle",nodef,true)}, // always inherit from parent
childPosition: function (child) { childPosition: function () {
if (child.parent.inferred) {child = child.parent} var child = this, parent = child.parent;
for (var i = 0, m = this.data.length; i < m; i++) {if (this.data[i] === child) {return i}} 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; return null;
}, },
setInherit: function (obj) { setInherit: function (obj) {
@ -680,7 +682,7 @@ MathJax.ElementJax.mml.Augment({
MML.mrow = MML.mbase.Subclass({ MML.mrow = MML.mbase.Subclass({
type: "mrow", type: "mrow",
isSpacelike: MML.mbase.childrenSpacelike, isSpacelike: MML.mbase.childrenSpacelike,
inferred: false, inferred: false, notParent: false,
isEmbellished: function () { isEmbellished: function () {
var isEmbellished = false; var isEmbellished = false;
for (var i = 0, m = this.data.length; i < m; i++) { for (var i = 0, m = this.data.length; i < m; i++) {
@ -1161,7 +1163,7 @@ MathJax.ElementJax.mml.Augment({
}); });
MML.semantics = MML.mbase.Subclass({ MML.semantics = MML.mbase.Subclass({
type: "semantics", type: "semantics", notParent: true,
isEmbellished: MML.mbase.childEmbellished, isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore, Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO, CoreMO: MML.mbase.childCoreMO,
@ -1302,7 +1304,7 @@ MathJax.ElementJax.mml.Augment({
MML.TeXAtom = MML.mbase.Subclass({ MML.TeXAtom = MML.mbase.Subclass({
type: "texatom", type: "texatom",
inferRow: true, inferRow: true, notParent: true,
texClass: MML.TEXCLASS.ORD, texClass: MML.TEXCLASS.ORD,
Core: MML.mbase.childCore, Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO, CoreMO: MML.mbase.childCoreMO,