Debian Codegraph @

js/src/tests/test262/language/eval-code/direct/super-call-method.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-performeval
5 description: >
6 SuperCall may may only occur in eval code for direct eval within a
7 constructor method
8 info: |
9 [...]
10 4. Let inMethod be false.
11 5. Let inConstructor be false.
12 6. If thisEnvRec has a [[HomeObject]] field, then
13 a. Let inMethod be true.
14 b. If thisEnvRec.[[FunctionObject]] has a [[Construct]] field, let
15 inConstructor be true.
16 7. Let script be the ECMAScript code that is the result of parsing x,
17 interpreted as UTF-16 encoded Unicode text as described in 6.1.4, for the
18 goal symbol Script. If inMethod is false, additional early error rules
19 from 18.2.1.1.1 are applied. If inConstructor is false, additional early
20 error rules from 18.2.1.1.2 are applied. If the parse fails, throw a
21 SyntaxError exception. If any early errors are detected, throw a
22 SyntaxError or a ReferenceError exception, depending on the type of the
23 error (but see also clause 16). Parsing and early error detection may be
24 interweaved in an implementation dependent manner.
25
26 18.2.1.1.1 Additional Early Error Rules for Eval Outside Methods
27
28 ScriptBody : StatementList
29
30 - It is a Syntax Error if StatementList contains super.
31 features: [super]
32 ---*/
33
34 var evaluatedArg = false;
35 var obj = {
36 method() {
37 // Early errors restricting the usage of SuperCall necessitate the use of
38 // `eval`.
39 eval('super(evaluatedArg = true);');
40 }
41 }
42
43 assert.throws(SyntaxError, function() {
44 obj.method();
45 });
46
47 assert.sameValue(
48 evaluatedArg, false, 'did not perform ArgumentsListEvaluation'
49 );
50
51 reportCompare(0, 0);