Skip to content

Commit 5f90a6e

Browse files
hashseedCommit bot
authored andcommitted
[debug,api] Do not use embedder field for debug context id.
We used to reserve the 0-th embedder data field for the debug context id. This is no longer necessary since the inspector has migrated to be part of V8. This makes the API a bit simpler. R=clemensh@chromium.org, jochen@chromium.org, kozyatinskiy@chromium.org BUG=v8:5530 Review-Url: https://codereview.chromium.org/2806303002 Cr-Commit-Position: refs/heads/master@{#44607}
1 parent f4ba786 commit 5f90a6e

File tree

10 files changed

+23
-20
lines changed

10 files changed

+23
-20
lines changed

include/v8.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8350,16 +8350,14 @@ class V8_EXPORT Context {
83508350
Isolate* GetIsolate();
83518351

83528352
/**
8353-
* The field at kDebugIdIndex is reserved for V8 debugger implementation.
8354-
* The value is propagated to the scripts compiled in given Context and
8355-
* can be used for filtering scripts.
8353+
* The field at kDebugIdIndex used to be reserved for the inspector.
8354+
* It now serves no purpose.
83568355
*/
83578356
enum EmbedderDataFields { kDebugIdIndex = 0 };
83588357

83598358
/**
83608359
* Gets the embedder data with the given index, which must have been set by a
8361-
* previous call to SetEmbedderData with the same index. Note that index 0
8362-
* currently has a special meaning for Chrome's debugger.
8360+
* previous call to SetEmbedderData with the same index.
83638361
*/
83648362
V8_INLINE Local<Value> GetEmbedderData(int index);
83658363

src/api.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9139,6 +9139,15 @@ MaybeLocal<Array> Debug::GetInternalProperties(Isolate* v8_isolate,
91399139
return debug::GetInternalProperties(v8_isolate, value);
91409140
}
91419141

9142+
void debug::SetContextId(Local<Context> context, int id) {
9143+
Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(id));
9144+
}
9145+
9146+
int debug::GetContextId(Local<Context> context) {
9147+
i::Object* value = Utils::OpenHandle(*context)->debug_context_id();
9148+
return (value->IsSmi()) ? i::Smi::cast(value)->value() : 0;
9149+
}
9150+
91429151
Local<Context> debug::GetDebugContext(Isolate* isolate) {
91439152
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
91449153
ENTER_V8(i_isolate);

src/contexts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ enum ContextLookupFlags {
240240
V(DATA_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, data_property_descriptor_map) \
241241
V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \
242242
V(DATE_FUNCTION_INDEX, JSFunction, date_function) \
243+
V(DEBUG_CONTEXT_ID_INDEX, Object, debug_context_id) \
243244
V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \
244245
error_message_for_code_gen_from_strings) \
245246
V(ERRORS_THROWN_INDEX, Smi, errors_thrown) \

src/d8.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,6 @@ class ModuleEmbedderData {
642642
};
643643

644644
enum {
645-
// The debugger reserves the first slot in the Context embedder data.
646-
kDebugIdIndex = Context::kDebugIdIndex,
647645
kModuleEmbedderDataIndex,
648646
kInspectorClientIndex
649647
};

src/debug/debug-interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Script;
2525

2626
namespace debug {
2727

28+
void SetContextId(Local<Context> context, int id);
29+
int GetContextId(Local<Context> context);
30+
2831
/**
2932
* Debugger is running in its own context which is entered while debugger
3033
* messages are being dispatched. This is an explicit getter for this

src/debug/debug.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,8 +2066,7 @@ void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id,
20662066
void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) {
20672067
// Attach the correct debug id to the script. The debug id is used by the
20682068
// inspector to filter scripts by native context.
2069-
FixedArray* array = isolate_->native_context()->embedder_data();
2070-
script->set_context_data(array->get(v8::Context::kDebugIdIndex));
2069+
script->set_context_data(isolate_->native_context()->debug_context_id());
20712070
if (ignore_events()) return;
20722071
if (!script->IsUserJavaScript() && script->type() != i::Script::TYPE_WASM) {
20732072
return;

src/inspector/inspected-context.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "src/inspector/inspected-context.h"
66

7+
#include "src/debug/debug-interface.h"
78
#include "src/inspector/injected-script.h"
89
#include "src/inspector/string-util.h"
910
#include "src/inspector/v8-console.h"
@@ -25,8 +26,7 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
2526
m_auxData(toString16(info.auxData)),
2627
m_reported(false) {
2728
v8::Isolate* isolate = m_inspector->isolate();
28-
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
29-
v8::Int32::New(isolate, contextId));
29+
v8::debug::SetContextId(info.context, contextId);
3030
v8::Local<v8::Object> global = info.context->Global();
3131
v8::Local<v8::Object> console =
3232
m_inspector->console()->createConsole(info.context);
@@ -46,10 +46,7 @@ InspectedContext::~InspectedContext() {
4646

4747
// static
4848
int InspectedContext::contextId(v8::Local<v8::Context> context) {
49-
v8::Local<v8::Value> data =
50-
context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
51-
if (data.IsEmpty() || !data->IsInt32()) return 0;
52-
return static_cast<int>(data.As<v8::Int32>()->Value());
49+
return v8::debug::GetContextId(context);
5350
}
5451

5552
v8::Local<v8::Context> InspectedContext::context() const {

src/runtime/runtime-function.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ RUNTIME_FUNCTION(Runtime_FunctionGetContextData) {
111111
DCHECK_EQ(1, args.length());
112112

113113
CONVERT_ARG_CHECKED(JSFunction, fun, 0);
114-
FixedArray* array = fun->native_context()->embedder_data();
115-
return array->get(v8::Context::kDebugIdIndex);
114+
return fun->native_context()->debug_context_id();
116115
}
117116

118117
RUNTIME_FUNCTION(Runtime_FunctionSetInstanceClassName) {

src/wasm/wasm-module.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
135135
const ModuleWireBytes& wire_bytes) {
136136
Handle<Script> script =
137137
isolate->factory()->NewScript(isolate->factory()->empty_string());
138-
FixedArray* array = isolate->native_context()->embedder_data();
139-
script->set_context_data(array->get(v8::Context::kDebugIdIndex));
138+
script->set_context_data(isolate->native_context()->debug_context_id());
140139
script->set_type(Script::TYPE_WASM);
141140

142141
int hash = StringHasher::HashSequentialString(

test/inspector/inspector-impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace {
1212

13-
const int kInspectorClientIndex = v8::Context::kDebugIdIndex + 1;
13+
const int kInspectorClientIndex = 0;
1414

1515
class ChannelImpl final : public v8_inspector::V8Inspector::Channel {
1616
public:

0 commit comments

Comments
 (0)