mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1036703 - Manage TokenStream::{sourceMap,display}URL_ using UniquePtr. r=jimb
--HG-- extra : rebase_source : 063beaeb184059b6a03338f05f4d073a5ea8bf27
This commit is contained in:
parent
0a295cbf0b
commit
04afd90124
@ -406,6 +406,25 @@ SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits)
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
namespace JS {
|
||||
|
||||
template<typename T>
|
||||
struct DeletePolicy
|
||||
{
|
||||
void operator()(T* ptr) {
|
||||
js_delete(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
struct FreePolicy
|
||||
{
|
||||
void operator()(void* ptr) {
|
||||
js_free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace JS
|
||||
|
||||
namespace js {
|
||||
|
||||
/* Integral types for all hash functions. */
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "frontend/TokenStream.h"
|
||||
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
@ -35,6 +36,7 @@ using mozilla::Maybe;
|
||||
using mozilla::PodAssign;
|
||||
using mozilla::PodCopy;
|
||||
using mozilla::PodZero;
|
||||
using mozilla::UniquePtr;
|
||||
|
||||
struct KeywordInfo {
|
||||
const char *chars; // C string with keyword text
|
||||
@ -354,9 +356,6 @@ TokenStream::TokenStream(ExclusiveContext *cx, const ReadOnlyCompileOptions &opt
|
||||
|
||||
TokenStream::~TokenStream()
|
||||
{
|
||||
js_free(displayURL_);
|
||||
js_free(sourceMapURL_);
|
||||
|
||||
JS_ASSERT_IF(originPrincipals, originPrincipals->refcount);
|
||||
}
|
||||
|
||||
@ -854,7 +853,9 @@ TokenStream::getDirectives(bool isMultiline, bool shouldWarnDeprecated)
|
||||
bool
|
||||
TokenStream::getDirective(bool isMultiline, bool shouldWarnDeprecated,
|
||||
const char *directive, int directiveLength,
|
||||
const char *errorMsgPragma, jschar **destination) {
|
||||
const char *errorMsgPragma,
|
||||
UniquePtr<jschar[], JS::FreePolicy> *destination)
|
||||
{
|
||||
JS_ASSERT(directiveLength <= 18);
|
||||
jschar peeked[18];
|
||||
int32_t c;
|
||||
@ -886,12 +887,11 @@ TokenStream::getDirective(bool isMultiline, bool shouldWarnDeprecated,
|
||||
|
||||
size_t length = tokenbuf.length();
|
||||
|
||||
js_free(*destination);
|
||||
*destination = cx->pod_malloc<jschar>(length + 1);
|
||||
*destination = cx->make_pod_array<jschar>(length + 1);
|
||||
if (!*destination)
|
||||
return false;
|
||||
|
||||
PodCopy(*destination, tokenbuf.begin(), length);
|
||||
PodCopy(destination->get(), tokenbuf.begin(), length);
|
||||
(*destination)[length] = '\0';
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/PodOperations.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
@ -642,7 +643,7 @@ class MOZ_STACK_CLASS TokenStream
|
||||
}
|
||||
|
||||
jschar *displayURL() {
|
||||
return displayURL_;
|
||||
return displayURL_.get();
|
||||
}
|
||||
|
||||
bool hasSourceMapURL() const {
|
||||
@ -650,7 +651,7 @@ class MOZ_STACK_CLASS TokenStream
|
||||
}
|
||||
|
||||
jschar *sourceMapURL() {
|
||||
return sourceMapURL_;
|
||||
return sourceMapURL_.get();
|
||||
}
|
||||
|
||||
// If the name at s[0:length] is not a keyword in this version, return
|
||||
@ -856,7 +857,8 @@ class MOZ_STACK_CLASS TokenStream
|
||||
bool getDirectives(bool isMultiline, bool shouldWarnDeprecated);
|
||||
bool getDirective(bool isMultiline, bool shouldWarnDeprecated,
|
||||
const char *directive, int directiveLength,
|
||||
const char *errorMsgPragma, jschar **destination);
|
||||
const char *errorMsgPragma,
|
||||
mozilla::UniquePtr<jschar[], JS::FreePolicy> *destination);
|
||||
bool getDisplayURL(bool isMultiline, bool shouldWarnDeprecated);
|
||||
bool getSourceMappingURL(bool isMultiline, bool shouldWarnDeprecated);
|
||||
|
||||
@ -898,8 +900,8 @@ class MOZ_STACK_CLASS TokenStream
|
||||
const jschar *prevLinebase; // start of previous line; nullptr if on the first line
|
||||
TokenBuf userbuf; // user input buffer
|
||||
const char *filename; // input filename or null
|
||||
jschar *displayURL_; // the user's requested source URL or null
|
||||
jschar *sourceMapURL_; // source map's filename or null
|
||||
mozilla::UniquePtr<jschar[], JS::FreePolicy> displayURL_; // the user's requested source URL or null
|
||||
mozilla::UniquePtr<jschar[], JS::FreePolicy> sourceMapURL_; // source map's filename or null
|
||||
CharBuffer tokenbuf; // current token string buffer
|
||||
bool maybeEOL[256]; // probabilistic EOL lookup table
|
||||
bool maybeStrSpecial[256]; // speeds up string scanning
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "js/Utility.h"
|
||||
|
||||
@ -106,7 +107,14 @@ struct MallocProvider
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *pod_calloc(size_t numElems, JSCompartment *comp = nullptr, JSContext *cx = nullptr) {
|
||||
mozilla::UniquePtr<T[], JS::FreePolicy>
|
||||
make_pod_array(size_t numElems) {
|
||||
return mozilla::UniquePtr<T[], JS::FreePolicy>(pod_malloc<T>(numElems));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *
|
||||
pod_calloc(size_t numElems, JSCompartment *comp = nullptr, JSContext *cx = nullptr) {
|
||||
if (numElems & mozilla::tl::MulOverflowMask<sizeof(T)>::value) {
|
||||
Client *client = static_cast<Client *>(this);
|
||||
client->reportAllocationOverflow();
|
||||
|
Loading…
Reference in New Issue
Block a user