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

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

Issue 977003004: ES6: Make function name configurable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | test/mjsunit/es7/object-observe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function getStrictF() {
6 'use strict';
7 return function f() {};
8 }
9
10
11 function getSloppyF() {
12 return function f() {};
13 }
14
15
16 function test(testFunction) {
17 testFunction(getStrictF());
18 testFunction(getSloppyF());
19 }
20
21
22 function testDescriptor(f) {
23 var descr = Object.getOwnPropertyDescriptor(f, 'name');
24 assertTrue(descr.configurable);
25 assertFalse(descr.enumerable);
26 assertEquals('f', descr.value);
27 assertFalse(descr.writable);
28 }
29 test(testDescriptor);
30
31
32 function testSet(f) {
33 f.name = 'g';
34 assertEquals('f', f.name);
35 }
36 test(testSet);
37
38
39 function testSetStrict(f) {
40 'use strict';
41 assertThrows(function() {
42 f.name = 'g';
43 }, TypeError);
44 }
45 test(testSetStrict);
46
47
48 function testReconfigureAsDataProperty(f) {
49 Object.defineProperty(f, 'name', {
50 value: 'g',
51 });
52 assertEquals('g', f.name);
53 Object.defineProperty(f, 'name', {
54 writable: true
55 });
56 f.name = 'h';
57 assertEquals('h', f.name);
58
59 f.name = 42;
60 assertEquals(42, f.name);
61 }
62 test(testReconfigureAsDataProperty);
63
64
65 function testReconfigureAsAccessorProperty(f) {
66 var name = 'g';
67 Object.defineProperty(f, 'name', {
68 get: function() { return name; },
69 set: function(v) { name = v; }
70 });
71 assertEquals('g', f.name);
72 f.name = 'h';
73 assertEquals('h', f.name);
74 }
75 test(testReconfigureAsAccessorProperty);
76
77
78 function testFunctionToString(f) {
79 Object.defineProperty(f, 'name', {
80 value: {toString: function() { assertUnreachable(); }},
81 });
82 assertEquals('function f() {}', f.toString());
83 }
84 test(testFunctionToString);
85
86
87 (function testSetOnInstance() {
88 // This needs to come before testDelete below
89 assertTrue(Function.prototype.hasOwnProperty('name'));
90
91 function f() {}
92 delete f.name;
93 assertEquals('Empty', f.name);
94
95 f.name = 42;
96 assertEquals('Empty', f.name); // non writable prototype property.
97 assertFalse(f.hasOwnProperty('name'));
98
99 Object.defineProperty(Function.prototype, 'name', {writable: true});
100
101 f.name = 123;
102 assertTrue(f.hasOwnProperty('name'));
103 assertEquals(123, f.name);
104 })();
105
106
107 (function testDelete() {
108 function f() {}
109 assertTrue(delete f.name);
110 assertFalse(f.hasOwnProperty('name'));
111 assertEquals('Empty', f.name);
112
113 assertTrue(delete Function.prototype.name);
114 assertEquals(undefined, f.name);
115 })();
OLDNEW
« 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