зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1034627 part 1 - Add some new string APIs. r=terrence
This commit is contained in:
Родитель
0916bd9c19
Коммит
2ab4bcd2b2
|
@ -5384,6 +5384,49 @@ JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &no
|
|||
return linear->twoByteChars(nogc);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(const jschar *)
|
||||
JS_GetTwoByteExternalStringChars(JSString *str)
|
||||
{
|
||||
return str->asExternal().twoByteChars();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res)
|
||||
{
|
||||
AssertHeapIsIdleOrStringIsFlat(cx, str);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, str);
|
||||
|
||||
JSLinearString *linear = str->ensureLinear(cx);
|
||||
if (!linear)
|
||||
return false;
|
||||
|
||||
*res = linear->latin1OrTwoByteChar(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(jschar)
|
||||
JS_GetFlatStringCharAt(JSFlatString *str, size_t index)
|
||||
{
|
||||
return str->latin1OrTwoByteChar(index);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_CopyStringChars(JSContext *cx, mozilla::Range<jschar> dest, JSString *str)
|
||||
{
|
||||
AssertHeapIsIdleOrStringIsFlat(cx, str);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, str);
|
||||
|
||||
JSLinearString *linear = str->ensureLinear(cx);
|
||||
if (!linear)
|
||||
return false;
|
||||
|
||||
MOZ_ASSERT(linear->length() <= dest.length());
|
||||
CopyChars(dest.start().get(), *linear);
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(const jschar *)
|
||||
JS_GetInternedStringChars(JSString *str)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Range.h"
|
||||
#include "mozilla/RangedPtr.h"
|
||||
#include "mozilla/TypedEnum.h"
|
||||
|
||||
|
@ -4181,6 +4182,18 @@ extern JS_PUBLIC_API(const jschar *)
|
|||
JS_GetTwoByteStringCharsAndLength(JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str,
|
||||
size_t *length);
|
||||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
JS_GetStringCharAt(JSContext *cx, JSString *str, size_t index, jschar *res);
|
||||
|
||||
extern JS_PUBLIC_API(jschar)
|
||||
JS_GetFlatStringCharAt(JSFlatString *str, size_t index);
|
||||
|
||||
extern JS_PUBLIC_API(const jschar *)
|
||||
JS_GetTwoByteExternalStringChars(JSString *str);
|
||||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
JS_CopyStringChars(JSContext *cx, mozilla::Range<jschar> dest, JSString *str);
|
||||
|
||||
extern JS_PUBLIC_API(const jschar *)
|
||||
JS_GetInternedStringChars(JSString *str);
|
||||
|
||||
|
|
|
@ -953,6 +953,14 @@ class JSExternalString : public JSFlatString
|
|||
return d.s.u3.externalFinalizer;
|
||||
}
|
||||
|
||||
/*
|
||||
* External chars are never allocated inline or in the nursery, so we can
|
||||
* safely expose this without requiring an AutoCheckCannotGC argument.
|
||||
*/
|
||||
const jschar *twoByteChars() const {
|
||||
return rawTwoByteChars();
|
||||
}
|
||||
|
||||
/* Only called by the GC for strings with the FINALIZE_EXTERNAL_STRING kind. */
|
||||
|
||||
inline void finalize(js::FreeOp *fop);
|
||||
|
|
Загрузка…
Ссылка в новой задаче