New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-25963] Android: Improve KrollRuntime error output #10003
Conversation
c447875
to
b5e6692
Compare
b5e6692
to
bced8a8
Compare
91d40c9
to
ba02d5e
Compare
ba02d5e
to
3bbb910
Compare
3bbb910
to
0877998
Compare
0877998
to
43b72f9
Compare
43b72f9
to
d236df6
Compare
f240c07
to
68ccd97
Compare
952a91d
to
18329ae
Compare
36ef889
to
2f87c47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look OK to me. But I think you should be able to generate mocha unit tests from your manual examples here.
We can't test any changes to the dialog, but we should be able to test that accessing a undefined property throws an Error and that the stack generally looks like we expect it to.
|
||
env->ReleaseStringUTFChars(javaMessage, messagePtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason we don't just do this cleanup right away after appending the messagePtr to the stream? (i.e. line 45 or so)
7b7312c
to
dc2d097
Compare
|
||
V8Runtime::exceptionStackTrace.Reset(isolate, message->GetStackTrace()); | ||
// obtain javascript stack trace | ||
if (jsStack->IsNullOrUndefined() || jsStack.IsEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse the order here? I was worried if trying to call IsNullOrUndefined()
on an empty handle would crash.
|
||
if (exception->IsObject()) { | ||
Local<Object> error = exception.As<Object>(); | ||
jsStack = exception.As<Object>()->Get(STRING_NEW(isolate, "stack")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the error
objet reference you assign just above here rather than call .As again
|
||
jstring title = env->NewStringUTF("Runtime Error"); | ||
jstring errorMessage = TypeConverter::jsValueToJavaString(isolate, env, message->Get()); | ||
jstring resourceName = TypeConverter::jsValueToJavaString(isolate, env, message->GetScriptResourceName()); | ||
jstring sourceLine = TypeConverter::jsValueToJavaString(isolate, env, message->GetSourceLine()); | ||
jstring javaStack = TypeConverter::jsValueToJavaString(isolate, env, stack); | ||
jstring jsStackString = TypeConverter::jsValueToJavaString(isolate, env, jsStack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to guard here for empty handle and/or undefined. TypeConverter handles null
-> NULL
, but I think it converts undefined
to 'undefined'
. And I think it'll just crash if the handle is empty.
I assigned to a bool up above for when the stack/nativeStack were not null/undefined/empty and if they were, I assigned NULL here and avoided the DeleteLocalRef
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should improve TypeConverter
to handle this validation? This allows us to validate the other conversions too errorMessage, resourceName, sourceLine etc..
Updated PR
9d1044e
to
d811b31
Compare
d811b31
to
4a0eb63
Compare
4a0eb63
to
fecb11e
Compare
@@ -114,7 +114,7 @@ jstring TypeConverter::jsValueToJavaString(v8::Isolate* isolate, v8::Local<v8::V | |||
|
|||
jstring TypeConverter::jsValueToJavaString(v8::Isolate* isolate, JNIEnv *env, v8::Local<v8::Value> jsValue) | |||
{ | |||
if (jsValue->IsNull()) { | |||
if (jsValue.IsEmpty() || jsValue->IsNullOrUndefined()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK, but beware this is a behavioral change here. Before we'd change an undefined
to 'undefined'
|
||
if (exception->IsObject()) { | ||
Local<Object> error = exception.As<Object>(); | ||
jsStack = error->Get(context, STRING_NEW(isolate, "stack")).ToLocalChecked(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the next line could cause a crash if the handle is empty. You could do something like this to better handle it:
jsStack = error->Get(context, STRING_NEW(isolate, "stack")).FromMaybe(Undefined(isolate).As<Value>());
javaStack = error->Get(context, STRING_NEW(isolate, "nativeStack")).FromMaybe(Undefined(isolate).As<Value>());
In that code if the handle is empty due to some error, we'll default to undefined
.
if (jsStack->IsNullOrUndefined() || jsStack.IsEmpty()) { | ||
Local<StackTrace> frames = message->GetStackTrace(); | ||
if (frames.IsEmpty() || !frames->GetFrameCount()) { | ||
frames = StackTrace::CurrentStackTrace(isolate, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we extract the 10 constant here like you did in JSException?
a5d02af
to
1cca9fb
Compare
Generated by 🚫 dangerJS |
QE? |
Provide access to current stack trace usingKrollRuntime.getInstance().getStackTrace()
TEST CASE #1
TEST CASE #2
TIMOB-25963
TIMOB-25965