[es6] Function.prototype.name should be the empty string
authorarv <arv@chromium.org>
Thu, 23 Apr 2015 00:29:40 +0000 (17:29 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 23 Apr 2015 00:29:27 +0000 (00:29 +0000)
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}

src/bootstrapper.cc
test/mjsunit/es6/function-name-configurable.js
test/mjsunit/es6/function-prototype-name.js [new file with mode: 0644]

index 1a5bfcf..1fbbcb9 100644 (file)
@@ -501,13 +501,10 @@ Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
         .Assert();
   }
 
-  // Allocate the empty function as the prototype for function ECMAScript
-  // 262 15.3.4.
-  Handle<String> empty_string =
-      factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty"));
+  // Allocate the empty function as the prototype for function - ES6 19.2.3
   Handle<Code> code(isolate->builtins()->builtin(Builtins::kEmptyFunction));
-  Handle<JSFunction> empty_function = factory->NewFunctionWithoutPrototype(
-      empty_string, code);
+  Handle<JSFunction> empty_function =
+      factory->NewFunctionWithoutPrototype(factory->empty_string(), code);
 
   // Allocate the function map first and then patch the prototype later
   Handle<Map> empty_function_map =
index f0ff406..68ba82d 100644 (file)
@@ -90,10 +90,10 @@ test(testFunctionToString);
 
   function f() {}
   delete f.name;
-  assertEquals('Empty', f.name);
+  assertEquals('', f.name);
 
   f.name = 42;
-  assertEquals('Empty', f.name);  // non writable prototype property.
+  assertEquals('', f.name);  // non writable prototype property.
   assertFalse(f.hasOwnProperty('name'));
 
   Object.defineProperty(Function.prototype, 'name', {writable: true});
@@ -108,7 +108,7 @@ test(testFunctionToString);
   function f() {}
   assertTrue(delete f.name);
   assertFalse(f.hasOwnProperty('name'));
-  assertEquals('Empty', f.name);
+  assertEquals('', f.name);
 
   assertTrue(delete Function.prototype.name);
   assertEquals(undefined, f.name);
diff --git a/test/mjsunit/es6/function-prototype-name.js b/test/mjsunit/es6/function-prototype-name.js
new file mode 100644 (file)
index 0000000..4766bd4
--- /dev/null
@@ -0,0 +1,11 @@
+// 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);