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.
5 function getStrictF() {
7 return function f(x) {};
11 function getSloppyF() {
12 return function f(x) {};
16 function getStrictGenerator() {
18 return function* f(x) {};
22 function getSloppyGenerator() {
23 return function* f(x) {};
27 function test(testFunction) {
28 testFunction(getStrictF());
29 testFunction(getSloppyF());
30 testFunction(getStrictGenerator());
31 testFunction(getSloppyGenerator());
35 function testDescriptor(f) {
36 var descr = Object.getOwnPropertyDescriptor(f, 'length');
37 assertTrue(descr.configurable);
38 assertFalse(descr.enumerable);
39 assertEquals(1, descr.value);
40 assertFalse(descr.writable);
47 assertEquals(1, f.length);
52 function testSetStrict(f) {
54 assertThrows(function() {
61 function testReconfigureAsDataProperty(f) {
62 Object.defineProperty(f, 'length', {
65 assertEquals(2, f.length);
66 Object.defineProperty(f, 'length', {
70 assertEquals(3, f.length);
73 assertEquals(42, f.length);
75 test(testReconfigureAsDataProperty);
78 function testReconfigureAsAccessorProperty(f) {
80 Object.defineProperty(f, 'length', {
81 get: function() { return length; },
82 set: function(v) { length = v; }
84 assertEquals(2, f.length);
86 assertEquals(3, f.length);
88 test(testReconfigureAsAccessorProperty);
91 (function testSetOnInstance() {
92 // This needs to come before testDelete below
93 assertTrue(Function.prototype.hasOwnProperty('length'));
97 assertEquals(0, f.length);
100 assertEquals(0, f.length); // non writable prototype property.
101 assertFalse(f.hasOwnProperty('length'));
103 Object.defineProperty(Function.prototype, 'length', {writable: true});
106 assertTrue(f.hasOwnProperty('length'));
107 assertEquals(123, f.length);
111 (function testDelete() {
113 assertTrue(delete f.length);
114 assertFalse(f.hasOwnProperty('length'));
115 assertEquals(0, f.length);
117 assertTrue(delete Function.prototype.length);
118 assertEquals(undefined, f.length);