Closed Bug 1407858 Opened 7 years ago Closed 7 years ago

Add first-class literal support to DOMString

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox58 --- wontfix
firefox59 --- fixed

People

(Reporter: n.nethercote, Assigned: bzbarsky)

References

Details

Attachments

(3 files, 1 obsolete file)

This is a follow-up to bug 1407117, which adds code that assigns static atom literals to DOMStrings via nsString. It would be better to allow the literals to be assigned directly, without consructing/destructing an nsString.
Flags: needinfo?(bzbarsky)
Priority: -- → P3
The renaming here is like this: SetStringBuffer -> SetKnownLiveStringBuffer SetEphemeralStringBuffer -> SetStringBuffer SetOwnedString -> SetKnownLiveString SetOwnedAtom -> SetKnownLiveAtom This should make it clearer what the lifetime expectations are on the caller side. MozReview-Commit-ID: ERHbB3r6paN
Attachment #8938595 - Flags: review?(bugs)
MozReview-Commit-ID: AaTeI1e7Qnk
Attachment #8938596 - Flags: review?(bugs)
MozReview-Commit-ID: EsgAAcfDFKt
Attachment #8938597 - Flags: review?(bugs)
Attachment #8938603 - Flags: review?(bugs)
Attachment #8938595 - Attachment is obsolete: true
Attachment #8938595 - Flags: review?(bugs)
Attachment #8938603 - Flags: review?(bugs) → review+
Comment on attachment 8938596 [details] [diff] [review] part 2. Make DOMString's data model clearer and update various documentation > * The proper way to extract a value is to check IsNull(). If not null, then >- * check HasStringBuffer(). If that's true, check for a zero length, and if the >- * length is nonzero call StringBuffer(). If the length is zero this is the >- * empty string. If HasStringBuffer() returns false, call AsAString() and get >- * the value from that. >+ * check IsEmpty(). If neither of those is true, check HasStringBuffer(). If >+ * that's true, call StringBuffer(). If HasStringBuffer() returns false, call >+ * AsAString() and get the value from that. This all doesn't seem to quite capture the case that AsString() can be called when IsEmpty() returns true. >+ >+ enum class State : uint8_t { Nit, { should be on its own line
Attachment #8938596 - Flags: review?(bugs) → review+
Comment on attachment 8938597 [details] [diff] [review] part 3. Add a literal string state to DOMString >+ // Get the literal string. This can only be called if HasLiteral() >+ // returned true. If that's true, it will never return null. >+ const char16_t* Literal() const >+ { >+ MOZ_ASSERT(HasLiteral(), >+ "Don't ask for the literal if we don't have it"); >+ MOZ_ASSERT(mStringBuffer, >+ "We better have a literal if we claim to"); mStringBuffer? Shouldn't you use mLiteral here. Both point to the same value, but would make reading easier. >- // The nsStringBuffer in the OwnedStringBuffer/UnownedStringBuffer cases. >- nsStringBuffer* MOZ_UNSAFE_REF("The ways in which this can be safe are " >+ union { I think { should be on its own line.
Attachment #8938597 - Flags: review?(bugs) → review+
> This all doesn't seem to quite capture the case that AsString() can be called when IsEmpty() returns true. Well, for _extracting_ a value that's not really relevant, since if IsEmpty() is true then the value is empty. > Nit, { should be on its own line Done. > mStringBuffer? Shouldn't you use mLiteral here. Yes, good catch. > I think { should be on its own line. Done.
Pushed by bzbarsky@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/a229bf234505 part 1. Give DOMString setter APIs clearer names. r=smaug https://hg.mozilla.org/integration/mozilla-inbound/rev/282695389a27 part 2. Make DOMString's data model clearer and update various documentation. r=smaug https://hg.mozilla.org/integration/mozilla-inbound/rev/45fe585acac1 part 3. Add a literal string state to DOMString. r=smaug
Too late for FF58. Mark 58 won't fix.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: