Add JSStringCreateWithCharactersNoCopy SPI
https://bugs.webkit.org/show_bug.cgi?id=118074
<rdar://problem/14279905>
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:
(JSStringCreateWithCharactersNoCopy):
Create a new OpaqueJSString, using the newly added StringImpl::createWithoutCopying function.
- API/JSStringRefPrivate.h: Added.
Add a home for the JSStringCreateWithCharactersNoCopy function.
(OpaqueJSString::OpaqueJSString):
Just call isolatedCopy on the passed in string.
Add an API test for JSStringCreateWithCharactersNoCopy.
Add new files.
Source/WTF:
(WTF::StringImpl::createFromLiteral):
Use the new ConstructWithoutCopying constructor, passing DoesHaveTerminatingNullCharacter to it.
Change the other createFromLiteral overload to just call the first.
(WTF::StringImpl::createWithoutCopying):
Add helper functions for creating strings that shouldn't copy their underlying data.
(WTF::StringImpl::StringImpl):
Rename the ConstructFromLiteralTag constructor enum to ConstructWithoutCopyingTag. Change the constructor
to take an enum that states whether the string has a terminating null character or not.
(WTF::StringImpl::createFromLiteral):
Call createWithoutCopying.
(WTF::StringImpl::requiresCopy):
Rename this from isASCIILiteral() and make it more generic so it can handle 16-bit strings as well.
(WTF::StringImpl::isolatedCopy):
If this string doesn't have to be copied, just create a new StringImpl object that references the current data.