From 2f7877450d3a1d516f43f39a543f6d2d1fc70ea0 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Tue, 16 Dec 2008 16:20:19 -0500 Subject: [PATCH] Bug 469191 - jsstack.js: give better locations for errors, r=dmandelin --- js/src/jsstack.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/js/src/jsstack.js b/js/src/jsstack.js index e56b69424ecc..085ede9d042c 100644 --- a/js/src/jsstack.js +++ b/js/src/jsstack.js @@ -107,13 +107,28 @@ function RedGreenCheck(fndecl, trace) { // to check for later. isn.redInfo = undefined; walk_tree(isn, function(t, stack) { + function getLocation(skiptop) { + if (!skiptop) { + let loc = location_of(t); + if (loc !== undefined) + return loc; + } + + for (let i = stack.length - 1; i >= 0; --i) { + loc = location_of(stack[i]); + if (loc !== undefined) + return loc; + } + return location_of(DECL_SAVED_TREE(fndecl)); + } + switch (TREE_CODE(t)) { case FIELD_DECL: if (isRed(t)) { let varName = dehydra_convert(t).name; // location_of(t) is the location of the declaration. isn.redInfo = ["cannot access JS_REQUIRES_STACK variable " + varName, - location_of(stack[stack.length - 1])]; + getLocation(true)]; self.hasRed = true; } break; @@ -124,7 +139,7 @@ function RedGreenCheck(fndecl, trace) { if (isRed(callee)) { let calleeName = dehydra_convert(callee).name; isn.redInfo = ["cannot call JS_REQUIRES_STACK function " + calleeName, - location_of(t)]; + getLocation(false)]; self.hasRed = true; } else if (isTurnRed(callee)) { isn.turnRed = true;