48c9ca4462
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/+/1764622 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Joshua Litt <joshualitt@chromium.org> Cr-Commit-Position: refs/heads/master@{#63373}
73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
(function testFunctionNames() {
|
|
let descriptor = {
|
|
value: '',
|
|
writable: false,
|
|
enumerable: false,
|
|
configurable: true
|
|
};
|
|
// Functions have a "name" property by default.
|
|
assertEquals(
|
|
descriptor, Object.getOwnPropertyDescriptor(function(){}, 'name'));
|
|
let a = { fn: function(){} };
|
|
assertSame('fn', a.fn.name);
|
|
descriptor.value = 'fn';
|
|
assertEquals(descriptor, Object.getOwnPropertyDescriptor(a.fn, 'name'));
|
|
|
|
let b = { __proto__: function(){} };
|
|
assertSame('', b.__proto__.name);
|
|
descriptor.value = '';
|
|
assertEquals(
|
|
descriptor, Object.getOwnPropertyDescriptor(b.__proto__, 'name'));
|
|
|
|
let c = { fn: function F(){} };
|
|
assertSame('F', c.fn.name);
|
|
descriptor.value = 'F';
|
|
assertEquals(descriptor, Object.getOwnPropertyDescriptor(c.fn, 'name'));
|
|
|
|
let d = { __proto__: function E(){} };
|
|
assertSame('E', d.__proto__.name);
|
|
descriptor.value = 'E';
|
|
assertEquals(
|
|
descriptor, Object.getOwnPropertyDescriptor(d.__proto__, 'name'));
|
|
})();
|
|
|
|
(function testClassNames() {
|
|
let descriptor = {
|
|
value: '',
|
|
writable: false,
|
|
enumerable: false,
|
|
configurable: true
|
|
};
|
|
|
|
// 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'));
|
|
|
|
let a = { fn: class {} };
|
|
assertSame('fn', a.fn.name);
|
|
descriptor.value = 'fn';
|
|
assertEquals(descriptor, Object.getOwnPropertyDescriptor(a.fn, 'name'));
|
|
|
|
let b = { __proto__: class {} };
|
|
assertSame('', b.__proto__.name);
|
|
descriptor.value = '';
|
|
assertEquals(
|
|
descriptor, Object.getOwnPropertyDescriptor(b.__proto__, 'name'));
|
|
|
|
let c = { fn: class F {} };
|
|
assertSame('F', c.fn.name);
|
|
descriptor.value = 'F';
|
|
assertEquals(descriptor, Object.getOwnPropertyDescriptor(c.fn, 'name'));
|
|
|
|
let d = { __proto__: class F {} };
|
|
assertSame('F', d.__proto__.name);
|
|
descriptor.value = 'F';
|
|
assertEquals(
|
|
descriptor, Object.getOwnPropertyDescriptor(d.__proto__, 'name'));
|
|
})();
|