mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 868637 - Simplify DOM Bindings JSON parsing. r=bz
At this point we could really just hoist the JSAPI call, but it's just cumbersome enough with all the casts that I don't really want to stick it in the codegen.
This commit is contained in:
parent
2e95fb1c15
commit
609401db48
@ -34,10 +34,8 @@ namespace dom {
|
||||
struct MainThreadDictionaryBase
|
||||
{
|
||||
protected:
|
||||
JSContext* ParseJSON(const nsAString& aJSON,
|
||||
Maybe<JSAutoRequest>& aAr,
|
||||
Maybe<JSAutoCompartment>& aAc,
|
||||
Maybe< JS::Rooted<JS::Value> >& aVal);
|
||||
bool ParseJSON(JSContext *aCx, const nsAString& aJSON,
|
||||
JS::MutableHandle<JS::Value> aVal);
|
||||
};
|
||||
|
||||
struct EnumEntry {
|
||||
|
@ -1311,26 +1311,17 @@ SetXrayExpandoChain(JSObject* obj, JSObject* chain)
|
||||
}
|
||||
}
|
||||
|
||||
JSContext*
|
||||
MainThreadDictionaryBase::ParseJSON(const nsAString& aJSON,
|
||||
Maybe<JSAutoRequest>& aAr,
|
||||
Maybe<JSAutoCompartment>& aAc,
|
||||
Maybe< JS::Rooted<JS::Value> >& aVal)
|
||||
bool
|
||||
MainThreadDictionaryBase::ParseJSON(JSContext *aCx,
|
||||
const nsAString& aJSON,
|
||||
JS::MutableHandle<JS::Value> aVal)
|
||||
{
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> global(cx, JS_GetGlobalObject(cx));
|
||||
aAr.construct(static_cast<JSContext*>(cx));
|
||||
aAc.construct(static_cast<JSContext*>(cx), global);
|
||||
aVal.construct(static_cast<JSContext*>(cx), JS::UndefinedValue());
|
||||
if (aJSON.IsEmpty()) {
|
||||
return cx;
|
||||
return true;
|
||||
}
|
||||
if (!JS_ParseJSON(cx,
|
||||
static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
|
||||
aJSON.Length(), aVal.ref().address())) {
|
||||
return nullptr;
|
||||
}
|
||||
return cx;
|
||||
return JS_ParseJSON(aCx,
|
||||
static_cast<const jschar*>(PromiseFlatString(aJSON).get()),
|
||||
aJSON.Length(), aVal.address());
|
||||
}
|
||||
|
||||
static JSString*
|
||||
|
@ -7350,19 +7350,10 @@ class CGDictionary(CGThing):
|
||||
return (string.Template(
|
||||
"struct ${selfName} ${inheritance}{\n"
|
||||
" ${selfName}() {}\n"
|
||||
" bool Init(JSContext* cx, JS::Handle<JS::Value> val);\n"
|
||||
" bool Init(JSContext* cx, JS::Handle<JS::Value> val);\n" +
|
||||
(" bool Init(const nsAString& aJSON);\n" if not self.workers else "") +
|
||||
" bool ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const;\n"
|
||||
"\n" +
|
||||
(" bool Init(const nsAString& aJSON)\n"
|
||||
" {\n"
|
||||
" Maybe<JSAutoRequest> ar;\n"
|
||||
" Maybe<JSAutoCompartment> ac;\n"
|
||||
" Maybe< JS::Rooted<JS::Value> > json;\n"
|
||||
" JSContext* cx = ParseJSON(aJSON, ar, ac, json);\n"
|
||||
" NS_ENSURE_TRUE(cx, false);\n"
|
||||
" return Init(cx, json.ref());\n"
|
||||
" }\n" if not self.workers else "") +
|
||||
"\n" +
|
||||
"\n".join(memberDecls) + "\n"
|
||||
"private:\n"
|
||||
" // Disallow copy-construction\n"
|
||||
@ -7454,6 +7445,17 @@ class CGDictionary(CGThing):
|
||||
"${initMembers}\n"
|
||||
" return true;\n"
|
||||
"}\n"
|
||||
"\n" +
|
||||
("bool\n"
|
||||
"${selfName}::Init(const nsAString& aJSON)\n"
|
||||
"{\n"
|
||||
" AutoSafeJSContext cx;\n"
|
||||
" JSAutoRequest ar(cx);\n"
|
||||
" JS::Rooted<JS::Value> json(cx);\n"
|
||||
" bool ok = ParseJSON(cx, aJSON, &json);\n"
|
||||
" NS_ENSURE_TRUE(ok, false);\n"
|
||||
" return Init(cx, json);\n"
|
||||
"}\n" if not self.workers else "") +
|
||||
"\n"
|
||||
"bool\n"
|
||||
"${selfName}::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const\n"
|
||||
|
Loading…
Reference in New Issue
Block a user