Commit 5f90a6eb authored by yangguo's avatar yangguo Committed by Commit bot

[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}
parent f4ba786d
...@@ -8350,16 +8350,14 @@ class V8_EXPORT Context { ...@@ -8350,16 +8350,14 @@ class V8_EXPORT Context {
Isolate* GetIsolate(); Isolate* GetIsolate();
/** /**
* The field at kDebugIdIndex is reserved for V8 debugger implementation. * The field at kDebugIdIndex used to be reserved for the inspector.
* The value is propagated to the scripts compiled in given Context and * It now serves no purpose.
* can be used for filtering scripts.
*/ */
enum EmbedderDataFields { kDebugIdIndex = 0 }; enum EmbedderDataFields { kDebugIdIndex = 0 };
/** /**
* Gets the embedder data with the given index, which must have been set by a * Gets the embedder data with the given index, which must have been set by a
* previous call to SetEmbedderData with the same index. Note that index 0 * previous call to SetEmbedderData with the same index.
* currently has a special meaning for Chrome's debugger.
*/ */
V8_INLINE Local<Value> GetEmbedderData(int index); V8_INLINE Local<Value> GetEmbedderData(int index);
......
...@@ -9139,6 +9139,15 @@ MaybeLocal<Array> Debug::GetInternalProperties(Isolate* v8_isolate, ...@@ -9139,6 +9139,15 @@ MaybeLocal<Array> Debug::GetInternalProperties(Isolate* v8_isolate,
return debug::GetInternalProperties(v8_isolate, value); return debug::GetInternalProperties(v8_isolate, value);
} }
void debug::SetContextId(Local<Context> context, int id) {
Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(id));
}
int debug::GetContextId(Local<Context> context) {
i::Object* value = Utils::OpenHandle(*context)->debug_context_id();
return (value->IsSmi()) ? i::Smi::cast(value)->value() : 0;
}
Local<Context> debug::GetDebugContext(Isolate* isolate) { Local<Context> debug::GetDebugContext(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8(i_isolate); ENTER_V8(i_isolate);
......
...@@ -240,6 +240,7 @@ enum ContextLookupFlags { ...@@ -240,6 +240,7 @@ enum ContextLookupFlags {
V(DATA_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, data_property_descriptor_map) \ V(DATA_PROPERTY_DESCRIPTOR_MAP_INDEX, Map, data_property_descriptor_map) \
V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \ V(DATA_VIEW_FUN_INDEX, JSFunction, data_view_fun) \
V(DATE_FUNCTION_INDEX, JSFunction, date_function) \ V(DATE_FUNCTION_INDEX, JSFunction, date_function) \
V(DEBUG_CONTEXT_ID_INDEX, Object, debug_context_id) \
V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \ V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \
error_message_for_code_gen_from_strings) \ error_message_for_code_gen_from_strings) \
V(ERRORS_THROWN_INDEX, Smi, errors_thrown) \ V(ERRORS_THROWN_INDEX, Smi, errors_thrown) \
......
...@@ -642,8 +642,6 @@ class ModuleEmbedderData { ...@@ -642,8 +642,6 @@ class ModuleEmbedderData {
}; };
enum { enum {
// The debugger reserves the first slot in the Context embedder data.
kDebugIdIndex = Context::kDebugIdIndex,
kModuleEmbedderDataIndex, kModuleEmbedderDataIndex,
kInspectorClientIndex kInspectorClientIndex
}; };
......
...@@ -25,6 +25,9 @@ class Script; ...@@ -25,6 +25,9 @@ class Script;
namespace debug { namespace debug {
void SetContextId(Local<Context> context, int id);
int GetContextId(Local<Context> context);
/** /**
* Debugger is running in its own context which is entered while debugger * Debugger is running in its own context which is entered while debugger
* messages are being dispatched. This is an explicit getter for this * messages are being dispatched. This is an explicit getter for this
......
...@@ -2066,8 +2066,7 @@ void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id, ...@@ -2066,8 +2066,7 @@ void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id,
void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) {
// Attach the correct debug id to the script. The debug id is used by the // Attach the correct debug id to the script. The debug id is used by the
// inspector to filter scripts by native context. // inspector to filter scripts by native context.
FixedArray* array = isolate_->native_context()->embedder_data(); script->set_context_data(isolate_->native_context()->debug_context_id());
script->set_context_data(array->get(v8::Context::kDebugIdIndex));
if (ignore_events()) return; if (ignore_events()) return;
if (!script->IsUserJavaScript() && script->type() != i::Script::TYPE_WASM) { if (!script->IsUserJavaScript() && script->type() != i::Script::TYPE_WASM) {
return; return;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "src/inspector/inspected-context.h" #include "src/inspector/inspected-context.h"
#include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h" #include "src/inspector/injected-script.h"
#include "src/inspector/string-util.h" #include "src/inspector/string-util.h"
#include "src/inspector/v8-console.h" #include "src/inspector/v8-console.h"
...@@ -25,8 +26,7 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector, ...@@ -25,8 +26,7 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
m_auxData(toString16(info.auxData)), m_auxData(toString16(info.auxData)),
m_reported(false) { m_reported(false) {
v8::Isolate* isolate = m_inspector->isolate(); v8::Isolate* isolate = m_inspector->isolate();
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex), v8::debug::SetContextId(info.context, contextId);
v8::Int32::New(isolate, contextId));
v8::Local<v8::Object> global = info.context->Global(); v8::Local<v8::Object> global = info.context->Global();
v8::Local<v8::Object> console = v8::Local<v8::Object> console =
m_inspector->console()->createConsole(info.context); m_inspector->console()->createConsole(info.context);
...@@ -46,10 +46,7 @@ InspectedContext::~InspectedContext() { ...@@ -46,10 +46,7 @@ InspectedContext::~InspectedContext() {
// static // static
int InspectedContext::contextId(v8::Local<v8::Context> context) { int InspectedContext::contextId(v8::Local<v8::Context> context) {
v8::Local<v8::Value> data = return v8::debug::GetContextId(context);
context->GetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex));
if (data.IsEmpty() || !data->IsInt32()) return 0;
return static_cast<int>(data.As<v8::Int32>()->Value());
} }
v8::Local<v8::Context> InspectedContext::context() const { v8::Local<v8::Context> InspectedContext::context() const {
......
...@@ -111,8 +111,7 @@ RUNTIME_FUNCTION(Runtime_FunctionGetContextData) { ...@@ -111,8 +111,7 @@ RUNTIME_FUNCTION(Runtime_FunctionGetContextData) {
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_CHECKED(JSFunction, fun, 0); CONVERT_ARG_CHECKED(JSFunction, fun, 0);
FixedArray* array = fun->native_context()->embedder_data(); return fun->native_context()->debug_context_id();
return array->get(v8::Context::kDebugIdIndex);
} }
RUNTIME_FUNCTION(Runtime_FunctionSetInstanceClassName) { RUNTIME_FUNCTION(Runtime_FunctionSetInstanceClassName) {
......
...@@ -135,8 +135,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate, ...@@ -135,8 +135,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
const ModuleWireBytes& wire_bytes) { const ModuleWireBytes& wire_bytes) {
Handle<Script> script = Handle<Script> script =
isolate->factory()->NewScript(isolate->factory()->empty_string()); isolate->factory()->NewScript(isolate->factory()->empty_string());
FixedArray* array = isolate->native_context()->embedder_data(); script->set_context_data(isolate->native_context()->debug_context_id());
script->set_context_data(array->get(v8::Context::kDebugIdIndex));
script->set_type(Script::TYPE_WASM); script->set_type(Script::TYPE_WASM);
int hash = StringHasher::HashSequentialString( int hash = StringHasher::HashSequentialString(
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
namespace { namespace {
const int kInspectorClientIndex = v8::Context::kDebugIdIndex + 1; const int kInspectorClientIndex = 0;
class ChannelImpl final : public v8_inspector::V8Inspector::Channel { class ChannelImpl final : public v8_inspector::V8Inspector::Channel {
public: public:
......
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