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

Side by Side Diff: test/mjsunit/strong/functions.js

Issue 954693003: [strong] Make functions and generators non-extensible non-constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/contexts.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --strong-mode 5 // Flags: --strong-mode
6 6
7 'use strong'; 7 'use strong';
8 8
9 function f() {}
10 function* g() {}
11
9 (function NoArguments() { 12 (function NoArguments() {
10 assertThrows("'use strong'; arguments", SyntaxError); 13 assertThrows("'use strong'; arguments", SyntaxError);
11 assertThrows("'use strong'; function f() { arguments }", SyntaxError); 14 assertThrows("'use strong'; function f() { arguments }", SyntaxError);
15 assertThrows("'use strong'; function* g() { arguments }", SyntaxError);
12 assertThrows("'use strong'; let f = function() { arguments }", SyntaxError); 16 assertThrows("'use strong'; let f = function() { arguments }", SyntaxError);
17 assertThrows("'use strong'; let g = function*() { arguments }", SyntaxError);
13 assertThrows("'use strong'; let f = () => arguments", SyntaxError); 18 assertThrows("'use strong'; let f = () => arguments", SyntaxError);
14 // The following are strict mode errors already. 19 // The following are strict mode errors already.
15 assertThrows("'use strong'; let arguments", SyntaxError); 20 assertThrows("'use strong'; let arguments", SyntaxError);
16 assertThrows("'use strong'; function f(arguments) {}", SyntaxError); 21 assertThrows("'use strong'; function f(arguments) {}", SyntaxError);
22 assertThrows("'use strong'; function* g(arguments) {}", SyntaxError);
17 assertThrows("'use strong'; let f = (arguments) => {}", SyntaxError); 23 assertThrows("'use strong'; let f = (arguments) => {}", SyntaxError);
18 })(); 24 })();
19 25
20 function g() {} 26 (function NoArgumentsProperty() {
27 assertFalse(f.hasOwnProperty("arguments"));
28 assertFalse(g.hasOwnProperty("arguments"));
29 assertThrows(function(){ f.arguments = 0 }, TypeError);
30 assertThrows(function(){ g.arguments = 0 }, TypeError);
31 })();
21 32
22 (function LexicalFunctionBindings(global) { 33 (function NoCaller() {
34 assertFalse(f.hasOwnProperty("caller"));
35 assertFalse(g.hasOwnProperty("caller"));
36 assertThrows(function(){ f.caller = 0 }, TypeError);
37 assertThrows(function(){ g.caller = 0 }, TypeError);
38 })();
39
40 (function NoCallee() {
41 assertFalse("callee" in f);
42 assertFalse("callee" in g);
43 assertThrows(function(){ f.callee = 0 }, TypeError);
44 assertThrows(function(){ g.callee = 0 }, TypeError);
45 })();
46
47 (function LexicalBindings(global) {
48 assertEquals('function', typeof f);
23 assertEquals('function', typeof g); 49 assertEquals('function', typeof g);
50 assertEquals(undefined, global.f);
24 assertEquals(undefined, global.g); 51 assertEquals(undefined, global.g);
25 })(this); 52 })(this);
26 53
27 (function ImmutableFunctionBindings() { 54 (function ImmutableBindings() {
28 function f() {} 55 function f2() {}
29 assertThrows(function(){ eval("g = 0") }, TypeError); 56 function* g2() {}
30 assertThrows(function(){ eval("f = 0") }, TypeError); 57 assertThrows(function(){ f = 0 }, TypeError);
58 assertThrows(function(){ g = 0 }, TypeError);
59 assertThrows(function(){ f2 = 0 }, TypeError);
60 assertThrows(function(){ g2 = 0 }, TypeError);
61 assertEquals('function', typeof f);
31 assertEquals('function', typeof g); 62 assertEquals('function', typeof g);
32 assertEquals('function', typeof f); 63 assertEquals('function', typeof f2);
64 assertEquals('function', typeof g2);
33 })(); 65 })();
66
67 (function NonExtensible() {
68 assertThrows(function(){ f.a = 0 }, TypeError);
69 assertThrows(function(){ g.a = 0 }, TypeError);
70 assertThrows(function(){ Object.defineProperty(f, "a", {value: 0}) }, TypeErro r);
71 assertThrows(function(){ Object.defineProperty(g, "a", {value: 0}) }, TypeErro r);
72 assertThrows(function(){ Object.setPrototypeOf(f, {}) }, TypeError);
73 assertThrows(function(){ Object.setPrototypeOf(g, {}) }, TypeError);
74 })();
75
76 (function NoPrototype() {
77 assertFalse("prototype" in f);
78 assertFalse(g.hasOwnProperty("prototype"));
79 assertThrows(function(){ f.prototype = 0 }, TypeError);
80 assertThrows(function(){ g.prototype = 0 }, TypeError);
81 assertThrows(function(){ f.prototype.a = 0 }, TypeError);
82 })();
83
84 (function NonConstructor() {
85 assertThrows(function(){ new f }, TypeError);
86 assertThrows(function(){ new g }, TypeError);
87 })();
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698