Bug 918828, part 3 - Update decompiler for JSOP_SYMBOL. This improves error messages when @@iterator is called implicitly. r=Waldo.

--HG--
extra : rebase_source : b9edaa7be12bdfde40b38d3f413f10624c4f0dcf
This commit is contained in:
Jason Orendorff 2014-07-01 21:18:12 -05:00
parent a9a9cfb535
commit 63daa2aa42
6 changed files with 41 additions and 4 deletions

View File

@ -109,8 +109,8 @@ check("o[- (o)]");
// A few one off tests
check_one("6", (function () { 6() }), " is not a function");
check_one("Array.prototype.reverse.call(...)", (function () { Array.prototype.reverse.call('123'); }), " is read-only");
check_one("(intermediate value)[(intermediate value)](...).next(...).value", function () { var [{ x }] = [null, {}]; }, " is null");
check_one("(intermediate value)[(intermediate value)](...).next(...).value", function () { ieval("let (x) { var [a, b, [c0, c1]] = [x, x, x]; }") }, " is undefined");
check_one("(intermediate value)[Symbol.iterator](...).next(...).value", function () { var [{ x }] = [null, {}]; }, " is null");
check_one("(intermediate value)[Symbol.iterator](...).next(...).value", function () { ieval("let (x) { var [a, b, [c0, c1]] = [x, x, x]; }") }, " is undefined");
// Check fallback behavior
assertThrowsInstanceOf(function () { for (let x of undefined) {} }, TypeError);

View File

@ -157,7 +157,7 @@ JSRuntime::initializeAtoms(JSContext *cx)
if (!wellKnownSymbols)
return false;
ImmutablePropertyNamePtr *descriptions = &commonNames->Symbol_iterator;
ImmutablePropertyNamePtr *descriptions = commonNames->wellKnownSymbolDescriptions();
ImmutableSymbolPtr *symbols = reinterpret_cast<ImmutableSymbolPtr *>(wellKnownSymbols);
for (size_t i = 0; i < JS::WellKnownSymbolLimit; i++) {
JS::Symbol *symbol = JS::Symbol::new_(cx, JS::SymbolCode(i), descriptions[i]);

View File

@ -1540,6 +1540,13 @@ ExpressionDecompiler::decompilePC(jsbytecode *pc)
return sprinter.printf("%d", GetBytecodeInteger(pc)) >= 0;
case JSOP_STRING:
return quote(loadAtom(pc), '"');
case JSOP_SYMBOL: {
unsigned i = uint8_t(pc[1]);
MOZ_ASSERT(i < JS::WellKnownSymbolLimit);
if (i < JS::WellKnownSymbolLimit)
return write(cx->names().wellKnownSymbolDescriptions()[i]);
break;
}
case JSOP_UNDEFINED:
return write(js_undefined_str);
case JSOP_THIS:

View File

@ -26,7 +26,7 @@ function test()
var [a, b, [c0, c1]] = [x, x, x];
}
expect = 'TypeError: (intermediate value)[(intermediate value)](...).next(...).value is null';
expect = 'TypeError: (intermediate value)[Symbol.iterator](...).next(...).value is null';
actual = 'No Error';
try
{

View File

@ -0,0 +1,26 @@
// The decompiler can handle the implicit call to @@iterator in a for-of loop.
var x;
function check(code) {
var s = "no exception thrown";
try {
eval(code);
} catch (exc) {
s = exc.message;
}
assertEq(s, "x[Symbol.iterator] is not a function");
}
x = {};
check("for (var v of x) throw fit;");
check("[...x]");
check("Math.hypot(...x)");
x[Symbol.iterator] = "potato";
check("for (var v of x) throw fit;");
x[Symbol.iterator] = {};
check("for (var v of x) throw fit;");
if (typeof reportCompare === "function")
reportCompare(0, 0, "ok");

View File

@ -400,6 +400,10 @@ struct JSAtomState
#define PROPERTYNAME_FIELD(name, code, init, clasp) js::ImmutablePropertyNamePtr name;
JS_FOR_EACH_PROTOTYPE(PROPERTYNAME_FIELD)
#undef PROPERTYNAME_FIELD
js::ImmutablePropertyNamePtr *wellKnownSymbolDescriptions() {
return &Symbol_iterator;
}
};
namespace js {