Commit d0db1c39 authored by arv's avatar arv Committed by Commit bot

[es6] Function.prototype.name should be the empty string

ES6 specifies the function name property (it was not part of ES5) and
it specifies the name of Function.prototype to the empty string ("" and
not "Empty"). This makes us match Firefox, Safari and IE developer
preview.

BUG=v8:4033
LOG=N
R=adamk@chromium.org
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel

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

Cr-Commit-Position: refs/heads/master@{#28021}
parent bf06d5c9
...@@ -501,13 +501,10 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { ...@@ -501,13 +501,10 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
.Assert(); .Assert();
} }
// Allocate the empty function as the prototype for function ECMAScript // Allocate the empty function as the prototype for function - ES6 19.2.3
// 262 15.3.4.
Handle<String> empty_string =
factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty"));
Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction)); Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype( Handle<JSFunction> empty_function =
empty_string, code); factory->NewFunctionWithoutPrototype(factory->empty_string(), code);
// Allocate the function map first and then patch the prototype later // Allocate the function map first and then patch the prototype later
Handle<Map> empty_function_map = Handle<Map> empty_function_map =
......
...@@ -90,10 +90,10 @@ test(testFunctionToString); ...@@ -90,10 +90,10 @@ test(testFunctionToString);
function f() {} function f() {}
delete f.name; delete f.name;
assertEquals('Empty', f.name); assertEquals('', f.name);
f.name = 42; f.name = 42;
assertEquals('Empty', f.name); // non writable prototype property. assertEquals('', f.name); // non writable prototype property.
assertFalse(f.hasOwnProperty('name')); assertFalse(f.hasOwnProperty('name'));
Object.defineProperty(Function.prototype, 'name', {writable: true}); Object.defineProperty(Function.prototype, 'name', {writable: true});
...@@ -108,7 +108,7 @@ test(testFunctionToString); ...@@ -108,7 +108,7 @@ test(testFunctionToString);
function f() {} function f() {}
assertTrue(delete f.name); assertTrue(delete f.name);
assertFalse(f.hasOwnProperty('name')); assertFalse(f.hasOwnProperty('name'));
assertEquals('Empty', f.name); assertEquals('', f.name);
assertTrue(delete Function.prototype.name); assertTrue(delete Function.prototype.name);
assertEquals(undefined, f.name); assertEquals(undefined, f.name);
......
// Copyright 2015 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.
assertSame('', Function.prototype.name);
var descr = Object.getOwnPropertyDescriptor(Function.prototype, 'name');
assertFalse(descr.enumerable);
assertTrue(descr.configurable);
assertFalse(descr.writable);
assertSame('', descr.value);
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