Commit 86863683 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[interpreter] When generating bytecode, properly track current scope.

The bytecode generator did not necessarily know for which scope, and
thus language mode, it was generating code, because it only tracked
scopes that have a context.  This led to wrong behavior in some
examples involving class expressions (which are always in strict
mode).

With this CL, the bytecode generator explicitly tracks the current
scope, independent of whether it has a context.

BUG=v8:5927

Change-Id: Ifa6b3ee5e13e07b63d00e74c7f557a328633c88b
Reviewed-on: https://chromium-review.googlesource.com/444785
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43300}
parent 3f8fc8cc
......@@ -281,10 +281,7 @@ void AstNumberingVisitor::VisitBlock(Block* node) {
IncrementNodeCount();
node->set_base_id(ReserveIdRange(Block::num_ids()));
Scope* scope = node->scope();
DCHECK(scope == nullptr || !scope->HasBeenRemoved());
// TODO(ishell): remove scope->NeedsContext() condition once v8:5927 is fixed.
// Current logic mimics what BytecodeGenerator::VisitBlock() does.
if (scope != nullptr && scope->NeedsContext()) {
if (scope != nullptr) {
LanguageModeScope language_mode_scope(this, scope->language_mode());
VisitStatementsAndDeclarations(node);
} else {
......
This diff is collapsed.
......@@ -44,6 +44,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
class ControlScopeForTopLevel;
class ControlScopeForTryCatch;
class ControlScopeForTryFinally;
class CurrentScope;
class ExpressionResultScope;
class EffectResultScope;
class GlobalDeclarationsBuilder;
......@@ -172,9 +173,12 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
inline BytecodeArrayBuilder* builder() const { return builder_; }
inline Zone* zone() const { return zone_; }
inline DeclarationScope* scope() const { return scope_; }
inline DeclarationScope* closure_scope() const { return closure_scope_; }
inline CompilationInfo* info() const { return info_; }
inline Scope* current_scope() const { return current_scope_; }
inline void set_current_scope(Scope* scope) { current_scope_ = scope; }
inline ControlScope* execution_control() const { return execution_control_; }
inline void set_execution_control(ControlScope* scope) {
execution_control_ = scope;
......@@ -204,7 +208,8 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
Zone* zone_;
BytecodeArrayBuilder* builder_;
CompilationInfo* info_;
DeclarationScope* scope_;
DeclarationScope* closure_scope_;
Scope* current_scope_;
GlobalDeclarationsBuilder* globals_builder_;
ZoneVector<GlobalDeclarationsBuilder*> global_declarations_;
......
// Copyright 2017 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.
let a = Object.freeze({});
assertThrows(() => class C {[a.b = "foo"]() {}}, TypeError);
assertThrows(() => class C extends (a.c = null) {}, TypeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment