Skip to content

Commit b58b51d

Browse files
author
Matheus Marchini
committed
fixup! src: add node's internals constants
1 parent b814884 commit b58b51d

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

src/llnode.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool BacktraceCmd::DoExecute(SBDebugger d, char** cmd,
130130
res.c_str());
131131
continue;
132132
} else {
133-
v8::Error::PrintInDebugMode("%s", err.GetMessage());
133+
Error::PrintInDebugMode("%s", err.GetMessage());
134134
}
135135
}
136136

src/llv8-inl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ inline Value Context::Native(Error& err) {
541541
return FixedArray::Get<Value>(v8()->context()->kNativeIndex, err);
542542
}
543543

544+
inline bool Context::IsNative(Error& err) {
545+
Value native = Native(err);
546+
if (err.Fail()) {
547+
return false;
548+
}
549+
return native.raw() == raw();
550+
}
551+
552+
template <class T>
553+
inline T Context::GetEmbedderData(int64_t index, Error& err) {
554+
FixedArray embedder_data = FixedArray(*this).Get<FixedArray>(
555+
v8()->context()->kEmbedderDataIndex, err);
556+
if (err.Fail()) {
557+
return T();
558+
}
559+
return embedder_data.Get<T>(index, err);
560+
}
561+
544562
inline Value Context::ContextSlot(int index, Error& err) {
545563
return FixedArray::Get<Value>(v8()->context()->kMinContextSlots + index, err);
546564
}

src/llv8.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ class Context : public FixedArray {
384384
inline JSFunction Closure(Error& err);
385385
inline Value Previous(Error& err);
386386
inline Value Native(Error& err);
387+
inline bool IsNative(Error& err);
388+
template <class T>
389+
inline T GetEmbedderData(int64_t index, Error& err);
387390
inline Value ContextSlot(int index, Error& err);
388391

389392
std::string Inspect(Error& err);

src/node-constants.cc

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ addr_t Environment::LoadCurrentEnvironment(Error& err) {
3030
err = Error::Failure("Missing Node's embedder data index");
3131
return 0;
3232
}
33-
addr_t currentEnvironment = 0;
33+
addr_t current_environment = 0;
3434
SBProcess process = target_.GetProcess();
3535
SBThread thread = process.GetSelectedThread();
3636
if (!thread.IsValid()) {
@@ -40,13 +40,6 @@ addr_t Environment::LoadCurrentEnvironment(Error& err) {
4040

4141
llv8()->Load(target_);
4242

43-
SBStream desc;
44-
if (!thread.GetDescription(desc)) {
45-
err = Error::Failure("Couldn't get thread description");
46-
return 0;
47-
}
48-
SBFrame selected_frame = thread.GetSelectedFrame();
49-
5043
uint32_t num_frames = thread.GetNumFrames();
5144

5245
// Heuristically finds the native context and gets the Environment from its
@@ -75,13 +68,10 @@ addr_t Environment::LoadCurrentEnvironment(Error& err) {
7568
}
7669
visited_contexts.insert(val.raw());
7770
v8::Context context(val);
78-
v8::Value native = context.Native(v8_err);
79-
if (v8_err.Success()) {
80-
if (native.raw() == context.raw()) {
81-
found = true;
82-
currentEnvironment = CurrentEnvironmentFromContext(native, err);
83-
break;
84-
}
71+
if (context.IsNative(err)) {
72+
found = true;
73+
current_environment = CurrentEnvironmentFromContext(context, err);
74+
break;
8575
}
8676

8777
val = context.Previous(v8_err);
@@ -95,29 +85,24 @@ addr_t Environment::LoadCurrentEnvironment(Error& err) {
9585
}
9686
}
9787

98-
if (!currentEnvironment) {
88+
if (!current_environment) {
9989
err =
10090
Error::Failure("Couldn't find the Environemnt from the native context");
10191
}
10292

103-
return currentEnvironment;
93+
return current_environment;
10494
}
10595

106-
addr_t Environment::CurrentEnvironmentFromContext(v8::Value context,
96+
addr_t Environment::CurrentEnvironmentFromContext(v8::Context context,
10797
Error& err) {
10898
llv8()->Load(target_);
10999

110-
v8::FixedArray contextArray = v8::FixedArray(context);
111-
v8::FixedArray embed = contextArray.Get<v8::FixedArray>(
112-
llv8()->context()->kEmbedderDataIndex, err);
113-
if (err.Fail()) {
114-
return 0;
115-
}
116-
v8::Smi encodedEnv = embed.Get<v8::Smi>(kEnvContextEmbedderDataIndex, err);
100+
v8::Smi environment =
101+
context.GetEmbedderData<v8::Smi>(kEnvContextEmbedderDataIndex, err);
117102
if (err.Fail()) {
118103
return 0;
119104
}
120-
return encodedEnv.raw();
105+
return environment.raw();
121106
}
122107

123108

src/node-constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Environment : public Module {
4141

4242
private:
4343
addr_t LoadCurrentEnvironment(Error& err);
44-
addr_t CurrentEnvironmentFromContext(v8::Value context, Error& err);
44+
addr_t CurrentEnvironmentFromContext(v8::Context context, Error& err);
4545
};
4646

4747
class ReqWrapQueue : public Module {

0 commit comments

Comments
 (0)