Commit e518a2b2 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[debugger] Throw exception if `var x` fails in debug eval

There are cases where DeclareEvalVar can fail to create a variable, in
particular when the declaration scope is not extensible. Throw an error
in such cases.

Fixed: chromium:1145119
Change-Id: I6260f570570c4d7801231bdb5f6724f3734444fd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3295348
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78017}
parent b65810bd
......@@ -321,6 +321,9 @@ namespace internal {
"Invalid property descriptor. Cannot both specify accessors and a value " \
"or writable attribute, %") \
T(VarRedeclaration, "Identifier '%' has already been declared") \
T(VarNotAllowedInEvalScope, \
"Identifier '%' cannot be declared with 'var' in current evaluation " \
"scope, consider trying 'let' instead") \
T(WrongArgs, "%: Arguments list has wrong type") \
/* ReferenceError */ \
T(NotDefined, "% is not defined") \
......
......@@ -11,6 +11,7 @@
#include "src/execution/arguments-inl.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/isolate.h"
#include "src/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop.
#include "src/init/bootstrapper.h"
#include "src/logging/counters.h"
......@@ -295,7 +296,7 @@ Object DeclareEvalHelper(Isolate* isolate, Handle<String> name,
} else if (context->has_extension()) {
object = handle(context->extension_object(), isolate);
DCHECK(object->IsJSContextExtensionObject());
} else {
} else if (context->scope_info().HasContextExtensionSlot()) {
// Sloppy varblock and function contexts might not have an extension object
// yet. Sloppy eval will never have an extension object, as vars are hoisted
// out, and lets are known statically.
......@@ -306,6 +307,10 @@ Object DeclareEvalHelper(Isolate* isolate, Handle<String> name,
isolate->factory()->NewJSObject(isolate->context_extension_function());
context->set_extension(*object);
} else {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewEvalError(MessageTemplate::kVarNotAllowedInEvalScope, name));
}
RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
......
......@@ -83,7 +83,7 @@ bytecodes: [
/* 48 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 53 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 58 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(286),
B(Wide), B(LdaSmi), I16(287),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -115,7 +115,7 @@ bytecodes: [
/* 41 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(285),
B(Wide), B(LdaSmi), I16(286),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -147,7 +147,7 @@ bytecodes: [
/* 48 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 53 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 58 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(286),
B(Wide), B(LdaSmi), I16(287),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -179,7 +179,7 @@ bytecodes: [
/* 41 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(285),
B(Wide), B(LdaSmi), I16(286),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......
......@@ -56,7 +56,7 @@ bytecodes: [
/* 44 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 49 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 54 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(284),
B(Wide), B(LdaSmi), I16(285),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -89,7 +89,7 @@ bytecodes: [
/* 44 E> */ B(StaKeyedPropertyAsDefine), R(this), R(0), U8(0),
/* 49 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 54 E> */ B(LdaKeyedProperty), R(this), U8(2),
B(Wide), B(LdaSmi), I16(284),
B(Wide), B(LdaSmi), I16(285),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......
......@@ -24,7 +24,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(1),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -59,13 +59,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(284),
B(Wide), B(LdaSmi), I16(285),
B(Star3),
B(LdaConstant), U8(1),
B(Star4),
......@@ -97,13 +97,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 61 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(284),
B(Wide), B(LdaSmi), I16(285),
B(Star3),
B(LdaConstant), U8(1),
B(Star4),
......@@ -143,7 +143,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -165,7 +165,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star3),
B(LdaConstant), U8(0),
B(Star4),
......@@ -180,7 +180,7 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star2),
B(LdaConstant), U8(0),
B(Star3),
......@@ -214,13 +214,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(286),
B(Wide), B(LdaSmi), I16(287),
B(Star3),
B(LdaConstant), U8(1),
B(Star4),
......@@ -251,13 +251,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 58 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(285),
B(Wide), B(LdaSmi), I16(286),
B(Star3),
B(LdaConstant), U8(1),
B(Star4),
......@@ -288,13 +288,13 @@ bytecodes: [
B(TestReferenceEqual), R(this),
B(Mov), R(this), R(0),
B(JumpIfTrue), U8(16),
B(Wide), B(LdaSmi), I16(278),
B(Wide), B(LdaSmi), I16(279),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
/* 65 E> */ B(CallRuntime), U16(Runtime::kNewTypeError), R(1), U8(2),
B(Throw),
B(Wide), B(LdaSmi), I16(286),
B(Wide), B(LdaSmi), I16(287),
B(Star3),
B(LdaConstant), U8(1),
B(Star4),
......@@ -323,7 +323,7 @@ bytecode array length: 19
bytecodes: [
/* 46 S> */ B(LdaImmutableCurrentContextSlot), U8(3),
/* 51 E> */ B(LdaKeyedProperty), R(this), U8(0),
B(Wide), B(LdaSmi), I16(285),
B(Wide), B(LdaSmi), I16(286),
B(Star1),
B(LdaConstant), U8(0),
B(Star2),
......
// Copyright 2021 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.
var Debug = debug.Debug;
let exception = null;
function listener(event, execState, eventData, data) {
if (event != Debug.DebugEvent.Break) return;
try {
execState.frame().evaluate("var a = 1").value();
} catch (e) {
exception = e;
}
}
Debug.setListener(listener);
function foo(arg) {
return function() {
// Context allocate arg.
arg;
debugger;
}
}
foo()();
assertNotNull(exception);
assertContains(
"Identifier 'a' cannot be declared with 'var' in current evaluation scope",
exception.message);
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