mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 916993 - Handlify the public JSString APIs; r=bz,jonco
--HG-- extra : rebase_source : 35c5d7832d794ce37be622db3140309d2605c212
This commit is contained in:
parent
546a202c87
commit
77df39999e
@ -425,7 +425,7 @@ GetParamsForMessage(JSContext* aCx,
|
||||
// as a dictionary.
|
||||
nsAutoString json;
|
||||
JS::Rooted<JS::Value> v(aCx, aJSON);
|
||||
NS_ENSURE_TRUE(JS_Stringify(aCx, v.address(), nullptr, JSVAL_NULL,
|
||||
NS_ENSURE_TRUE(JS_Stringify(aCx, &v, JS::NullPtr(), JS::NullHandleValue,
|
||||
JSONCreator, &json), false);
|
||||
NS_ENSURE_TRUE(!json.IsEmpty(), false);
|
||||
|
||||
@ -872,7 +872,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
funval, 1, argv.address(), rval.address());
|
||||
if (aJSONRetVal) {
|
||||
nsString json;
|
||||
if (JS_Stringify(ctx, rval.address(), nullptr, JSVAL_NULL,
|
||||
if (JS_Stringify(ctx, &rval, JS::NullPtr(), JS::NullHandleValue,
|
||||
JSONCreator, &json)) {
|
||||
aJSONRetVal->AppendElement(json);
|
||||
}
|
||||
|
@ -1484,7 +1484,7 @@ MainThreadDictionaryBase::ParseJSON(JSContext *aCx,
|
||||
}
|
||||
|
||||
static JSString*
|
||||
ConcatJSString(JSContext* cx, const char* pre, JSString* str, const char* post)
|
||||
ConcatJSString(JSContext* cx, const char* pre, JS::Handle<JSString*> str, const char* post)
|
||||
{
|
||||
if (!str) {
|
||||
return nullptr;
|
||||
@ -1496,12 +1496,12 @@ ConcatJSString(JSContext* cx, const char* pre, JSString* str, const char* post)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
str = JS_ConcatStrings(cx, preString, str);
|
||||
if (!str) {
|
||||
preString = JS_ConcatStrings(cx, preString, str);
|
||||
if (!preString) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return JS_ConcatStrings(cx, str, postString);
|
||||
return JS_ConcatStrings(cx, preString, postString);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1544,8 +1544,8 @@ NativeToString(JSContext* cx, JS::Handle<JSObject*> wrapper,
|
||||
} else {
|
||||
const js::Class* clasp = js::GetObjectClass(obj);
|
||||
if (IsDOMClass(clasp)) {
|
||||
str = ConcatJSString(cx, "[object ",
|
||||
JS_NewStringCopyZ(cx, clasp->name), "]");
|
||||
str = JS_NewStringCopyZ(cx, clasp->name);
|
||||
str = ConcatJSString(cx, "[object ", str, "]");
|
||||
} else if (IsDOMIfaceAndProtoClass(clasp)) {
|
||||
const DOMIfaceAndProtoJSClass* ifaceAndProtoJSClass =
|
||||
DOMIfaceAndProtoJSClass::FromJSClass(clasp);
|
||||
|
@ -886,8 +886,9 @@ nsJSObjWrapper::NP_Enumerate(NPObject *npobj, NPIdentifier **idarray,
|
||||
}
|
||||
|
||||
NPIdentifier id;
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
JSString *str = JS_InternJSString(cx, JSVAL_TO_STRING(v));
|
||||
if (v.isString()) {
|
||||
JS::Rooted<JSString*> str(cx, v.toString());
|
||||
str = JS_InternJSString(cx, str);
|
||||
if (!str) {
|
||||
PR_Free(*idarray);
|
||||
return false;
|
||||
@ -1398,7 +1399,8 @@ CallNPMethodInternal(JSContext *cx, JS::Handle<JSObject*> obj, unsigned argc,
|
||||
|
||||
if (npobj->_class->invoke) {
|
||||
JSFunction *fun = ::JS_GetObjectFunction(funobj);
|
||||
JSString *name = ::JS_InternJSString(cx, ::JS_GetFunctionId(fun));
|
||||
JS::Rooted<JSString*> funId(cx, ::JS_GetFunctionId(fun));
|
||||
JSString *name = ::JS_InternJSString(cx, funId);
|
||||
NPIdentifier id = StringToNPIdentifier(cx, name);
|
||||
|
||||
ok = npobj->_class->invoke(npobj, id, npargs, argc, &v);
|
||||
|
@ -31,7 +31,7 @@ PluginIdentifierParent::RecvRetain()
|
||||
|
||||
// The following is what nsNPAPIPlugin.cpp does. Gross, but the API doesn't
|
||||
// give you a NPP to play with.
|
||||
JSString* str = JSID_TO_STRING(id);
|
||||
JS::RootedString str(cx, JSID_TO_STRING(id));
|
||||
JSString* str2 = JS_InternJSString(cx, str);
|
||||
if (!str2) {
|
||||
return false;
|
||||
|
@ -1046,7 +1046,7 @@ PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray<PPluginIdentifier
|
||||
// Because of GC hazards, all identifiers returned from enumerate
|
||||
// must be made permanent.
|
||||
if (_identifierisstring(ids[index])) {
|
||||
JSString* str = NPIdentifierToString(ids[index]);
|
||||
JS::RootedString str(cx, NPIdentifierToString(ids[index]));
|
||||
if (!JS_StringHasBeenInterned(cx, str)) {
|
||||
DebugOnly<JSString*> str2 = JS_InternJSString(cx, str);
|
||||
NS_ASSERTION(str2 == str, "Interning a JS string which is currently an ID should return itself.");
|
||||
|
@ -181,9 +181,11 @@ nsJSON::EncodeFromJSVal(JS::Value *value, JSContext *cx, nsAString &result)
|
||||
}
|
||||
|
||||
nsJSONWriter writer;
|
||||
if (!JS_Stringify(cx, value, NULL, JSVAL_NULL, WriteCallback, &writer)) {
|
||||
JS::Rooted<JS::Value> vp(cx, *value);
|
||||
if (!JS_Stringify(cx, &vp, JS::NullPtr(), JS::NullHandleValue, WriteCallback, &writer)) {
|
||||
return NS_ERROR_XPC_BAD_CONVERT_JS;
|
||||
}
|
||||
*value = vp;
|
||||
|
||||
NS_ENSURE_TRUE(writer.DidWrite(), NS_ERROR_UNEXPECTED);
|
||||
writer.FlushBuffer();
|
||||
@ -240,7 +242,7 @@ nsJSON::EncodeInternal(JSContext* cx, const JS::Value& aValue,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// We're good now; try to stringify
|
||||
if (!JS_Stringify(cx, val.address(), NULL, JSVAL_NULL, WriteCallback, writer))
|
||||
if (!JS_Stringify(cx, &val, JS::NullPtr(), JS::NullHandleValue, WriteCallback, writer))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
@ -528,7 +530,7 @@ nsJSONListener::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
|
||||
mBufferedChars.Length());
|
||||
bool ok = JS_ParseJSONWithReviver(mCx, chars.get(),
|
||||
uint32_t(mBufferedChars.Length()),
|
||||
reviver, value.address());
|
||||
reviver, &value);
|
||||
|
||||
*mRootVal = value;
|
||||
mBufferedChars.TruncateLength(0);
|
||||
|
@ -30,8 +30,8 @@ EventTarget::GetEventListener(const nsAString& aType, ErrorResult& aRv) const
|
||||
{
|
||||
JSContext* cx = GetJSContext();
|
||||
|
||||
JSString* type =
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
||||
JS::RootedString type(cx,
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()));
|
||||
if (!type || !(type = JS_InternJSString(cx, type))) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return NULL;
|
||||
@ -47,8 +47,8 @@ EventTarget::SetEventListener(const nsAString& aType,
|
||||
{
|
||||
JSContext* cx = GetJSContext();
|
||||
|
||||
JSString* type =
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
||||
JS::RootedString type(cx,
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()));
|
||||
if (!type || !(type = JS_InternJSString(cx, type))) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
@ -70,8 +70,8 @@ EventTarget::AddEventListener(const nsAString& aType,
|
||||
|
||||
JSContext* cx = GetJSContext();
|
||||
|
||||
JSString* type =
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
||||
JS::RootedString type(cx,
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()));
|
||||
if (!type || !(type = JS_InternJSString(cx, type))) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
@ -94,8 +94,8 @@ EventTarget::RemoveEventListener(const nsAString& aType,
|
||||
|
||||
JSContext* cx = GetJSContext();
|
||||
|
||||
JSString* type =
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length());
|
||||
JS::RootedString type(cx,
|
||||
JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()));
|
||||
if (!type || !(type = JS_InternJSString(cx, type))) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
|
@ -844,7 +844,7 @@ public:
|
||||
}
|
||||
|
||||
static JSObject*
|
||||
Create(JSContext* aCx, JS::Handle<JSObject*> aParent, JSString* aType,
|
||||
Create(JSContext* aCx, JS::Handle<JSObject*> aParent, JS::Handle<JSString*> aType,
|
||||
bool aLengthComputable, double aLoaded, double aTotal)
|
||||
{
|
||||
JS::Rooted<JSString*> type(aCx, JS_InternJSString(aCx, aType));
|
||||
@ -1041,7 +1041,7 @@ CreateErrorEvent(JSContext* aCx, JS::Handle<JSString*> aMessage,
|
||||
}
|
||||
|
||||
JSObject*
|
||||
CreateProgressEvent(JSContext* aCx, JSString* aType, bool aLengthComputable,
|
||||
CreateProgressEvent(JSContext* aCx, JS::Handle<JSString*> aType, bool aLengthComputable,
|
||||
double aLoaded, double aTotal)
|
||||
{
|
||||
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
|
@ -32,8 +32,8 @@ CreateErrorEvent(JSContext* aCx, JS::Handle<JSString*> aMessage,
|
||||
uint32_t aLineNumber, bool aMainRuntime);
|
||||
|
||||
JSObject*
|
||||
CreateProgressEvent(JSContext* aCx, JSString* aType, bool aLengthComputable,
|
||||
double aLoaded, double aTotal);
|
||||
CreateProgressEvent(JSContext* aCx, JS::Handle<JSString*> aType,
|
||||
bool aLengthComputable, double aLoaded, double aTotal);
|
||||
|
||||
bool
|
||||
IsSupportedEventClass(JSObject* aEvent);
|
||||
|
@ -257,7 +257,7 @@ TryParse(JSContext *cx, const char (&input)[N], JS::HandleValue filter)
|
||||
AutoInflatedString str(cx);
|
||||
JS::RootedValue v(cx);
|
||||
str = input;
|
||||
CHECK(JS_ParseJSONWithReviver(cx, str.chars(), str.length(), filter, v.address()));
|
||||
CHECK(JS_ParseJSONWithReviver(cx, str.chars(), str.length(), filter, &v));
|
||||
CHECK_SAME(v, JSVAL_NULL);
|
||||
return true;
|
||||
}
|
||||
|
@ -5269,7 +5269,7 @@ INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_InternJSString(JSContext *cx, JSString *str)
|
||||
JS_InternJSString(JSContext *cx, HandleString str)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
@ -5480,7 +5480,7 @@ JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_NewDependentString(JSContext *cx, JSString *str, size_t start, size_t length)
|
||||
JS_NewDependentString(JSContext *cx, HandleString str, size_t start, size_t length)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
@ -5488,13 +5488,11 @@ JS_NewDependentString(JSContext *cx, JSString *str, size_t start, size_t length)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right)
|
||||
JS_ConcatStrings(JSContext *cx, HandleString left, HandleString right)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
Rooted<JSString*> lstr(cx, left);
|
||||
Rooted<JSString*> rstr(cx, right);
|
||||
return ConcatStrings<CanGC>(cx, lstr, rstr);
|
||||
return ConcatStrings<CanGC>(cx, left, right);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
@ -5571,19 +5569,15 @@ JS_EncodeStringToBuffer(JSContext *cx, JSString *str, char *buffer, size_t lengt
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacerArg, jsval space,
|
||||
JSONWriteCallback callback, void *data)
|
||||
JS_Stringify(JSContext *cx, MutableHandleValue vp, HandleObject replacer,
|
||||
HandleValue space, JSONWriteCallback callback, void *data)
|
||||
{
|
||||
RootedObject replacer(cx, replacerArg);
|
||||
RootedValue value(cx, *vp);
|
||||
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, replacer, space);
|
||||
StringBuffer sb(cx);
|
||||
if (!js_Stringify(cx, &value, replacer, space, sb))
|
||||
if (!js_Stringify(cx, vp, replacer, space, sb))
|
||||
return false;
|
||||
*vp = value;
|
||||
if (sb.empty()) {
|
||||
HandlePropertyName null = cx->names().null;
|
||||
return callback(null->chars(), null->length(), data);
|
||||
@ -5597,22 +5591,16 @@ JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandle
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
RootedValue reviver(cx, NullValue()), value(cx);
|
||||
RootedValue reviver(cx, NullValue());
|
||||
return ParseJSONWithReviver(cx, JS::StableCharPtr(chars, len), len, reviver, vp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, jsval reviverArg, jsval *vp)
|
||||
JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, HandleValue reviver, MutableHandleValue vp)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
RootedValue reviver(cx, reviverArg), value(cx);
|
||||
if (!ParseJSONWithReviver(cx, StableCharPtr(chars, len), len, reviver, &value))
|
||||
return false;
|
||||
|
||||
*vp = value;
|
||||
return true;
|
||||
return ParseJSONWithReviver(cx, StableCharPtr(chars, len), len, reviver, vp);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -3599,7 +3599,7 @@ extern JS_PUBLIC_API(JSString *)
|
||||
JS_NewStringCopyZ(JSContext *cx, const char *s);
|
||||
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_InternJSString(JSContext *cx, JSString *str);
|
||||
JS_InternJSString(JSContext *cx, JS::HandleString str);
|
||||
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_InternStringN(JSContext *cx, const char *s, size_t length);
|
||||
@ -3736,7 +3736,7 @@ JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
|
||||
* are mutable by definition, so the thread safety comments above apply.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
|
||||
JS_NewDependentString(JSContext *cx, JS::HandleString str, size_t start,
|
||||
size_t length);
|
||||
|
||||
/*
|
||||
@ -3744,7 +3744,7 @@ JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
|
||||
* See above for thread safety comments.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSString *)
|
||||
JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
|
||||
JS_ConcatStrings(JSContext *cx, JS::HandleString left, JS::HandleString right);
|
||||
|
||||
/*
|
||||
* For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before
|
||||
@ -3876,18 +3876,18 @@ typedef bool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data);
|
||||
* JSON.stringify as specified by ES5.
|
||||
*/
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
|
||||
JSONWriteCallback callback, void *data);
|
||||
JS_Stringify(JSContext *cx, JS::MutableHandleValue value, JS::HandleObject replacer,
|
||||
JS::HandleValue space, JSONWriteCallback callback, void *data);
|
||||
|
||||
/*
|
||||
* JSON.parse as specified by ES5.
|
||||
*/
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandle<JS::Value> vp);
|
||||
JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, JS::MutableHandleValue vp);
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, jsval reviver,
|
||||
jsval *vp);
|
||||
JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, JS::HandleValue reviver,
|
||||
JS::MutableHandleValue vp);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
|
@ -71,7 +71,7 @@ SaveProfileTask::Run() {
|
||||
JSAutoCompartment autoComp(cx, obj);
|
||||
JSObject* profileObj = profiler_get_profile_jsobject(cx);
|
||||
JS::Rooted<JS::Value> val(cx, OBJECT_TO_JSVAL(profileObj));
|
||||
JS_Stringify(cx, val.address(), nullptr, JSVAL_NULL, WriteCallback, &stream);
|
||||
JS_Stringify(cx, &val, JS::NullPtr(), JS::NullHandleValue, WriteCallback, &stream);
|
||||
stream.close();
|
||||
LOGF("Saved to %s", tmpPath.get());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user