Bug 1033916 - Move JSAutoByteString out of jsapi.h into js/public/AutoByteString.h, incidentally breaking the jsfriendapi.h -> jsapi.h dependency. r=jandem

--HG--
extra : rebase_source : d85baf9b28e632db5669aa3d056cc9744686f5c8
This commit is contained in:
Jeff Walden 2018-08-20 07:46:08 -07:00
parent 3e90595274
commit ffd93ba761
55 changed files with 196 additions and 83 deletions

View file

@ -6,6 +6,7 @@
#include "ChromeUtils.h"
#include "js/AutoByteString.h"
#include "js/SavedFrameAPI.h"
#include "jsfriendapi.h"
#include "WrapperFactory.h"

View file

@ -19,6 +19,7 @@
#include "GeckoProfiler.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/Conversions.h"
#include "js/StableStringChars.h"
#include "nsString.h"

View file

@ -8,6 +8,7 @@
#define mozilla_dom_BindingUtils_h__
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/Wrapper.h"
#include "js/Conversions.h"
#include "mozilla/ArrayUtils.h"

View file

@ -7,6 +7,7 @@
#ifndef mozilla_dom_DOMJSClass_h
#define mozilla_dom_DOMJSClass_h
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/Wrapper.h"
#include "mozilla/Assertions.h"

View file

@ -16,6 +16,7 @@
#include "base/basictypes.h"
#include "jsapi.h"
#include "js/AutoByteString.h"
#include "xpcpublic.h"

140
js/public/AutoByteString.h Normal file
View file

@ -0,0 +1,140 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* DEPRECATED functions and classes for heap-allocating copies of a JSString's
* data.
*/
#ifndef js_AutoByteString_h
#define js_AutoByteString_h
#include "mozilla/Assertions.h" // MOZ_ASSERT
#include "mozilla/Attributes.h" // MOZ_RAII, MOZ_GUARD*
#include <string.h> // strlen
#include "jstypes.h" // JS_PUBLIC_API
#include "js/MemoryFunctions.h" // JS_free
#include "js/RootingAPI.h" // JS::Handle
#include "js/TypeDecls.h" // JSContext, JSString
#include "js/Utility.h" // js_free, JS::UniqueChars
/**
* DEPRECATED
*
* Allocate memory sufficient to contain the characters of |str| truncated to
* Latin-1 and a trailing null terminator, fill the memory with the characters
* interpreted in that manner plus the null terminator, and return a pointer to
* the memory. The memory must be freed using JS_free to avoid leaking.
*
* This function *loses information* when it copies the characters of |str| if
* |str| contains code units greater than 0xFF. Additionally, users that
* depend on null-termination will misinterpret the copied characters if |str|
* contains any nulls. Avoid using this function if possible, because it will
* eventually be removed.
*/
extern JS_PUBLIC_API(char*)
JS_EncodeString(JSContext* cx, JSString* str);
/**
* DEPRECATED
*
* Same behavior as JS_EncodeString(), but encode into a UTF-8 string.
*
* This function *loses information* when it copies the characters of |str| if
* |str| contains invalid UTF-16: U+FFFD REPLACEMENT CHARACTER will be copied
* instead.
*
* The returned string is also subject to misinterpretation if |str| contains
* any nulls (which are faithfully transcribed into the returned string, but
* which will implicitly truncate the string if it's passed to functions that
* expect null-terminated strings).
*
* Avoid using this function if possible, because we'll remove it once we can
* devise a better API for the task.
*/
extern JS_PUBLIC_API(char*)
JS_EncodeStringToUTF8(JSContext* cx, JS::Handle<JSString*> str);
/**
* DEPRECATED
*
* A lightweight RAII helper class around the various JS_Encode* functions
* above, subject to the same pitfalls noted above. Avoid using this class if
* possible, because as with the functions above, it too needs to be replaced
* with a better, safer API.
*/
class MOZ_RAII JSAutoByteString final
{
private:
char* mBytes;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
private:
JSAutoByteString(const JSAutoByteString& another) = delete;
void operator=(const JSAutoByteString& another) = delete;
public:
JSAutoByteString(JSContext* cx, JSString* str
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mBytes(JS_EncodeString(cx, str))
{
MOZ_ASSERT(cx);
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
: mBytes(nullptr)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
~JSAutoByteString() {
JS_free(nullptr, mBytes);
}
/* Take ownership of the given byte array. */
void initBytes(JS::UniqueChars&& bytes) {
MOZ_ASSERT(!mBytes);
mBytes = bytes.release();
}
char* encodeLatin1(JSContext* cx, JSString* str) {
MOZ_ASSERT(!mBytes);
MOZ_ASSERT(cx);
mBytes = JS_EncodeString(cx, str);
return mBytes;
}
char* encodeUtf8(JSContext* cx, JS::Handle<JSString*> str) {
MOZ_ASSERT(!mBytes);
MOZ_ASSERT(cx);
mBytes = JS_EncodeStringToUTF8(cx, str);
return mBytes;
}
void clear() {
js_free(mBytes);
mBytes = nullptr;
}
char* ptr() const {
return mBytes;
}
bool operator!() const {
return !mBytes;
}
size_t length() const {
if (!mBytes)
return 0;
return strlen(mBytes);
}
};
#endif /* js_AutoByteString_h */

View file

@ -41,6 +41,7 @@
#include "jit/BaselineJIT.h"
#include "jit/InlinableNatives.h"
#include "jit/JitRealm.h"
#include "js/AutoByteString.h"
#include "js/Debug.h"
#include "js/HashTable.h"
#include "js/StableStringChars.h"

View file

@ -17,6 +17,7 @@
#include "builtin/intl/ScopedICUObject.h"
#include "builtin/intl/SharedIntlData.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
#include "js/TypeDecls.h"
#include "vm/GlobalObject.h"

View file

@ -19,6 +19,7 @@
#include "builtin/intl/SharedIntlData.h"
#include "builtin/intl/TimeZoneDataGenerated.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
#include "vm/DateTime.h"
#include "vm/GlobalObject.h"

View file

@ -21,6 +21,7 @@
#include "builtin/intl/NumberFormat.h"
#include "builtin/intl/PluralRules.h"
#include "builtin/intl/ScopedICUObject.h"
#include "js/AutoByteString.h"
#include "js/Class.h"
#include "js/StableStringChars.h"
#include "vm/GlobalObject.h"

View file

@ -15,6 +15,7 @@
#include "builtin/intl/ICUStubs.h"
#include "builtin/intl/ScopedICUObject.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "vm/GlobalObject.h"
#include "vm/JSContext.h"
#include "vm/StringType.h"

View file

@ -15,6 +15,7 @@
#include "builtin/intl/ICUStubs.h"
#include "builtin/intl/ScopedICUObject.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "vm/GlobalObject.h"
#include "vm/JSContext.h"

View file

@ -40,6 +40,7 @@
#include "gc/Policy.h"
#include "gc/Zone.h"
#include "jit/AtomicOperations.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
#include "js/UniquePtr.h"
#include "js/Vector.h"

View file

@ -10,6 +10,7 @@
#include "prlink.h"
#include "ctypes/CTypes.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
using JS::AutoStableStringChars;

View file

@ -8,6 +8,7 @@
#include "frontend/BytecodeEmitter.h"
#include "frontend/TDZCheckCache.h"
#include "js/AutoByteString.h"
using namespace js;
using namespace js::frontend;

View file

@ -37,6 +37,7 @@
#include "frontend/FoldConstants.h"
#include "frontend/TokenStream.h"
#include "irregexp/RegExpParser.h"
#include "js/AutoByteString.h"
#include "vm/BytecodeUtil.h"
#include "vm/JSAtom.h"
#include "vm/JSContext.h"

View file

@ -17,6 +17,7 @@
#include "gc/GC.h"
#include "js/AllocPolicy.h"
#include "js/AutoByteString.h"
#include "js/Vector.h"
#include "vm/JSContext.h"

View file

@ -55,6 +55,7 @@
#include "gc/WeakMap.h"
#include "jit/JitCommon.h"
#include "jit/JitSpewer.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "js/Conversions.h"
#include "js/Date.h"

View file

@ -4595,19 +4595,6 @@ JS_PUBLIC_API(bool)
JS_DecodeBytes(JSContext* cx, const char* src, size_t srclen, char16_t* dst,
size_t* dstlenp);
/**
* A variation on JS_EncodeCharacters where a null terminated string is
* returned that you are expected to call JS_free on when done.
*/
JS_PUBLIC_API(char*)
JS_EncodeString(JSContext* cx, JSString* str);
/**
* Same behavior as JS_EncodeString(), but encode into UTF-8 string
*/
JS_PUBLIC_API(char*)
JS_EncodeStringToUTF8(JSContext* cx, JS::HandleString str);
/**
* Get number of bytes in the string encoding (without accounting for a
* terminating zero bytes. The function returns (size_t) -1 if the string
@ -4627,75 +4614,6 @@ JS_GetStringEncodingLength(JSContext* cx, JSString* str);
MOZ_MUST_USE JS_PUBLIC_API(bool)
JS_EncodeStringToBuffer(JSContext* cx, JSString* str, char* buffer, size_t length);
class MOZ_RAII JSAutoByteString
{
public:
JSAutoByteString(JSContext* cx, JSString* str
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mBytes(JS_EncodeString(cx, str))
{
MOZ_ASSERT(cx);
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
explicit JSAutoByteString(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
: mBytes(nullptr)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
~JSAutoByteString() {
JS_free(nullptr, mBytes);
}
/* Take ownership of the given byte array. */
void initBytes(JS::UniqueChars&& bytes) {
MOZ_ASSERT(!mBytes);
mBytes = bytes.release();
}
char* encodeLatin1(JSContext* cx, JSString* str) {
MOZ_ASSERT(!mBytes);
MOZ_ASSERT(cx);
mBytes = JS_EncodeString(cx, str);
return mBytes;
}
char* encodeUtf8(JSContext* cx, JS::HandleString str) {
MOZ_ASSERT(!mBytes);
MOZ_ASSERT(cx);
mBytes = JS_EncodeStringToUTF8(cx, str);
return mBytes;
}
void clear() {
js_free(mBytes);
mBytes = nullptr;
}
char* ptr() const {
return mBytes;
}
bool operator!() const {
return !mBytes;
}
size_t length() const {
if (!mBytes)
return 0;
return strlen(mBytes);
}
private:
char* mBytes;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
/* Copy and assignment are not supported. */
JSAutoByteString(const JSAutoByteString& another);
JSAutoByteString& operator=(const JSAutoByteString& another);
};
/************************************************************************/
/*
* Symbols

View file

@ -23,6 +23,7 @@
#include "gc/FreeOp.h"
#include "gc/Marking.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "js/UniquePtr.h"
#include "js/Wrapper.h"

View file

@ -17,6 +17,8 @@
#include "js/UniquePtr.h"
#include "vm/JSContext.h"
class JSAutoByteString;
namespace js {
class ErrorObject;

View file

@ -20,6 +20,7 @@
#include "gc/GCInternals.h"
#include "gc/PublicIterators.h"
#include "gc/WeakMap.h"
#include "js/AutoByteString.h"
#include "js/Printf.h"
#include "js/Proxy.h"
#include "js/Wrapper.h"

View file

@ -13,11 +13,12 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/UniquePtr.h"
#include "jsapi.h" // For JSAutoByteString. See bug 1033916.
#include "jspubtd.h"
#include "js/AutoByteString.h"
#include "js/CallArgs.h"
#include "js/CallNonGenericMethod.h"
#include "js/CharacterEncoding.h"
#include "js/Class.h"
#include "js/ErrorReport.h"
#include "js/HeapAPI.h"

View file

@ -124,6 +124,7 @@ EXPORTS += [
EXPORTS.js += [
'../public/AllocPolicy.h',
'../public/AutoByteString.h',
'../public/CallArgs.h',
'../public/CallNonGenericMethod.h',
'../public/CharacterEncoding.h',

View file

@ -8,6 +8,7 @@
#include "jsapi.h"
#include "js/AutoByteString.h"
#include "vm/Interpreter.h" // For InstanceOfOperator
#include "vm/JSObject-inl.h"

View file

@ -25,6 +25,7 @@
#include "builtin/String.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "js/Conversions.h"
#include "js/Wrapper.h"
#include "shell/jsshell.h"

View file

@ -77,6 +77,7 @@
#include "jit/JitcodeMap.h"
#include "jit/JitRealm.h"
#include "jit/shared/CodeGenerator-shared.h"
#include "js/AutoByteString.h"
#include "js/Debug.h"
#include "js/GCVector.h"
#include "js/Initialization.h"

View file

@ -32,6 +32,7 @@
#include "frontend/SourceNotes.h"
#include "gc/FreeOp.h"
#include "gc/GCInternals.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "js/Printf.h"
#include "util/StringBuffer.h"

View file

@ -25,6 +25,7 @@
#include "gc/PublicIterators.h"
#include "jit/BaselineDebugModeOSR.h"
#include "jit/BaselineJIT.h"
#include "js/AutoByteString.h"
#include "js/Date.h"
#include "js/StableStringChars.h"
#include "js/UbiNodeBreadthFirst.h"

View file

@ -8,6 +8,7 @@
#include "builtin/ModuleObject.h"
#include "gc/Policy.h"
#include "js/AutoByteString.h"
#include "vm/ArgumentsObject.h"
#include "vm/AsyncFunction.h"
#include "vm/GlobalObject.h"

View file

@ -13,6 +13,7 @@
#include "jsexn.h"
#include "js/AutoByteString.h"
#include "js/CallArgs.h"
#include "js/CharacterEncoding.h"
#include "vm/GlobalObject.h"

View file

@ -31,6 +31,7 @@
#include "jit/Ion.h"
#include "jit/IonAnalysis.h"
#include "jit/Jit.h"
#include "js/AutoByteString.h"
#include "util/StringBuffer.h"
#include "vm/AsyncFunction.h"
#include "vm/AsyncIteration.h"

View file

@ -21,6 +21,7 @@
#include "builtin/String.h"
#include "gc/Marking.h"
#include "js/AutoByteString.h"
#include "util/Text.h"
#include "vm/JSContext.h"
#include "vm/SymbolType.h"

View file

@ -37,6 +37,7 @@
#include "gc/Marking.h"
#include "jit/Ion.h"
#include "jit/PcScriptCache.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "js/Printf.h"
#ifdef JS_SIMULATOR_ARM64

View file

@ -15,6 +15,8 @@
#include "vm/JSObject-inl.h"
class JSAutoByteString;
namespace js {
inline const char*

View file

@ -31,6 +31,7 @@
#include "gc/Policy.h"
#include "jit/InlinableNatives.h"
#include "jit/Ion.h"
#include "js/AutoByteString.h"
#include "js/CallNonGenericMethod.h"
#include "js/Proxy.h"
#include "js/StableStringChars.h"

View file

@ -35,6 +35,7 @@
#include "frontend/BytecodeCompiler.h"
#include "gc/Policy.h"
#include "jit/BaselineJIT.h"
#include "js/AutoByteString.h"
#include "js/MemoryMetrics.h"
#include "js/Proxy.h"
#include "js/UbiNode.h"

View file

@ -12,6 +12,7 @@
#include "mozilla/DebugOnly.h"
#include "gc/Marking.h"
#include "js/AutoByteString.h"
#include "js/Value.h"
#include "vm/Debugger.h"
#include "vm/TypedArrayObject.h"

View file

@ -6,6 +6,7 @@
#include "vm/Probes-inl.h"
#include "js/AutoByteString.h"
#include "vm/JSContext.h"
#ifdef INCLUDE_MOZILLA_DTRACE

View file

@ -14,6 +14,7 @@
#include "builtin/ModuleObject.h"
#include "gc/Allocator.h"
#include "gc/FreeOp.h"
#include "js/AutoByteString.h"
#include "util/StringBuffer.h"
#include "vm/EnvironmentObject.h"
#include "vm/JSScript.h"

View file

@ -38,6 +38,7 @@
#include "gc/Policy.h"
#include "jit/AtomicOperations.h"
#include "jit/InlinableNatives.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "js/Date.h"
#include "js/StableStringChars.h"

View file

@ -20,6 +20,7 @@
#include "gc/GCInternals.h"
#include "gc/Marking.h"
#include "gc/Nursery.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
#include "js/UbiNode.h"
#include "util/StringBuffer.h"

View file

@ -26,6 +26,7 @@
#include "util/Text.h"
#include "vm/Printer.h"
class JSAutoByteString;
class JSDependentString;
class JSExtensibleString;
class JSExternalString;

View file

@ -6,6 +6,7 @@
#include "js/UbiNodeCensus.h"
#include "js/AutoByteString.h"
#include "js/StableStringChars.h"
#include "util/Text.h"
#include "vm/JSContext.h"

View file

@ -10,6 +10,7 @@
#include "mozilla/EndianUtils.h"
#include "mozilla/TypeTraits.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "NamespaceImports.h"

View file

@ -32,6 +32,7 @@
#include "builtin/String.h"
#include "frontend/Parser.h"
#include "gc/Policy.h"
#include "js/AutoByteString.h"
#include "js/MemoryMetrics.h"
#include "js/Printf.h"
#include "js/StableStringChars.h"

View file

@ -17,6 +17,7 @@
#endif
#include "jsapi.h"
#include "js/AutoByteString.h"
#include "js/Printf.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"

View file

@ -10,6 +10,7 @@
#include "AccessCheck.h"
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/Proxy.h"
#include "js/StructuredClone.h"
#include "nsContentUtils.h"

View file

@ -15,6 +15,7 @@
#include "nsContentUtils.h"
#include "nsCycleCollector.h"
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/SavedFrameAPI.h"
#include "js/StructuredClone.h"
#include "mozilla/Attributes.h"

View file

@ -21,6 +21,7 @@
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/CharacterEncoding.h"
#include "mozilla/dom/BindingUtils.h"

View file

@ -7,6 +7,7 @@
#include "nsXULAppAPI.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "js/AutoByteString.h"
#include "js/Printf.h"
#include "mozilla/ChaosMode.h"
#include "mozilla/dom/ScriptSettings.h"

View file

@ -8,6 +8,7 @@
#include "xpcprivate.h"
#include "XPCWrapper.h"
#include "js/AutoByteString.h"
#include "js/Printf.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMException.h"

View file

@ -10,6 +10,7 @@
#include "xpc_make_class.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/Preferences.h"
#include "js/AutoByteString.h"
#include "js/Class.h"
#include "js/Printf.h"

View file

@ -11,6 +11,7 @@
#include "WrapperFactory.h"
#include "jsapi.h"
#include "js/Proxy.h"
#include "js/Wrapper.h"

View file

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MozIntlHelper.h"
#include "jsapi.h"
#include "js/Wrapper.h"
#include "mozilla/ModuleUtils.h"