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

Side by Side Diff: test/mjsunit/es6/generators-runtime.js

Issue 1027283004: [es6] do not add caller/arguments to ES6 function definitions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 8 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 | « test/mjsunit/es6/generators-poisoned-properties.js ('k') | test/mjsunit/function-bind.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Test aspects of the generator runtime. 28 // Test aspects of the generator runtime.
29 29
30 // See: 30 // See:
31 // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-ob jects 31 // http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorfunction-ob jects
32 32
33 function f() { } 33 function f() { "use strict"; }
34 function* g() { yield 1; } 34 function* g() { yield 1; }
35 var GeneratorFunctionPrototype = Object.getPrototypeOf(g); 35 var GeneratorFunctionPrototype = Object.getPrototypeOf(g);
36 var GeneratorFunction = GeneratorFunctionPrototype.constructor; 36 var GeneratorFunction = GeneratorFunctionPrototype.constructor;
37 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 37 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
38 38
39 // A generator function should have the same set of properties as any 39 // A generator function should have the same set of properties as any
40 // other function. 40 // other function.
41 function TestGeneratorFunctionInstance() { 41 function TestGeneratorFunctionInstance() {
42 var f_own_property_names = Object.getOwnPropertyNames(f); 42 var f_own_property_names = Object.getOwnPropertyNames(f);
43 var g_own_property_names = Object.getOwnPropertyNames(g); 43 var g_own_property_names = Object.getOwnPropertyNames(g);
44 44
45 f_own_property_names.sort(); 45 f_own_property_names.sort();
46 g_own_property_names.sort(); 46 g_own_property_names.sort();
47 47
48 assertArrayEquals(f_own_property_names, g_own_property_names); 48 assertArrayEquals(f_own_property_names, g_own_property_names);
49 var i; 49 var i;
50 for (i = 0; i < f_own_property_names.length; i++) { 50 for (i = 0; i < f_own_property_names.length; i++) {
51 var prop = f_own_property_names[i]; 51 var prop = f_own_property_names[i];
52 var f_desc = Object.getOwnPropertyDescriptor(f, prop); 52 var f_desc = Object.getOwnPropertyDescriptor(f, prop);
53 var g_desc = Object.getOwnPropertyDescriptor(g, prop); 53 var g_desc = Object.getOwnPropertyDescriptor(g, prop);
54 assertEquals(f_desc.configurable, g_desc.configurable, prop); 54 if (prop === "prototype") {
55 if (prop === 'arguments' || prop === 'caller') { 55 // ES6 draft 03-17-2015 section 25.2.2.2
56 // Unlike sloppy functions, which have read-only data arguments and caller 56 assertFalse(g_desc.writable, prop);
57 // properties, sloppy generators have a poison pill implemented via 57 assertFalse(g_desc.enumerable, prop);
58 // accessors 58 assertFalse(g_desc.configurable, prop);
59 assertFalse('writable' in g_desc, prop);
60 assertTrue(g_desc.get instanceof Function, prop);
61 assertEquals(g_desc.get, g_desc.set, prop);
62 } else { 59 } else {
60 assertEquals(f_desc.configurable, g_desc.configurable, prop);
63 assertEquals(f_desc.writable, g_desc.writable, prop); 61 assertEquals(f_desc.writable, g_desc.writable, prop);
62 assertEquals(f_desc.enumerable, g_desc.enumerable, prop);
64 } 63 }
65 assertEquals(f_desc.enumerable, g_desc.enumerable, prop);
66 } 64 }
67 } 65 }
68 TestGeneratorFunctionInstance(); 66 TestGeneratorFunctionInstance();
69 67
70 68
71 // Generators have an additional object interposed in the chain between 69 // Generators have an additional object interposed in the chain between
72 // themselves and Function.prototype. 70 // themselves and Function.prototype.
73 function TestGeneratorFunctionPrototype() { 71 function TestGeneratorFunctionPrototype() {
74 // Sanity check. 72 // Sanity check.
75 assertSame(Object.getPrototypeOf(f), Function.prototype); 73 assertSame(Object.getPrototypeOf(f), Function.prototype);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 function TestPerGeneratorPrototype() { 151 function TestPerGeneratorPrototype() {
154 assertTrue((function*(){}).prototype !== (function*(){}).prototype); 152 assertTrue((function*(){}).prototype !== (function*(){}).prototype);
155 assertTrue((function*(){}).prototype !== g.prototype); 153 assertTrue((function*(){}).prototype !== g.prototype);
156 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype)); 154 assertSame(GeneratorObjectPrototype, Object.getPrototypeOf(g.prototype));
157 assertTrue(!(g.prototype instanceof Function)); 155 assertTrue(!(g.prototype instanceof Function));
158 assertSame(typeof (g.prototype), "object"); 156 assertSame(typeof (g.prototype), "object");
159 157
160 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype)); 158 assertArrayEquals([], Object.getOwnPropertyNames(g.prototype));
161 } 159 }
162 TestPerGeneratorPrototype(); 160 TestPerGeneratorPrototype();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/generators-poisoned-properties.js ('k') | test/mjsunit/function-bind.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698