v8/test/mjsunit/stack-traces-class-fields.js
Joyee Cheung 6c3d784c16 Rename fields to names or members
Rename variables and flag names so that the classes can be reused
by private methods implementation.

In particular:

Rename "fields" to "members" in the initializer so that we can
initialize both fields and private methods/accessors there,
for example:

instance_fields_initializer -> instance_members_initializer
InitializeClassFieldsStatement -> InitializeClassMembersStatement

Rename "private field" to "private name" for the private symbols
used to implement private fields so that we can use them to
store private methods/accessors later as well, for example:

private_field_name_var -> private_name_var
NewPrivateFieldSymbol -> NewPrivateNameSymbol

The follow-on is in
https://chromium-review.googlesource.com/c/v8/v8/+/1301018

The design doc is in
https://docs.google.com/document/d/1T-Ql6HOIH2U_8YjWkwK2rTfywwb7b3Qe8d3jkz72KwA/edit?usp=sharing

Bug: v8:8330
Change-Id: I1cdca8def711da879b6e4d67c5ff0a5a4a36abbe
Reviewed-on: https://chromium-review.googlesource.com/c/1312597
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/master@{#57289}
2018-11-06 16:04:08 +00:00

247 lines
4.8 KiB
JavaScript

// Copyright 2018 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: --harmony-class-fields
// Utility function for testing that the expected strings occur
// in the stack trace produced when running the given function.
function testTrace(name, fun, expected, unexpected) {
var threw = false;
try {
fun();
} catch (e) {
for (var i = 0; i < expected.length; i++) {
assertTrue(
e.stack.indexOf(expected[i]) != -1,
name + " doesn't contain expected[" + i + "] stack = " + e.stack
);
}
if (unexpected) {
for (var i = 0; i < unexpected.length; i++) {
assertEquals(
e.stack.indexOf(unexpected[i]),
-1,
name + " contains unexpected[" + i + "]"
);
}
}
threw = true;
}
assertTrue(threw, name + " didn't throw");
}
function thrower() {
FAIL;
}
function testClassConstruction() {
class X {
static x = thrower();
}
}
// ReferenceError: FAIL is not defined
// at thrower
// at <static_fields_initializer>
// at testClassConstruction
// at testTrace
testTrace(
"during class construction",
testClassConstruction,
["thrower", "<static_fields_initializer>"],
["anonymous"]
);
function testClassConstruction2() {
class X {
[thrower()];
}
}
// ReferenceError: FAIL is not defined
// at thrower
// at testClassConstruction2
// at testTrace
testTrace("during class construction2", testClassConstruction2, ["thrower"]);
function testClassInstantiation() {
class X {
x = thrower();
}
new X();
}
// ReferenceError: FAIL is not defined
// at thrower
// at X.<instance_members_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace(
"during class instantiation",
testClassInstantiation,
["thrower", "X.<instance_members_initializer>", "new X"],
["anonymous"]
);
function testClassInstantiationWithSuper() {
class Base {}
class X extends Base {
x = thrower();
}
new X();
}
// ReferenceError: FAIL is not defined
// at thrower
// at X.<instance_members_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace(
"during class instantiation with super",
testClassInstantiationWithSuper,
["thrower", "X.<instance_members_initializer>", "new X"],
["Base", "anonymous"]
);
function testClassInstantiationWithSuper2() {
class Base {}
class X extends Base {
constructor() {
super();
}
x = thrower();
}
new X();
}
// ReferenceError: FAIL is not defined
// at thrower
// at X.<instance_members_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace(
"during class instantiation with super2",
testClassInstantiationWithSuper2,
["thrower", "X.<instance_members_initializer>", "new X"],
["Base", "anonymous"]
);
function testClassInstantiationWithSuper3() {
class Base {
x = thrower();
}
class X extends Base {
constructor() {
super();
}
}
new X();
}
// ReferenceError: FAIL is not defined
// at thrower
// at X.<instance_members_initializer>
// at new Base
// at new X
// at testClassInstantiationWithSuper3
// at testTrace
testTrace(
"during class instantiation with super3",
testClassInstantiationWithSuper3,
["thrower", "X.<instance_members_initializer>", "new Base", "new X"],
["anonymous"]
);
function testClassFieldCall() {
class X {
x = thrower;
}
let x = new X();
x.x();
}
// ReferenceError: FAIL is not defined
// at X.thrower [as x]
// at testClassFieldCall
// at testTrace
testTrace(
"during class field call",
testClassFieldCall,
["X.thrower"],
["anonymous"]
);
function testStaticClassFieldCall() {
class X {
static x = thrower;
}
X.x();
}
// ReferenceError: FAIL is not defined
// at Function.thrower [as x]
// at testStaticClassFieldCall
// at testTrace
testTrace(
"during static class field call",
testStaticClassFieldCall,
["Function.thrower"],
["anonymous"]
);
function testClassFieldCallWithFNI() {
class X {
x = function() {
FAIL;
};
}
let x = new X();
x.x();
}
// ReferenceError: FAIL is not defined
// at X.x
// at testClassFieldCallWithFNI
// at testTrace
testTrace(
"during class field call with FNI",
testClassFieldCallWithFNI,
["X.x"],
["anonymous"]
);
function testStaticClassFieldCallWithFNI() {
class X {
static x = function() {
FAIL;
};
}
X.x();
}
// ReferenceError: FAIL is not defined
// at Function.x
// at testStaticClassFieldCallWithFNI
// at testTrace
testTrace(
"during static class field call with FNI",
testStaticClassFieldCallWithFNI,
["Function.x"],
["anonymous"]
);