Commit 2a20d518 authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[es6] add SetFunctionName() behaviour to AssignmentExpression

BUG=v8:3699
LOG=N
R=adamk@chromium.org, rossberg@chromium.org, littledan@chromium.org

Review URL: https://codereview.chromium.org/1582783004

Cr-Commit-Position: refs/heads/master@{#33276}
parent a3a6bd41
......@@ -2126,6 +2126,10 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
}
}
if (op == Token::ASSIGN && allow_harmony_function_name()) {
Traits::SetFunctionNameFromIdentifierRef(right, expression);
}
ExpressionT result = factory()->NewAssignment(op, expression, right, pos);
if (is_destructuring_assignment) {
......
......@@ -5453,5 +5453,28 @@ void ParserTraits::SetFunctionNameFromPropertyName(
}
void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier) {
if (!value->IsFunctionLiteral() && !value->IsClassLiteral()) return;
if (!identifier->IsVariableProxy()) return;
auto name = identifier->AsVariableProxy()->raw_name();
DCHECK_NOT_NULL(name);
if (value->IsFunctionLiteral()) {
auto function = value->AsFunctionLiteral();
if (function->is_anonymous()) {
function->set_raw_name(name);
}
} else {
DCHECK(value->IsClassLiteral());
auto class_literal = value->AsClassLiteral();
if (class_literal->raw_name() == nullptr) {
class_literal->set_raw_name(name);
}
}
}
} // namespace internal
} // namespace v8
......@@ -646,6 +646,9 @@ class ParserTraits {
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
void SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier);
private:
Parser* parser_;
};
......
......@@ -929,6 +929,8 @@ class PreParserTraits {
void SetFunctionNameFromPropertyName(PreParserExpression,
PreParserIdentifier) {}
void SetFunctionNameFromIdentifierRef(PreParserExpression,
PreParserExpression) {}
private:
PreParser* pre_parser_;
......
......@@ -120,3 +120,42 @@
// Should be '[2]'
assertEquals('', C[sym2].name);
})();
(function testAssignment() {
var basicFn, arrowFn, generatorFn, classLit;
basicFn = function() { return true; };
assertEquals('basicFn', basicFn.name);
var basicFn2 = basicFn;
assertEquals('basicFn', basicFn2.name);
basicFn = function functionWithName() { };
assertEquals("functionWithName", basicFn.name);
arrowFn = x => x;
assertEquals('arrowFn', arrowFn.name);
var arrowFn2 = arrowFn;
assertEquals('arrowFn', arrowFn2.name);
generatorFn = function*() { yield true; };
assertEquals('generatorFn', generatorFn.name);
var generatorFn2 = generatorFn;
assertEquals('generatorFn', generatorFn2.name);
generatorFn = function* generatorWithName() { };
assertEquals("generatorWithName", generatorFn.name);
classLit = class { constructor() {} };
assertEquals('classLit', classLit.name);
var classLit2 = classLit;
assertEquals('classLit', classLit2.name);
classLit = class classWithName { constructor() {} };
assertEquals('classWithName', classLit.name);
classLit = class { constructor() {} static name() {} };
assertEquals('function', typeof classLit.name);
classLit = class { constructor() {} static get name() { return true; } };
assertTrue(classLit.name);
classLit = class { constructor() {} static ['name']() {} };
assertEquals('function', typeof classLit.name);
classLit = class { constructor() {} static get ['name']() { return true; } };
assertTrue(classLit.name);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment