Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: test/mjsunit/es6/function-name-configurable.js

Issue 960343002: ES6: Make function name configurable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use reconfigure instead Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | test/mjsunit/es7/object-observe.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/function-name-configurable.js
diff --git a/test/mjsunit/es6/function-name-configurable.js b/test/mjsunit/es6/function-name-configurable.js
new file mode 100644
index 0000000000000000000000000000000000000000..f0ff406da86d0f0c39648ba4785eeede43c47cf0
--- /dev/null
+++ b/test/mjsunit/es6/function-name-configurable.js
@@ -0,0 +1,115 @@
+// 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.
+
+function getStrictF() {
+ 'use strict';
+ return function f() {};
+}
+
+
+function getSloppyF() {
+ return function f() {};
+}
+
+
+function test(testFunction) {
+ testFunction(getStrictF());
+ testFunction(getSloppyF());
+}
+
+
+function testDescriptor(f) {
+ var descr = Object.getOwnPropertyDescriptor(f, 'name');
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertEquals('f', descr.value);
+ assertFalse(descr.writable);
+}
+test(testDescriptor);
+
+
+function testSet(f) {
+ f.name = 'g';
+ assertEquals('f', f.name);
+}
+test(testSet);
+
+
+function testSetStrict(f) {
+ 'use strict';
+ assertThrows(function() {
+ f.name = 'g';
+ }, TypeError);
+}
+test(testSetStrict);
+
+
+function testReconfigureAsDataProperty(f) {
+ Object.defineProperty(f, 'name', {
+ value: 'g',
+ });
+ assertEquals('g', f.name);
+ Object.defineProperty(f, 'name', {
+ writable: true
+ });
+ f.name = 'h';
+ assertEquals('h', f.name);
+
+ f.name = 42;
+ assertEquals(42, f.name);
+}
+test(testReconfigureAsDataProperty);
+
+
+function testReconfigureAsAccessorProperty(f) {
+ var name = 'g';
+ Object.defineProperty(f, 'name', {
+ get: function() { return name; },
+ set: function(v) { name = v; }
+ });
+ assertEquals('g', f.name);
+ f.name = 'h';
+ assertEquals('h', f.name);
+}
+test(testReconfigureAsAccessorProperty);
+
+
+function testFunctionToString(f) {
+ Object.defineProperty(f, 'name', {
+ value: {toString: function() { assertUnreachable(); }},
+ });
+ assertEquals('function f() {}', f.toString());
+}
+test(testFunctionToString);
+
+
+(function testSetOnInstance() {
+ // This needs to come before testDelete below
+ assertTrue(Function.prototype.hasOwnProperty('name'));
+
+ function f() {}
+ delete f.name;
+ assertEquals('Empty', f.name);
+
+ f.name = 42;
+ assertEquals('Empty', f.name); // non writable prototype property.
+ assertFalse(f.hasOwnProperty('name'));
+
+ Object.defineProperty(Function.prototype, 'name', {writable: true});
+
+ f.name = 123;
+ assertTrue(f.hasOwnProperty('name'));
+ assertEquals(123, f.name);
+})();
+
+
+(function testDelete() {
+ function f() {}
+ assertTrue(delete f.name);
+ assertFalse(f.hasOwnProperty('name'));
+ assertEquals('Empty', f.name);
+
+ assertTrue(delete Function.prototype.name);
+ assertEquals(undefined, f.name);
+})();
« no previous file with comments | « src/bootstrapper.cc ('k') | test/mjsunit/es7/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698