Commit 48c9ca44 authored by Joshua Litt's avatar Joshua Litt Committed by Commit Bot

[names] Fix some test262 name tests to conform with spec changes

In order to reflect web reality, TC39 has made some slight changes to
name descriptors, see https://github.com/tc39/ecma262/pull/1490 for
details. V8 was mostly already in compliance with these changes, but
ThrowTypeError and anonymous classes needed some slight changes.

Bug: v8:9646
Change-Id: I163238954938f0c005e3adbc61b90498e01436da
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1764622Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63373}
parent 0292896d
......@@ -660,17 +660,21 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic() {
Handle<JSFunction> function = factory()->NewFunction(args);
function->shared().DontAdaptArguments();
// %ThrowTypeError% must not have a name property.
if (JSReceiver::DeleteProperty(function, factory()->name_string())
.IsNothing()) {
DCHECK(false);
}
PropertyAttributes ro_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
// %ThrowTypeError% must have a name property with an empty string value.
// Per spec, ThrowTypeError's name must also be non-configurable, otherwise
// we could omit explicitly setting a property attribute here and just fall
// back to the default name attribute on function.
JSObject::SetOwnPropertyIgnoreAttributes(
function, factory()->name_string(), factory()->empty_string(), ro_attribs)
.Assert();
// length needs to be non configurable.
Handle<Object> value(Smi::FromInt(function->length()), isolate());
JSObject::SetOwnPropertyIgnoreAttributes(
function, factory()->length_string(), value,
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
JSObject::SetOwnPropertyIgnoreAttributes(function, factory()->length_string(),
value, ro_attribs)
.Assert();
if (JSObject::PreventExtensions(function, kThrowOnError).IsNothing()) {
......
......@@ -528,8 +528,7 @@ Handle<ClassBoilerplate> ClassBoilerplate::BuildClassBoilerplate(
// Add name accessor to the class object if necessary.
bool install_class_name_accessor = false;
if (!expr->has_name_static_property() &&
expr->constructor()->has_shared_name()) {
if (!expr->has_name_static_property()) {
if (static_desc.HasDictionaryProperties()) {
// Install class name accessor if necessary during class literal
// instantiation.
......
......@@ -37,7 +37,7 @@
literal = { __proto__: class {} };
assertEquals('', literal.__proto__.name);
assertEquals(
undefined, Object.getOwnPropertyDescriptor(literal.__proto__, 'name'));
'', Object.getOwnPropertyDescriptor(literal.__proto__, 'name').value);
literal = { __proto__: class F {} };
assertEquals('F', literal.__proto__.name);
......
......@@ -394,7 +394,7 @@
})();
(function testClassNameOrder() {
assertEquals(['length', 'prototype'], Object.getOwnPropertyNames(class {}));
assertEquals(['length', 'prototype', 'name'], Object.getOwnPropertyNames(class {}));
var tmp = {'': class {}};
var Tmp = tmp[''];
......
......@@ -5,8 +5,12 @@
var throwTypeErrorFunction =
Object.getOwnPropertyDescriptor(Function.prototype, 'arguments').get;
assertFalse(
Object.prototype.hasOwnProperty.call(throwTypeErrorFunction, 'name'));
var nameDesc =
Object.getOwnPropertyDescriptor(throwTypeErrorFunction, 'name');
assertEquals('', nameDesc.value);
assertFalse(nameDesc.configurable);
assertFalse(nameDesc.enumerable);
assertFalse(nameDesc.writable);
assertThrows(function() {
'use strict';
throwTypeErrorFunction.name = 'foo';
......
......@@ -43,8 +43,8 @@
configurable: true
};
// Anonymous classes do not have a "name" property by default.
assertSame(undefined, Object.getOwnPropertyDescriptor(class {}, 'name'));
// Anonymous classes do have a "name" property by default with a value of ''.
assertEquals(descriptor, Object.getOwnPropertyDescriptor(class {}, 'name'));
descriptor.value = 'C';
assertEquals(descriptor, Object.getOwnPropertyDescriptor(class C {}, 'name'));
......@@ -55,8 +55,9 @@
let b = { __proto__: class {} };
assertSame('', b.__proto__.name);
assertSame(
undefined, Object.getOwnPropertyDescriptor(b.__proto__, 'name'));
descriptor.value = '';
assertEquals(
descriptor, Object.getOwnPropertyDescriptor(b.__proto__, 'name'));
let c = { fn: class F {} };
assertSame('F', c.fn.name);
......
......@@ -549,10 +549,6 @@
'intl402/RelativeTimeFormat/constructor/constructor/locales-valid': [FAIL],
'intl402/Segmenter/constructor/constructor/locales-valid': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=9646
'built-ins/ThrowTypeError/name': [FAIL],
'language/expressions/class/name': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=9647
'language/expressions/assignment/dstr/ident-name-prop-name-literal-break-escaped': [FAIL],
'language/expressions/assignment/dstr/ident-name-prop-name-literal-case-escaped': [FAIL],
......
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