Commit dadb3a5b authored by adamk's avatar adamk Committed by Commit bot

Add ES2015 Function.name support to pattern and default parameter initializers

Note that in these cases, we don't support computed property names yet, just
as we don't for object and class literals.

BUG=v8:3699, v8:4710
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#33562}
parent 4a2f3ee8
......@@ -1677,6 +1677,10 @@ ParserBase<Traits>::ParsePropertyDefinition(
classifier->RecordCoverInitializedNameError(
Scanner::Location(next_beg_pos, scanner()->location().end_pos),
MessageTemplate::kInvalidCoverInitializedName);
if (allow_harmony_function_name()) {
Traits::SetFunctionNameFromIdentifierRef(rhs, lhs);
}
} else {
value = lhs;
}
......@@ -2882,6 +2886,10 @@ void ParserBase<Traits>::ParseFormalParameter(
if (!*ok) return;
parameters->is_simple = false;
classifier->RecordNonSimpleParameter();
if (allow_harmony_function_name()) {
Traits::SetFunctionNameFromIdentifierRef(initializer, pattern);
}
}
Traits::AddFormalParameter(parameters, pattern, initializer,
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
//
// Flags: --harmony-function-name
// Flags: --harmony-destructuring-bind --harmony-destructuring-assignment
(function testVariableDeclarationsFunction() {
'use strict';
......@@ -159,3 +160,153 @@
classLit = class { constructor() {} static get ['name']() { return true; } };
assertTrue(classLit.name);
})();
(function testObjectBindingPattern() {
var {
a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
foo: bar = function() {},
inParens = (() => {}),
inManyParens = ((((() => {})))),
} = {};
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('bar', bar.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})();
(function testArrayBindingPattern() {
var [
a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
inParens = (() => {}),
inManyParens = ((((() => {})))),
] = [];
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})();
(function testObjectAssignmentPattern() {
var a, b, x, y, z, q;
({
a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
foo: bar = function() {},
inParens = (() => {}),
inManyParens = ((((() => {})))),
} = {});
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('bar', bar.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})();
(function testArrayAssignmentPattern() {
var a, b, x, y, z, q;
[
a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
inParens = (() => {}),
inManyParens = ((((() => {})))),
] = [];
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})();
(function testParameterDestructuring() {
(function({ a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
foo: bar = function() {},
inParens = (() => {}),
inManyParens = ((((() => {})))) }) {
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('bar', bar.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})({});
(function([ a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
inParens = (() => {}),
inManyParens = ((((() => {})))) ]) {
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.name)
})([]);
})();
(function testDefaultParameters() {
(function(a = function() {},
b = () => {},
x = function withName() { },
y = class { },
z = class ClassName { },
q = class { static name() { return 42 } },
inParens = (() => {}),
inManyParens = ((((() => {}))))) {
assertEquals('a', a.name);
assertEquals('b', b.name);
assertEquals('withName', x.name);
assertEquals('y', y.name);
assertEquals('ClassName', z.name);
assertEquals('function', typeof q.name);
assertEquals('inParens', inParens.name)
assertEquals('inManyParens', inManyParens.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