Rename SloppyBlockWithEvalContextExtension to ContextExtension

The plan is to also use it for With and Catch scopes, so all kinds of
contexts have a pointer back to their ScopeInfo

R=neis@chromium.org,marja@chromium.org
BUG=v8:5215

Review-Url: https://codereview.chromium.org/2301913002
Cr-Commit-Position: refs/heads/master@{#39092}
This commit is contained in:
jochen 2016-09-01 08:03:44 -07:00 committed by Commit bot
parent 69debbb50c
commit 50d54ee2e3
11 changed files with 41 additions and 53 deletions

View File

@ -64,8 +64,8 @@ bool Context::is_declaration_context() {
Object* ext = extension();
// If we have the special extension, we immediately know it must be a
// declaration scope. That's just a small performance shortcut.
return ext->IsSloppyBlockWithEvalContextExtension()
|| ScopeInfo::cast(ext)->is_declaration_scope();
return ext->IsContextExtension() ||
ScopeInfo::cast(ext)->is_declaration_scope();
}
@ -93,8 +93,8 @@ JSObject* Context::extension_object() {
HeapObject* object = extension();
if (object->IsTheHole(GetIsolate())) return nullptr;
if (IsBlockContext()) {
if (!object->IsSloppyBlockWithEvalContextExtension()) return nullptr;
object = SloppyBlockWithEvalContextExtension::cast(object)->extension();
if (!object->IsContextExtension()) return nullptr;
object = JSObject::cast(ContextExtension::cast(object)->extension());
}
DCHECK(object->IsJSContextExtensionObject() ||
(IsNativeContext() && object->IsJSGlobalObject()));
@ -112,9 +112,9 @@ JSReceiver* Context::extension_receiver() {
ScopeInfo* Context::scope_info() {
DCHECK(IsModuleContext() || IsScriptContext() || IsBlockContext());
HeapObject* object = extension();
if (object->IsSloppyBlockWithEvalContextExtension()) {
if (object->IsContextExtension()) {
DCHECK(IsBlockContext());
object = SloppyBlockWithEvalContextExtension::cast(object)->scope_info();
object = ContextExtension::cast(object)->scope_info();
}
return ScopeInfo::cast(object);
}

View File

@ -298,8 +298,8 @@ class ScriptContextTable : public FixedArray {
//
// [ previous ] A pointer to the previous context.
//
// [ extension ] A pointer to an extension JSObject, or "the hole". Used to
// implement 'with' statements and dynamic declarations
// [ extension ] A pointer to a ContextExtension object, or "the hole". Used
// to implement 'with' statements and dynamic declarations
// (through 'eval'). The object in a 'with' statement is
// stored in the extension slot of a 'with' context.
// Dynamically declared variables/functions are also added
@ -308,8 +308,8 @@ class ScriptContextTable : public FixedArray {
// For script and block contexts, contains the respective
// ScopeInfo. For block contexts representing sloppy declaration
// block scopes, it may also be a struct being a
// SloppyBlockWithEvalContextExtension, pairing the ScopeInfo
// with an extension object.
// ContextExtension, pairing the ScopeInfo with an extension
// object.
//
// [ native_context ] A pointer to the native context.
//

View File

@ -102,14 +102,11 @@ Handle<PrototypeInfo> Factory::NewPrototypeInfo() {
return result;
}
Handle<SloppyBlockWithEvalContextExtension>
Factory::NewSloppyBlockWithEvalContextExtension(
Handle<ScopeInfo> scope_info, Handle<JSObject> extension) {
Handle<ContextExtension> Factory::NewContextExtension(
Handle<ScopeInfo> scope_info, Handle<Object> extension) {
DCHECK(scope_info->is_declaration_scope());
Handle<SloppyBlockWithEvalContextExtension> result =
Handle<SloppyBlockWithEvalContextExtension>::cast(
NewStruct(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE));
Handle<ContextExtension> result =
Handle<ContextExtension>::cast(NewStruct(CONTEXT_EXTENSION_TYPE));
result->set_scope_info(*scope_info);
result->set_extension(*extension);
return result;

View File

@ -64,10 +64,9 @@ class Factory final {
// Create a new PrototypeInfo struct.
Handle<PrototypeInfo> NewPrototypeInfo();
// Create a new SloppyBlockWithEvalContextExtension struct.
Handle<SloppyBlockWithEvalContextExtension>
NewSloppyBlockWithEvalContextExtension(Handle<ScopeInfo> scope_info,
Handle<JSObject> extension);
// Create a new ContextExtension struct.
Handle<ContextExtension> NewContextExtension(Handle<ScopeInfo> scope_info,
Handle<Object> extension);
// Create a pre-tenured empty AccessorPair.
Handle<AccessorPair> NewAccessorPair();

View File

@ -911,10 +911,8 @@ void PrototypeInfo::PrototypeInfoVerify() {
CHECK(validity_cell()->IsCell() || validity_cell()->IsSmi());
}
void SloppyBlockWithEvalContextExtension::
SloppyBlockWithEvalContextExtensionVerify() {
CHECK(IsSloppyBlockWithEvalContextExtension());
void ContextExtension::ContextExtensionVerify() {
CHECK(IsContextExtension());
VerifyObjectField(kScopeInfoOffset);
VerifyObjectField(kExtensionOffset);
}

View File

@ -5692,10 +5692,8 @@ ACCESSORS(PrototypeInfo, validity_cell, Object, kValidityCellOffset)
SMI_ACCESSORS(PrototypeInfo, bit_field, kBitFieldOffset)
BOOL_ACCESSORS(PrototypeInfo, bit_field, should_be_fast_map, kShouldBeFastBit)
ACCESSORS(SloppyBlockWithEvalContextExtension, scope_info, ScopeInfo,
kScopeInfoOffset)
ACCESSORS(SloppyBlockWithEvalContextExtension, extension, JSObject,
kExtensionOffset)
ACCESSORS(ContextExtension, scope_info, ScopeInfo, kScopeInfoOffset)
ACCESSORS(ContextExtension, extension, Object, kExtensionOffset)
ACCESSORS(AccessorPair, getter, Object, kGetterOffset)
ACCESSORS(AccessorPair, setter, Object, kSetterOffset)

View File

@ -1136,10 +1136,8 @@ void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
os << "\n";
}
void SloppyBlockWithEvalContextExtension::
SloppyBlockWithEvalContextExtensionPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "SloppyBlockWithEvalContextExtension");
void ContextExtension::ContextExtensionPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "ContextExtension");
os << "\n - scope_info: " << Brief(scope_info());
os << "\n - extension: " << Brief(extension());
os << "\n";

View File

@ -395,7 +395,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
V(BOX_TYPE) \
V(PROTOTYPE_INFO_TYPE) \
V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \
V(CONTEXT_EXTENSION_TYPE) \
\
V(FIXED_ARRAY_TYPE) \
V(FIXED_DOUBLE_ARRAY_TYPE) \
@ -513,9 +513,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(DEBUG_INFO, DebugInfo, debug_info) \
V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \
V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \
V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \
SloppyBlockWithEvalContextExtension, \
sloppy_block_with_eval_context_extension)
V(CONTEXT_EXTENSION, ContextExtension, context_extension)
// We use the full 8 bits of the instance_type field to encode heap object
// instance types. The high-order bit (bit 7) is set if the object is not a
@ -689,7 +687,7 @@ enum InstanceType {
TRANSITION_ARRAY_TYPE,
PROPERTY_CELL_TYPE,
PROTOTYPE_INFO_TYPE,
SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE,
CONTEXT_EXTENSION_TYPE,
// All the following types are subtypes of JSReceiver, which corresponds to
// objects in the JS sense. The first and the last type in this range are
@ -6653,28 +6651,29 @@ class PrototypeInfo : public Struct {
// Pair used to store both a ScopeInfo and an extension object in the extension
// slot of a block context. Needed in the rare case where a declaration block
// scope (a "varblock" as used to desugar parameter destructuring) also contains
// a sloppy direct eval. (In no other case both are needed at the same time.)
class SloppyBlockWithEvalContextExtension : public Struct {
// slot of a block, catch, or with context. Needed in the rare case where a
// declaration block scope (a "varblock" as used to desugar parameter
// destructuring) also contains a sloppy direct eval, or for with and catch
// scopes. (In no other case both are needed at the same time.)
class ContextExtension : public Struct {
public:
// [scope_info]: Scope info.
DECL_ACCESSORS(scope_info, ScopeInfo)
// [extension]: Extension object.
DECL_ACCESSORS(extension, JSObject)
DECL_ACCESSORS(extension, Object)
DECLARE_CAST(SloppyBlockWithEvalContextExtension)
DECLARE_CAST(ContextExtension)
// Dispatched behavior.
DECLARE_PRINTER(SloppyBlockWithEvalContextExtension)
DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension)
DECLARE_PRINTER(ContextExtension)
DECLARE_VERIFIER(ContextExtension)
static const int kScopeInfoOffset = HeapObject::kHeaderSize;
static const int kExtensionOffset = kScopeInfoOffset + kPointerSize;
static const int kSize = kExtensionOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension);
DISALLOW_IMPLICIT_CONSTRUCTORS(ContextExtension);
};

View File

@ -294,9 +294,8 @@ Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name,
DCHECK(context->IsBlockContext());
object = isolate->factory()->NewJSObject(
isolate->context_extension_function());
Handle<HeapObject> extension =
isolate->factory()->NewSloppyBlockWithEvalContextExtension(
handle(context->scope_info()), object);
Handle<HeapObject> extension = isolate->factory()->NewContextExtension(
handle(context->scope_info()), object);
context->set_extension(*extension);
} else {
object = handle(context->extension_object(), isolate);

View File

@ -278,7 +278,7 @@ Type::bitset BitsetType::Lub(i::Map* map) {
case CELL_TYPE:
case WEAK_CELL_TYPE:
case PROTOTYPE_INFO_TYPE:
case SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE:
case CONTEXT_EXTENSION_TYPE:
UNREACHABLE();
return kNone;
}

View File

@ -89,7 +89,7 @@ INSTANCE_TYPES = {
163: "ALIASED_ARGUMENTS_ENTRY_TYPE",
164: "BOX_TYPE",
173: "PROTOTYPE_INFO_TYPE",
174: "SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE",
174: "CONTEXT_EXTENSION_TYPE",
167: "FIXED_ARRAY_TYPE",
148: "FIXED_DOUBLE_ARRAY_TYPE",
168: "SHARED_FUNCTION_INFO_TYPE",
@ -232,7 +232,7 @@ KNOWN_MAPS = {
0x09231: (165, "DebugInfoMap"),
0x0925d: (166, "BreakPointInfoMap"),
0x09289: (173, "PrototypeInfoMap"),
0x092b5: (174, "SloppyBlockWithEvalContextExtensionMap"),
0x092b5: (174, "ContextExtensionMap"),
}
# List of known V8 objects.