Fix "name" property of %ThrowTypeError% to be spec-conformant

This is a normative PR that reached consensus at the June 2019 TC39:
https://github.com/tc39/test262/pull/2299

Bug: v8:9646
Change-Id: Idbeea703fe264da43825729e7b37a08a1bb10001
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2360907
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69466}
This commit is contained in:
Shu-yu Guo 2020-08-18 12:00:37 -07:00 committed by Commit Bot
parent 65dde24353
commit 985a9ddaa1
3 changed files with 13 additions and 10 deletions

View File

@ -642,11 +642,14 @@ 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);
}
// %ThrowTypeError% must have a name property with an empty string value. Per
// spec, ThrowTypeError's name is non-configurable, unlike ordinary functions'
// name property. To redefine it to be non-configurable, use
// SetOwnPropertyIgnoreAttributes.
JSObject::SetOwnPropertyIgnoreAttributes(
function, factory()->name_string(), factory()->empty_string(),
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
.Assert();
// length needs to be non configurable.
Handle<Object> value(Smi::FromInt(function->length()), isolate());

View File

@ -5,8 +5,11 @@
var throwTypeErrorFunction =
Object.getOwnPropertyDescriptor(Function.prototype, 'arguments').get;
assertFalse(
Object.prototype.hasOwnProperty.call(throwTypeErrorFunction, 'name'));
var nameDesc =
Object.getOwnPropertyDescriptor(throwTypeErrorFunction, 'name');
assertFalse(nameDesc.configurable, 'configurable');
assertFalse(nameDesc.enumerable, 'enumerable');
assertFalse(nameDesc.writable, 'writable');
assertThrows(function() {
'use strict';
throwTypeErrorFunction.name = 'foo';

View File

@ -502,9 +502,6 @@
'intl402/Intl/getCanonicalLocales/unicode-ext-canonicalize-yes-to-true': [FAIL],
'intl402/Intl/getCanonicalLocales/unicode-ext-key-with-digit': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=9646
'built-ins/ThrowTypeError/name': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=9742
'intl402/Locale/getters': [FAIL],