Closed Bug 1024587 Opened 10 years ago Closed 10 years ago

IonMonkey: Implement CharCodeAt Recover Instruction

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla33

People

(Reporter: nbp, Assigned: devillers.nicolas, Mentored)

References

(Blocks 1 open bug)

Details

(Whiteboard: [good first bug][lang=c++])

Attachments

(1 file, 1 obsolete file)

Implement RCharCodeAt in js/src/jit/Recover.cpp. See Bug 1003801 comment 0 for explanation.
Mentor: nicolas.b.pierron
Whiteboard: [good first bug][mentor=nbp][lang=c++] → [good first bug][lang=c++]
Working on it.
Assignee: nobody → devillers.nicolas
Working on it.
Attached patch bug-1024587-fix.patch (obsolete) — Splinter Review
Attachment #8444154 - Flags: review?(nicolas.b.pierron)
Comment on attachment 8444154 [details] [diff] [review] bug-1024587-fix.patch Review of attachment 8444154 [details] [diff] [review]: ----------------------------------------------------------------- This looks good :) Still a new nits to fix before being ready to go. ::: js/src/jit/Recover.cpp @@ +438,5 @@ > + RootedValue result(cx); > + > + if (!js::str_charCodeAt_handle(cx, lhs, rhs, &result)) { > + return false; > + } style-nit: no curly braces when we have only one line. ::: js/src/jsstr.cpp @@ +1011,5 @@ > +{ > + RootedString str(cx); > + size_t i; > + if (index.isInt32()) { > + // case integer nit: As soon as the code is easy to understand there is no need to paraphrase it. @@ +1020,5 @@ > + // double case > + double d = 0.0; > + if (!ToInteger(cx, index, &d)) { > + return false; > + } style-nit: no curly braces. @@ +1021,5 @@ > + double d = 0.0; > + if (!ToInteger(cx, index, &d)) { > + return false; > + } > + if (d < 0 || string->length() <= d ) nit: Add a comment to explain why we need to compare "d < 0" before doing the "size_t(d)". @@ +1053,5 @@ > + if (args.length() == 0) { > + index.setInt32(0); > + } else { > + index = args[0]; > + } style-nit: Remove curly braces. style-nit: Initialize the index before the condition, and invert the condition to set the index to args[0].
Attachment #8444154 - Flags: review?(nicolas.b.pierron) → feedback+
Comment on attachment 8444154 [details] [diff] [review] bug-1024587-fix.patch Review of attachment 8444154 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/jsstr.cpp @@ +1007,4 @@ > } > > bool > +js::str_charCodeAt_handle(JSContext *cx, HandleString string, HandleValue index, MutableHandleValue res) We usually have names like _impl and not _handle. @@ +1053,5 @@ > + if (args.length() == 0) { > + index.setInt32(0); > + } else { > + index = args[0]; > + } Actually now that you killed the fast path, this function could be written like. if (args.thisv.isString()) { str = this.toString } else { str = ThisToStringForStringProto(cx, args); .. } if (args.length() == 0) { index.setint(0) } else () { index = args[0] }
Indicated changes added
Attachment #8444178 - Flags: review?(nicolas.b.pierron)
Attachment #8444178 - Flags: review?(evilpies)
(In reply to Tom Schuster [:evilpie] from comment #5) > Comment on attachment 8444154 [details] [diff] [review] > bug-1024587-fix.patch > > Review of attachment 8444154 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: js/src/jsstr.cpp > @@ +1007,4 @@ > > } > > > > bool > > +js::str_charCodeAt_handle(JSContext *cx, HandleString string, HandleValue index, MutableHandleValue res) > > We usually have names like _impl and not _handle. The problem with these functions is that we cannot overload (because of ambiguous resolution) the default name, as it is used for the JSClass declaration, and we cannot overload the _impl function as it is used by Ion code generator. I guess we could only do _handle functions for the math functions and keep doing the _impl for others. What do you think?
(In reply to Nicolas B. Pierron [:nbp] from comment #7) > The problem with these functions is that we cannot overload (because of > ambiguous resolution) the default name, as it is used for the JSClass > declaration, and we cannot overload the _impl function as it is used by Ion > code generator. str_charCodeAt_impl is not used anywhere as far as I can see. Also, there's a CharCodeAt function in jit/VMFunctions.cpp, could we use that one?
(In reply to Jan de Mooij [:jandem] from comment #8) > (In reply to Nicolas B. Pierron [:nbp] from comment #7) > > The problem with these functions is that we cannot overload (because of > > ambiguous resolution) the default name, as it is used for the JSClass > > declaration, and we cannot overload the _impl function as it is used by Ion > > code generator. > > str_charCodeAt_impl is not used anywhere as far as I can see. Also, there's > a CharCodeAt function in jit/VMFunctions.cpp, could we use that one? For Recover instructions, I prefer to avoid using a type-dependent function (because we do not know if the Int input property still holds, it might be a double now), where the inputs are looking for having an int and a number in the range of the string. Also, I think that this CharCodeAt function should probably be located in jsstr.cpp and not in VMFunction.cpp.
Should I rename it to str_charCodeAt_handle again ? What do you think ?
Comment on attachment 8444178 [details] [diff] [review] bug-1024587-fix-v2.patch Review of attachment 8444178 [details] [diff] [review]: ----------------------------------------------------------------- This sounds good to me. ::: js/src/jsstr.cpp @@ +1019,5 @@ > + double d = 0.0; > + if (!ToInteger(cx, index, &d)) > + return false; > + // check whether d is negative as size_t is unsigned > + if (d < 0 || string->length() <= d ) nit: The comment should read something like: Check "d" before doing a cast to an unsigned, as the cast is rounded towards 0. (including -0.4)
Attachment #8444178 - Flags: review?(nicolas.b.pierron) → review+
(In reply to Nicolas B. Pierron [:nbp] from comment #9) > (In reply to Jan de Mooij [:jandem] from comment #8) > > (In reply to Nicolas B. Pierron [:nbp] from comment #7) > > > The problem with these functions is that we cannot overload (because of > > > ambiguous resolution) the default name, as it is used for the JSClass > > > declaration, and we cannot overload the _impl function as it is used by Ion > > > code generator. > > > > str_charCodeAt_impl is not used anywhere as far as I can see. Also, there's > > a CharCodeAt function in jit/VMFunctions.cpp, could we use that one? > > […], where the inputs are looking for having an int and a number in > the range of the string. […] re-phrased: Where the function is checking its inputs against ints and double before reading from the string.
Comment on attachment 8444178 [details] [diff] [review] bug-1024587-fix-v2.patch Review of attachment 8444178 [details] [diff] [review]: ----------------------------------------------------------------- Sorry for the delay. I don't think the name is so important, I just thought I would point it out.
Attachment #8444178 - Flags: review?(evilpies) → review+
Attachment #8444154 - Attachment is obsolete: true
https://tbpl.mozilla.org/?tree=Try&rev=5ea199f40b6d I've pushed this change to Try, and it looks green on the platform where I tested (and which should be enough to catch errors)
Congratulation for your first patch :)
Status: NEW → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla33
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: