- Revision
- 179873
- Author
- [email protected]
- Date
- 2015-02-10 11:01:41 -0800 (Tue, 10 Feb 2015)
Log Message
Parser::parseVarDeclarationList gets the wrong JSToken for the last identifier
https://bugs.webkit.org/show_bug.cgi?id=141272
Reviewed by Oliver Hunt.
This patch fixes a bug where the wrong text location would be
assigned to a variable declaration inside a ForIn/ForOf loop.
It also fixes a bug in the type profiler where the type profiler
emits the wrong text offset for a ForIn loop's variable declarator
when it's not a pattern node.
* bytecompiler/NodesCodegen.cpp:
(JSC::ForInNode::emitLoopHeader):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseVarDeclarationList):
* tests/typeProfiler/loop.js:
(testForIn):
(testForOf):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (179872 => 179873)
--- trunk/Source/_javascript_Core/ChangeLog 2015-02-10 17:28:03 UTC (rev 179872)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-02-10 19:01:41 UTC (rev 179873)
@@ -1,3 +1,24 @@
+2015-02-10 Saam Barati <[email protected]>
+
+ Parser::parseVarDeclarationList gets the wrong JSToken for the last identifier
+ https://bugs.webkit.org/show_bug.cgi?id=141272
+
+ Reviewed by Oliver Hunt.
+
+ This patch fixes a bug where the wrong text location would be
+ assigned to a variable declaration inside a ForIn/ForOf loop.
+ It also fixes a bug in the type profiler where the type profiler
+ emits the wrong text offset for a ForIn loop's variable declarator
+ when it's not a pattern node.
+
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::ForInNode::emitLoopHeader):
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseVarDeclarationList):
+ * tests/typeProfiler/loop.js:
+ (testForIn):
+ (testForOf):
+
2015-02-09 Saam Barati <[email protected]>
JSC's Type Profiler doesn't profile the type of the looping variable in ForOf/ForIn loops
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (179872 => 179873)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-02-10 17:28:03 UTC (rev 179872)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-02-10 19:01:41 UTC (rev 179873)
@@ -2076,7 +2076,7 @@
}
generator.emitMove(local.get(), propertyName);
if (generator.vm()->typeProfiler())
- generator.emitTypeProfilerExpressionInfo(m_lexpr->position(), JSTextPosition(-1, m_lexpr->position().offset + ident.length(), -1));
+ generator.emitTypeProfilerExpressionInfo(simpleBinding->divotStart(), simpleBinding->divotEnd());
return;
}
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (179872 => 179873)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2015-02-10 17:28:03 UTC (rev 179872)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2015-02-10 19:01:41 UTC (rev 179873)
@@ -452,6 +452,7 @@
TreeExpression head = 0;
TreeExpression tail = 0;
const Identifier* lastIdent;
+ JSToken lastIdentToken;
do {
lastIdent = 0;
lastPattern = 0;
@@ -466,6 +467,7 @@
identStart = varStart;
const Identifier* name = m_token.m_data.ident;
lastIdent = name;
+ lastIdentToken = m_token;
next();
hasInitializer = match(EQUAL);
failIfFalseIfStrict(declareVariable(name), "Cannot declare a variable named ", name->impl(), " in strict mode");
@@ -506,7 +508,7 @@
tail = context.appendToCommaExpr(location, head, tail, node);
} while (match(COMMA));
if (lastIdent)
- lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, m_token);
+ lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, lastIdentToken);
return head;
}
Modified: trunk/Source/_javascript_Core/tests/typeProfiler/loop.js (179872 => 179873)
--- trunk/Source/_javascript_Core/tests/typeProfiler/loop.js 2015-02-10 17:28:03 UTC (rev 179872)
+++ trunk/Source/_javascript_Core/tests/typeProfiler/loop.js 2015-02-10 19:01:41 UTC (rev 179873)
@@ -1,37 +1,57 @@
load("./driver/driver.js");
function testForIn(x) {
- // FIXME: add support for the following statement types: "for (var arg of expr)" and "for (var arg in expr)"
- // https://bugs.webkit.org/show_bug.cgi?id=141241
-
+ for (var arg1 in x)
+ x;
+
for (arg2 in x)
x;
- for ({x: arg3} in x)
+ for ({x: arg3} in x)
x;
+
+ for (var {x: arg4} in x)
+ x;
}
function testForOf(x) {
+ for (var arg1 of x)
+ x;
+
for (arg2 of x)
x;
for ({x: arg3} of x)
x;
+ for (var {x: arg4} of x)
+ x;
}
testForIn([1])
-var types = findTypeForExpression(testForIn, "arg2");
+var types = findTypeForExpression(testForIn, "arg1");
assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
+types = findTypeForExpression(testForIn, "arg2");
+assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.String) !== -1, "Primitive type names should contain 'String'");
types = findTypeForExpression(testForIn, "arg3");
assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
+types = findTypeForExpression(testForIn, "arg4");
+assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
testForOf([1])
+types = findTypeForExpression(testForOf, "arg1");
+assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
types = findTypeForExpression(testForOf, "arg2");
assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
types = findTypeForExpression(testForOf, "arg3");
assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
+types = findTypeForExpression(testForOf, "arg4");
+assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Undefined) !== -1, "Primitive type names should contain 'Undefined'");
testForOf([{x:29}])
+types = findTypeForExpression(testForOf, "arg1");
+assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg1' should have field 'x'");
types = findTypeForExpression(testForOf, "arg2");
-assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg1' should have field 'x'");
+assert(types.instructionTypeSet.structures[0].fields.indexOf("x") !== -1, "variable 'arg2' should have field 'x'");
types = findTypeForExpression(testForOf, "arg3");
assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");
+types = findTypeForExpression(testForOf, "arg4");
+assert(types.instructionTypeSet.primitiveTypeNames.indexOf(T.Integer) !== -1, "Primitive type names should contain 'Integer'");