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

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

Issue 993073002: [es6] Function length property should be configurable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix status file again 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 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-length-configurable.js
diff --git a/test/mjsunit/es6/function-length-configurable.js b/test/mjsunit/es6/function-length-configurable.js
new file mode 100644
index 0000000000000000000000000000000000000000..e5b51aba206410844ec993858d499efbf0483ccf
--- /dev/null
+++ b/test/mjsunit/es6/function-length-configurable.js
@@ -0,0 +1,119 @@
+// 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(x) {};
+}
+
+
+function getSloppyF() {
+ return function f(x) {};
+}
+
+
+function getStrictGenerator() {
+ 'use strict';
+ return function* f(x) {};
+}
+
+
+function getSloppyGenerator() {
+ return function* f(x) {};
+}
+
+
+function test(testFunction) {
+ testFunction(getStrictF());
+ testFunction(getSloppyF());
+ testFunction(getStrictGenerator());
+ testFunction(getSloppyGenerator());
+}
+
+
+function testDescriptor(f) {
+ var descr = Object.getOwnPropertyDescriptor(f, 'length');
+ assertTrue(descr.configurable);
+ assertFalse(descr.enumerable);
+ assertEquals(1, descr.value);
+ assertFalse(descr.writable);
+}
+test(testDescriptor);
+
+
+function testSet(f) {
+ f.length = 2;
+ assertEquals(1, f.length);
+}
+test(testSet);
+
+
+function testSetStrict(f) {
+ 'use strict';
+ assertThrows(function() {
+ f.length = 2;
+ }, TypeError);
+}
+test(testSetStrict);
+
+
+function testReconfigureAsDataProperty(f) {
+ Object.defineProperty(f, 'length', {
+ value: 2,
+ });
+ assertEquals(2, f.length);
+ Object.defineProperty(f, 'length', {
+ writable: true
+ });
+ f.length = 3;
+ assertEquals(3, f.length);
+
+ f.length = 42;
+ assertEquals(42, f.length);
+}
+test(testReconfigureAsDataProperty);
+
+
+function testReconfigureAsAccessorProperty(f) {
+ var length = 2;
+ Object.defineProperty(f, 'length', {
+ get: function() { return length; },
+ set: function(v) { length = v; }
+ });
+ assertEquals(2, f.length);
+ f.length = 3;
+ assertEquals(3, f.length);
+}
+test(testReconfigureAsAccessorProperty);
+
+
+(function testSetOnInstance() {
+ // This needs to come before testDelete below
+ assertTrue(Function.prototype.hasOwnProperty('length'));
+
+ function f() {}
+ delete f.length;
+ assertEquals(0, f.length);
+
+ f.length = 42;
+ assertEquals(0, f.length); // non writable prototype property.
+ assertFalse(f.hasOwnProperty('length'));
+
+ Object.defineProperty(Function.prototype, 'length', {writable: true});
+
+ f.length = 123;
+ assertTrue(f.hasOwnProperty('length'));
+ assertEquals(123, f.length);
+})();
+
+
+(function testDelete() {
+ function f(x) {}
+ assertTrue(delete f.length);
+ assertFalse(f.hasOwnProperty('length'));
+ assertEquals(0, f.length);
+
+ assertTrue(delete Function.prototype.length);
+ assertEquals(undefined, f.length);
+})();
« 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