v8/test/mjsunit/strong/classes.js
conradw c983689d39 [strong] Implement static restrictions on direct eval
Does not entirely disallow the use of 'eval' as an identifier in strong mode,
as originally proposed.

BUG=v8:3956
LOG=N

Review URL: https://codereview.chromium.org/1059273004

Cr-Commit-Position: refs/heads/master@{#27796}
2015-04-13 17:25:15 +00:00

63 lines
2.0 KiB
JavaScript

// 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
// Flags: --harmony-classes --harmony-arrow-functions
'use strong';
class C {}
let indirect_eval = eval;
function assertTypeError(script) { assertThrows(script, TypeError) }
function assertSyntaxError(script) { assertThrows(script, SyntaxError) }
function assertReferenceError(script) { assertThrows(script, ReferenceError) }
(function ImmutableClassBindings() {
class D {}
assertTypeError(function(){ indirect_eval("C = 0") });
assertEquals('function', typeof C);
assertEquals('function', typeof D);
assertTypeError("'use strong'; (function f() {class E {}; E = 0})()");
})();
function constructor(body) {
return "'use strong'; " +
"(class extends Object { constructor() { " + body + " } })";
}
(function NoMissingSuper() {
assertReferenceError(constructor(""));
assertReferenceError(constructor("1"));
})();
(function NoNestedSuper() {
assertSyntaxError(constructor("(super());"));
assertSyntaxError(constructor("(() => super())();"));
assertSyntaxError(constructor("{ super(); }"));
assertSyntaxError(constructor("if (1) super();"));
})();
(function NoDuplicateSuper() {
assertSyntaxError(constructor("super(), super();"));
assertSyntaxError(constructor("super(); super();"));
assertSyntaxError(constructor("super(); (super());"));
assertSyntaxError(constructor("super(); { super() }"));
assertSyntaxError(constructor("super(); (() => super())();"));
})();
(function NoReturnValue() {
assertSyntaxError(constructor("return {};"));
assertSyntaxError(constructor("return undefined;"));
assertSyntaxError(constructor("{ return {}; }"));
assertSyntaxError(constructor("if (1) return {};"));
})();
(function NoReturnBeforeSuper() {
assertSyntaxError(constructor("return; super();"));
assertSyntaxError(constructor("if (0) return; super();"));
assertSyntaxError(constructor("{ return; } super();"));
})();