summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/strong/functions.js
blob: 6956462e5d5edcc45d17a92a83c929dba5eface5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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.

// Flags: --strong-mode

'use strong';

function f() {}
function* g() {}

(function NoArguments() {
  assertThrows("'use strong'; arguments", SyntaxError);
  assertThrows("'use strong'; function f() { arguments }", SyntaxError);
  assertThrows("'use strong'; function* g() { arguments }", SyntaxError);
  assertThrows("'use strong'; let f = function() { arguments }", SyntaxError);
  assertThrows("'use strong'; let g = function*() { arguments }", SyntaxError);
  assertThrows("'use strong'; let f = () => arguments", SyntaxError);
  // The following are strict mode errors already.
  assertThrows("'use strong'; let arguments", SyntaxError);
  assertThrows("'use strong'; function f(arguments) {}", SyntaxError);
  assertThrows("'use strong'; function* g(arguments) {}", SyntaxError);
  assertThrows("'use strong'; let f = (arguments) => {}", SyntaxError);
})();

(function NoArgumentsProperty() {
  assertFalse(f.hasOwnProperty("arguments"));
  assertFalse(g.hasOwnProperty("arguments"));
  assertThrows(function(){ f.arguments = 0 }, TypeError);
  assertThrows(function(){ g.arguments = 0 }, TypeError);
})();

(function NoCaller() {
  assertFalse(f.hasOwnProperty("caller"));
  assertFalse(g.hasOwnProperty("caller"));
  assertThrows(function(){ f.caller = 0 }, TypeError);
  assertThrows(function(){ g.caller = 0 }, TypeError);
})();

(function NoCallee() {
  assertFalse("callee" in f);
  assertFalse("callee" in g);
  assertThrows(function(){ f.callee = 0 }, TypeError);
  assertThrows(function(){ g.callee = 0 }, TypeError);
})();

(function LexicalBindings(global) {
  assertEquals('function', typeof f);
  assertEquals('function', typeof g);
  assertEquals(undefined, global.f);
  assertEquals(undefined, global.g);
})(this);

(function ImmutableBindings() {
  function f2() {}
  function* g2() {}
  assertThrows(function(){ f = 0 }, TypeError);
  assertThrows(function(){ g = 0 }, TypeError);
  assertThrows(function(){ f2 = 0 }, TypeError);
  assertThrows(function(){ g2 = 0 }, TypeError);
  assertEquals('function', typeof f);
  assertEquals('function', typeof g);
  assertEquals('function', typeof f2);
  assertEquals('function', typeof g2);
})();

(function NonExtensible() {
  assertThrows(function(){ f.a = 0 }, TypeError);
  assertThrows(function(){ g.a = 0 }, TypeError);
  assertThrows(function(){ Object.defineProperty(f, "a", {value: 0}) }, TypeError);
  assertThrows(function(){ Object.defineProperty(g, "a", {value: 0}) }, TypeError);
  assertThrows(function(){ Object.setPrototypeOf(f, {}) }, TypeError);
  assertThrows(function(){ Object.setPrototypeOf(g, {}) }, TypeError);
})();

(function NoPrototype() {
  assertFalse("prototype" in f);
  assertFalse(g.hasOwnProperty("prototype"));
  assertThrows(function(){ f.prototype = 0 }, TypeError);
  assertThrows(function(){ g.prototype = 0 }, TypeError);
  assertThrows(function(){ f.prototype.a = 0 }, TypeError);
})();

(function NonConstructor() {
  assertThrows(function(){ new f }, TypeError);
  assertThrows(function(){ new g }, TypeError);
})();