-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add JSRT API JsLessThan (Fix #3568) #3931
Conversation
@dotnet-bot test Ubuntu shared_ubuntu_linux_debug please |
Would it make sense to add the other operators as well? (LessThanOrEqual, GreaterThan, GreaterThanOrEqual) I know that they can all be implemented in terms of JsLessThan and JsEqual, but adding wrappers for these comparison primitives to help user code read better doesn't seem like a bad idea. @liminzhu @Cellule opinions? |
@xiaoyinl When you make your next update to add documentation (assuming you still have a work item there), could you rebase this PR to a single commit? |
@dilijev The way this PR implements LessThan is that, as proposed by @liminzhu, it takes a parameter If you have decided to separate |
@xiaoyinl I didn't realize the discussion on the issue at first. I'm not familiar with the discussion here. In general we want to keep the API surface small so let's not add a bunch more operations without more unanimous approval. But I agree with you that IMO having that functionality might be regarded as worse than only allowing /cc @liminzhu @bterlson @marktjsonar who were involved in the issue discussion. |
@dilijev If I remember it correctly, there is an edge case that makes
|
Ole! Thanks for the PR @xiaoyinl ! @xiaoyinl @dilijev having separate
let x = {a: 1};
let y = {b: 2};
x > y // false
x < y // false
x == y // false
x === y // false
x >= y // true
x <= y // true Edit: forgot to mention. @xiaoyinl can you put the API in ChakraCore.h instead? ChakraCore.h APIs only ship with ChakraCore. ChakraCommon.h APIs get shipped with Chakra on Windows as well, and there's a process we need to follow internally before that can happen. |
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.
LGTM, but I'll let others review and approve.
@akroshg who is a good person to code-review JSRT changes? |
@liminzhu I would have thought you. :) Maybe @boingoing? |
@dilijev well I care much about the interface but usually don't look into .cpp's so another pair of eyes would be nice :) |
lib/Jsrt/Jsrt.cpp
Outdated
CHAKRA_API JsLessThan(_In_ JsValueRef object1, _In_ JsValueRef object2, _Out_ bool *result) | ||
{ | ||
return ContextAPIWrapper<JSRT_MAYBE_TRUE>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode { | ||
PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTEquals, object1, object2, false); |
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'm pretty sure we will need a new TTD action for recording these. Right now we're recording doing a non-strict-equals with RecordJsRTEquals
and the flag value false
to indicate not is-strict
. We probably want to add a new action like RecordJsRTLessThan
with a flag to say if it should be or-equal
.
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.
Code changes look good to me but we should add a TTD action.
lib/Jsrt/Jsrt.cpp
Outdated
@@ -2239,7 +2239,7 @@ CHAKRA_API JsLessThan(_In_ JsValueRef object1, _In_ JsValueRef object2, _Out_ bo | |||
CHAKRA_API JsLessThanOrEqual(_In_ JsValueRef object1, _In_ JsValueRef object2, _Out_ bool *result) | |||
{ | |||
return ContextAPIWrapper<JSRT_MAYBE_TRUE>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode { | |||
PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTEquals, object1, object2, false); | |||
PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTLessThan, object1, object2, false); |
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.
Looks like this should pass true for allowsEqual
, right?
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.
Sorry I should have mentioned earlier. We need an execute function to match the TTD action we recorded. Then when we replay we will know which action to execute.
This is simple, though, just needs a little glue code.
First we'll need to add the handler. Take a look at EqualsAction_Execute
in TTActionEvents.cpp to get an idea of what to do. This is mostly just boiler-plate - execute the less-than or less-than-equal based on the flag you saved earlier.
Second we'll need to do the mapping between the action and the execute function. Check out TTEventLog.cpp near line 553. I think you'll want to add something like this:
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(LessThanActionTag, ContextAPIWrapper, JsRTDoubleVarSingleScalarArgumentAction, LessThanAction_Execute);
@boingoing Thank you for the detailed explanation. I have done what you mentioned. Hopefully this time I didn't miss anything. |
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 looks good to me, thank you for the attention to detail. 👍
Thank you again for the review! I have squashed the commits. |
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.
LGTM
Testing internally; then will merge. |
Merge pull request #3931 from xiaoyinl:JsLessThan This PR implements the API JsLessThan and JsLessThanOrEqual, proposed in issue #3568. Fixes #3568 Todo: - [x] Add more test cases - [x] Update documents (microsoft/ChakraCore-wiki#43)
This PR updates the documents for chakra-core/ChakraCore#3931.
This PR updates the documents for chakra-core/ChakraCore#3931.
This PR implements the API JsLessThan and JsLessThanOrEqual, proposed in issue #3568.
Fixes #3568
Todo: