4ca9d843f8
Previously, the class fields initializer function was stored on a synthetic context allocated variable. This approach had sevaral problems: - We didn't know that class literal had fields until after we had completely parsed the class literal. This meant that we had to go back and fix up the scope of the constructor to have this synthetic variable. This resulted in mismatch between parser and preparsed scope data. - This synthetic variable could potentially resolve to an initializer of an outer class. For ex: class X extends Object { c = 1; constructor() { var t = () => { class P extends Object { constructor() { var t = () => { super(); }; t(); } } super(); } t(); } } In this the inner class P could access the outer class X's initiliazer function. We would have to maintain extra metadata to make sure this doesn't happen. Instead this new approach uses a private symbol to store the initializer function on the class constructor itself. For the base constructor case, we can simply check for a bit on the constructor function literal to see if we need to emit code that loads and calls this initializer function. Therefore, we don't pay the cost of loading this function in case there are no class fields. For the derived constructor case, there are two possiblities: (a) We are in a super() call directly in the derived constructor: In this case we can do a check similar to the base constructor check, we can check for a bit on the derived constructor and emit code for loading and calling the initializer function. This is usually the common case and we don't pay any cost for not using class fields. (b) We are in a super() call inside an arrow function in the derived constructor: In this case, we /always/ emit code to load and call the initializer function. If the function doesn't exist then we have undefined and we don't call anything. Otherwise we call the function. super() can't be called twice so even if we emit code to load and call the initializer function multiple times, it doesn't matter because it would have already been an error. Bug: v8:5367 Change-Id: I7f77cd6493ff84cf0e430a8c1039bc9ac6941a88 Reviewed-on: https://chromium-review.googlesource.com/781660 Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Reviewed-by: Mythri Alle <mythria@chromium.org> Cr-Commit-Position: refs/heads/master@{#49628}
178 lines
4.3 KiB
Plaintext
178 lines
4.3 KiB
Plaintext
#
|
|
# Autogenerated by generate-bytecode-expectations.
|
|
#
|
|
|
|
---
|
|
wrap: no
|
|
test function name: test
|
|
|
|
---
|
|
snippet: "
|
|
var test;
|
|
(function() {
|
|
class A {
|
|
method() { return 2; }
|
|
}
|
|
class B extends A {
|
|
method() { return super.method() + 1; }
|
|
}
|
|
test = new B().method;
|
|
test();
|
|
})();
|
|
"
|
|
frame size: 6
|
|
parameter count: 1
|
|
bytecode array length: 34
|
|
bytecodes: [
|
|
B(Mov), R(closure), R(0),
|
|
/* 99 E> */ B(StackCheck),
|
|
/* 104 S> */ B(LdaConstant), U8(0),
|
|
/* 111 E> */ B(LdaKeyedProperty), R(closure), U8(1),
|
|
B(Star), R(4),
|
|
B(LdaConstant), U8(1),
|
|
B(Star), R(5),
|
|
B(Mov), R(this), R(3),
|
|
/* 117 E> */ B(CallRuntime), U16(Runtime::kLoadFromSuper), R(3), U8(3),
|
|
B(Star), R(1),
|
|
/* 117 E> */ B(CallAnyReceiver), R(1), R(this), U8(1), U8(3),
|
|
/* 126 E> */ B(AddSmi), I8(1), U8(0),
|
|
/* 130 S> */ B(Return),
|
|
]
|
|
constant pool: [
|
|
SYMBOL_TYPE,
|
|
ONE_BYTE_INTERNALIZED_STRING_TYPE ["method"],
|
|
]
|
|
handlers: [
|
|
]
|
|
|
|
---
|
|
snippet: "
|
|
var test;
|
|
(function() {
|
|
class A {
|
|
get x() { return 1; }
|
|
set x(val) { return; }
|
|
}
|
|
class B extends A {
|
|
method() { super.x = 2; return super.x; }
|
|
}
|
|
test = new B().method;
|
|
test();
|
|
})();
|
|
"
|
|
frame size: 5
|
|
parameter count: 1
|
|
bytecode array length: 47
|
|
bytecodes: [
|
|
B(Mov), R(closure), R(0),
|
|
/* 125 E> */ B(StackCheck),
|
|
/* 130 S> */ B(LdaConstant), U8(0),
|
|
/* 130 E> */ B(LdaKeyedProperty), R(closure), U8(0),
|
|
B(Star), R(2),
|
|
B(LdaConstant), U8(1),
|
|
B(Star), R(3),
|
|
B(LdaSmi), I8(2),
|
|
B(Star), R(4),
|
|
B(Mov), R(this), R(1),
|
|
/* 138 E> */ B(CallRuntime), U16(Runtime::kStoreToSuper_Strict), R(1), U8(4),
|
|
/* 143 S> */ B(LdaConstant), U8(0),
|
|
/* 150 E> */ B(LdaKeyedProperty), R(closure), U8(2),
|
|
B(Star), R(2),
|
|
B(LdaConstant), U8(1),
|
|
B(Star), R(3),
|
|
B(Mov), R(this), R(1),
|
|
/* 156 E> */ B(CallRuntime), U16(Runtime::kLoadFromSuper), R(1), U8(3),
|
|
/* 158 S> */ B(Return),
|
|
]
|
|
constant pool: [
|
|
SYMBOL_TYPE,
|
|
ONE_BYTE_INTERNALIZED_STRING_TYPE ["x"],
|
|
]
|
|
handlers: [
|
|
]
|
|
|
|
---
|
|
snippet: "
|
|
var test;
|
|
(function() {
|
|
class A {
|
|
constructor(x) { this.x_ = x; }
|
|
}
|
|
class B extends A {
|
|
constructor() { super(1); this.y_ = 2; }
|
|
}
|
|
test = new B().constructor;
|
|
})();
|
|
"
|
|
frame size: 5
|
|
parameter count: 1
|
|
bytecode array length: 40
|
|
bytecodes: [
|
|
B(Mov), R(closure), R(1),
|
|
/* 113 E> */ B(StackCheck),
|
|
/* 118 S> */ B(Ldar), R(1),
|
|
B(GetSuperConstructor), R(3),
|
|
B(LdaSmi), I8(1),
|
|
B(Star), R(4),
|
|
B(Ldar), R(0),
|
|
/* 118 E> */ B(Construct), R(3), R(4), U8(1), U8(0),
|
|
B(Star), R(2),
|
|
B(Ldar), R(this),
|
|
/* 118 E> */ B(ThrowSuperAlreadyCalledIfNotHole),
|
|
B(Mov), R(2), R(this),
|
|
/* 128 S> */ B(Ldar), R(this),
|
|
B(ThrowSuperNotCalledIfHole),
|
|
B(LdaSmi), I8(2),
|
|
/* 136 E> */ B(StaNamedProperty), R(2), U8(0), U8(2),
|
|
B(Ldar), R(this),
|
|
B(ThrowSuperNotCalledIfHole),
|
|
/* 141 S> */ B(Return),
|
|
]
|
|
constant pool: [
|
|
ONE_BYTE_INTERNALIZED_STRING_TYPE ["y_"],
|
|
]
|
|
handlers: [
|
|
]
|
|
|
|
---
|
|
snippet: "
|
|
var test;
|
|
(function() {
|
|
class A {
|
|
constructor() { this.x_ = 1; }
|
|
}
|
|
class B extends A {
|
|
constructor() { super(); this.y_ = 2; }
|
|
}
|
|
test = new B().constructor;
|
|
})();
|
|
"
|
|
frame size: 4
|
|
parameter count: 1
|
|
bytecode array length: 36
|
|
bytecodes: [
|
|
B(Mov), R(closure), R(1),
|
|
/* 112 E> */ B(StackCheck),
|
|
/* 117 S> */ B(Ldar), R(1),
|
|
B(GetSuperConstructor), R(3),
|
|
B(Ldar), R(0),
|
|
/* 117 E> */ B(Construct), R(3), R(0), U8(0), U8(0),
|
|
B(Star), R(2),
|
|
B(Ldar), R(this),
|
|
/* 117 E> */ B(ThrowSuperAlreadyCalledIfNotHole),
|
|
B(Mov), R(2), R(this),
|
|
/* 126 S> */ B(Ldar), R(this),
|
|
B(ThrowSuperNotCalledIfHole),
|
|
B(LdaSmi), I8(2),
|
|
/* 134 E> */ B(StaNamedProperty), R(2), U8(0), U8(2),
|
|
B(Ldar), R(this),
|
|
B(ThrowSuperNotCalledIfHole),
|
|
/* 139 S> */ B(Return),
|
|
]
|
|
constant pool: [
|
|
ONE_BYTE_INTERNALIZED_STRING_TYPE ["y_"],
|
|
]
|
|
handlers: [
|
|
]
|
|
|