Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit c8e6e2f

Browse files
committed
chakrashim: fix inspector evaluate
* Fixed the way that Runtime::evaluate handled and returned exceptions * Fixed Runtime::evaluate to use the global stack frame * Added support for console command line during evaluate calls * Fixed various incorrect function calls in chakrashim PR-URL: #442 Reviewed-By: Jimmy Thomson <jithomso@microsoft.com>
1 parent ffa70ff commit c8e6e2f

17 files changed

+196
-35
lines changed

deps/chakrashim/include/v8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class Local {
351351
friend class PropertyDescriptor;
352352
friend class Proxy;
353353
friend class RegExp;
354+
friend class Set;
354355
friend class Signature;
355356
friend class Script;
356357
friend class StackFrame;

deps/chakrashim/src/inspector/v8-console.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,13 @@ V8Console::CommandLineAPIScope::~CommandLineAPIScope() {
839839
v8::Local<v8::Value> name;
840840
if (!names->Get(m_context, i).ToLocal(&name) || !name->IsName()) continue;
841841
if (name->IsString()) {
842-
v8::Local<v8::Value> descriptor;
843-
bool success = m_global
844-
->GetOwnPropertyDescriptor(
845-
m_context, v8::Local<v8::Name>::Cast(name))
846-
.ToLocal(&descriptor);
842+
// Trigger the accessorGetterCallback to do the delete. This ensures that
843+
// the correct property is being deleted. It's possible (though unlikely)
844+
// that some other code (or the user) has replaced these properties before
845+
// they were able to be cleaned up.
846+
v8::Local<v8::Value> value;
847+
bool success = m_global->Get(m_context, v8::Local<v8::Name>::Cast(name))
848+
.ToLocal(&value);
847849
DCHECK(success);
848850
USE(success);
849851
}

deps/chakrashim/src/inspector/v8-debugger-agent-impl.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
#include <algorithm>
88

9+
#include "src/inspector/inspected-context.h"
910
#include "src/inspector/java-script-call-frame.h"
1011
#include "src/inspector/protocol/Protocol.h"
1112
#include "src/inspector/script-breakpoint.h"
1213
#include "src/inspector/search-util.h"
1314
#include "src/inspector/string-util.h"
15+
#include "src/inspector/v8-console.h"
1416
#include "src/inspector/v8-debugger-script.h"
1517
#include "src/inspector/v8-debugger.h"
1618
#include "src/inspector/v8-inspector-impl.h"
@@ -713,6 +715,20 @@ void V8DebuggerAgentImpl::evaluateOnCallFrame(
713715
return;
714716
}
715717

718+
std::unique_ptr<V8Console::CommandLineAPIScope> claScope;
719+
720+
if (includeCommandLineAPI.fromMaybe(false)) {
721+
InspectedContext* inspectedContext =
722+
m_inspector->getContext(
723+
m_session->contextGroupId(),
724+
V8Debugger::contextId(
725+
v8::Local<v8::Context>::New(m_isolate, m_pausedContext)));
726+
claScope.reset(new V8Console::CommandLineAPIScope(
727+
inspectedContext->context(),
728+
V8Console::createCommandLineAPI(inspectedContext),
729+
inspectedContext->context()->Global()));
730+
}
731+
716732
bool isError = false;
717733
v8::MaybeLocal<v8::Value> maybeResultValue =
718734
m_pausedCallFrames[ordinal]->evaluate(

deps/chakrashim/src/inspector/v8-debugger.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) {
278278
}
279279

280280
JsValueRef stackTrace = JS_INVALID_REFERENCE;
281-
JsDiagGetStackTrace(&stackTrace);
281+
CHAKRA_VERIFY_NOERROR(JsDiagGetStackTrace(&stackTrace));
282282

283283
unsigned int length = 0;
284284
CHAKRA_VERIFY_NOERROR(jsrt::GetArrayLength(stackTrace, &length));

deps/chakrashim/src/inspector/v8-runtime-agent-impl.cc

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "src/inspector/inspected-context.h"
3434
#include "src/inspector/protocol/Protocol.h"
3535
#include "src/inspector/string-util.h"
36+
#include "src/inspector/v8-console.h"
3637
#include "src/inspector/v8-console-message.h"
3738
#include "src/inspector/v8-debugger-agent-impl.h"
3839
#include "src/inspector/v8-debugger.h"
@@ -69,6 +70,27 @@ std::unique_ptr<protocol::DictionaryValue> ParseObjectId(
6970
return wrapUnique(protocol::DictionaryValue::cast(parsedValue.release()));
7071
}
7172

73+
bool ensureContext(ErrorString* errorString, V8InspectorImpl* inspector,
74+
int contextGroupId, Maybe<int> executionContextId,
75+
int* contextId) {
76+
if (executionContextId.isJust()) {
77+
*contextId = executionContextId.fromJust();
78+
} else {
79+
v8::HandleScope handles(inspector->isolate());
80+
v8::Local<v8::Context> defaultContext =
81+
inspector->client()->ensureDefaultContextInGroup(contextGroupId);
82+
83+
if (defaultContext.IsEmpty()) {
84+
*errorString = "Cannot find default execution context";
85+
return false;
86+
}
87+
88+
*contextId = V8Debugger::contextId(defaultContext);
89+
}
90+
91+
return true;
92+
}
93+
7294
} // namespace
7395

7496
V8RuntimeAgentImpl::V8RuntimeAgentImpl(
@@ -91,6 +113,24 @@ void V8RuntimeAgentImpl::evaluate(
91113
std::unique_ptr<EvaluateCallback> callback) {
92114
ErrorString errorString;
93115

116+
int contextId = 0;
117+
if (!ensureContext(&errorString, m_inspector, m_session->contextGroupId(),
118+
std::move(executionContextId), &contextId)) {
119+
callback->sendFailure(errorString);
120+
return;
121+
}
122+
123+
std::unique_ptr<V8Console::CommandLineAPIScope> claScope;
124+
125+
if (includeCommandLineAPI.fromMaybe(false)) {
126+
InspectedContext* inspectedContext =
127+
m_inspector->getContext(m_session->contextGroupId(), contextId);
128+
claScope.reset(new V8Console::CommandLineAPIScope(
129+
inspectedContext->context(),
130+
V8Console::createCommandLineAPI(inspectedContext),
131+
inspectedContext->context()->Global()));
132+
}
133+
94134
JsValueRef expStr;
95135
if (JsCreateStringUtf16(expression.characters16(), expression.length(),
96136
&expStr) != JsNoError) {
@@ -99,9 +139,10 @@ void V8RuntimeAgentImpl::evaluate(
99139
return;
100140
}
101141

142+
bool isError = false;
102143
v8::Local<v8::Value> evalResult =
103-
jsrt::InspectorHelpers::EvaluateOnCallFrame(
104-
/* ordinal */ 0, expStr, returnByValue.fromMaybe(false));
144+
jsrt::InspectorHelpers::EvaluateOnGlobalCallFrame(
145+
expStr, returnByValue.fromMaybe(false), &isError);
105146

106147
if (evalResult.IsEmpty()) {
107148
errorString = "Failed to evaluate expression";
@@ -114,7 +155,7 @@ void V8RuntimeAgentImpl::evaluate(
114155
std::unique_ptr<protocol::Value> protocolValue =
115156
toProtocolValue(&errorString, v8::Context::GetCurrent(), evalResult);
116157
if (!protocolValue) {
117-
callback->sendSuccess(nullptr, exceptionDetails);
158+
callback->sendFailure(errorString);
118159
return;
119160
}
120161
std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject =
@@ -125,6 +166,29 @@ void V8RuntimeAgentImpl::evaluate(
125166
return;
126167
}
127168

169+
if (isError) {
170+
protocol::ErrorSupport errors;
171+
std::unique_ptr<protocol::Runtime::RemoteObject> exceptionObject =
172+
protocol::Runtime::RemoteObject::parse(protocolValue.get(), &errors);
173+
if (!exceptionObject) {
174+
errorString = errors.errors();
175+
callback->sendFailure(errorString);
176+
return;
177+
}
178+
179+
std::unique_ptr<protocol::Runtime::ExceptionDetails> exDetails =
180+
protocol::Runtime::ExceptionDetails::create()
181+
.setExceptionId(m_session->inspector()->nextExceptionId())
182+
.setText(exceptionObject->getDescription("Uncaught"))
183+
.setLineNumber(0)
184+
.setColumnNumber(0)
185+
.build();
186+
187+
exDetails->setException(std::move(exceptionObject));
188+
189+
exceptionDetails = std::move(exDetails);
190+
}
191+
128192
callback->sendSuccess(std::move(remoteObject), exceptionDetails);
129193
}
130194

deps/chakrashim/src/jsrtcachedpropertyidref.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ DEF(url)
125125
DEF(toStringTag)
126126
DEF(Symbol_toStringTag)
127127

128+
DEF(add)
129+
DEF(from)
130+
128131
DEFSYMBOL(self)
129132
DEFSYMBOL(__external__)
130133
DEFSYMBOL(__hiddenvalues__)

deps/chakrashim/src/jsrtcontextcachedobj.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ DEFTYPE(Float64Array)
4646
DEFTYPE(RegExp)
4747
DEFTYPE(Map)
4848
DEFTYPE(Symbol)
49+
DEFTYPE(Set)
4950

5051

5152
// These prototype functions will be cached/shimmed
5253
DEFMETHOD(Object, toString)
5354
DEFMETHOD(Object, valueOf)
5455
DEFMETHOD(String, concat)
56+
DEFMETHOD(Array, from)
5557
DEFMETHOD(Array, push)
5658
DEFMETHOD(Map, get)
5759
DEFMETHOD(Map, set)
5860
DEFMETHOD(Map, has)
61+
DEFMETHOD(Set, add)
5962

6063

6164
#undef DEFTYPE

deps/chakrashim/src/jsrtcontextshim.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ DECLARE_GETOBJECT(ProxyConstructor,
532532
globalConstructor[GlobalType::Proxy])
533533
DECLARE_GETOBJECT(MapConstructor,
534534
globalConstructor[GlobalType::Map])
535+
DECLARE_GETOBJECT(SetConstructor,
536+
globalConstructor[GlobalType::Set])
537+
DECLARE_GETOBJECT(ArrayConstructor,
538+
globalConstructor[GlobalType::Array])
535539
DECLARE_GETOBJECT(ToStringFunction,
536540
globalPrototypeFunction[GlobalPrototypeFunction
537541
::Object_toString])
@@ -541,6 +545,9 @@ DECLARE_GETOBJECT(ValueOfFunction,
541545
DECLARE_GETOBJECT(StringConcatFunction,
542546
globalPrototypeFunction[GlobalPrototypeFunction
543547
::String_concat])
548+
DECLARE_GETOBJECT(ArrayFromFunction,
549+
globalPrototypeFunction[GlobalPrototypeFunction
550+
::Array_from])
544551
DECLARE_GETOBJECT(ArrayPushFunction,
545552
globalPrototypeFunction[GlobalPrototypeFunction
546553
::Array_push])
@@ -553,6 +560,9 @@ DECLARE_GETOBJECT(MapSetFunction,
553560
DECLARE_GETOBJECT(MapHasFunction,
554561
globalPrototypeFunction[GlobalPrototypeFunction
555562
::Map_has])
563+
DECLARE_GETOBJECT(SetAddFunction,
564+
globalPrototypeFunction[GlobalPrototypeFunction
565+
::Set_add])
556566

557567

558568
JsValueRef ContextShim::GetProxyOfGlobal() {

deps/chakrashim/src/jsrtcontextshim.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,21 @@ class ContextShim {
7979
JsValueRef GetRegExpConstructor();
8080
JsValueRef GetProxyConstructor();
8181
JsValueRef GetMapConstructor();
82+
JsValueRef GetSetConstructor();
83+
JsValueRef GetArrayConstructor();
8284
JsValueRef GetGlobalType(GlobalType index);
8385

8486
JsValueRef GetToStringFunction();
8587
JsValueRef GetValueOfFunction();
8688
JsValueRef GetStringConcatFunction();
89+
JsValueRef GetArrayFromFunction();
8790
JsValueRef GetArrayPushFunction();
8891
JsValueRef GetGlobalPrototypeFunction(GlobalPrototypeFunction index);
8992
JsValueRef GetProxyOfGlobal();
9093
JsValueRef GetMapGetFunction();
9194
JsValueRef GetMapSetFunction();
9295
JsValueRef GetMapHasFunction();
96+
JsValueRef GetSetAddFunction();
9397

9498
void * GetAlignedPointerFromEmbedderData(int index);
9599
void SetAlignedPointerInEmbedderData(int index, void * value);

deps/chakrashim/src/jsrtinspectorhelpers.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,22 @@ namespace jsrt {
630630
return EvaluateOnCallFrame(ordinal, expression, returnByValue, isError);
631631
}
632632

633+
v8::Local<v8::Value> InspectorHelpers::EvaluateOnGlobalCallFrame(
634+
JsValueRef expression, bool returnByValue, bool* isError) {
635+
JsValueRef stackTrace = JS_INVALID_REFERENCE;
636+
JsErrorCode err = JsDiagGetStackTrace(&stackTrace);
637+
if (err == JsErrorDiagNotAtBreak) {
638+
return v8::Local<v8::Value>();
639+
}
640+
641+
CHAKRA_VERIFY_NOERROR(err);
642+
643+
unsigned int length = 0;
644+
CHAKRA_VERIFY_NOERROR(jsrt::GetArrayLength(stackTrace, &length));
645+
646+
return EvaluateOnCallFrame(length - 1, expression, returnByValue, isError);
647+
}
648+
633649
v8::Local<v8::Value> InspectorHelpers::GetScriptSource(
634650
unsigned int scriptId) {
635651
JsValueRef scriptSource = JS_INVALID_REFERENCE;

0 commit comments

Comments
 (0)