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