Skip to content

Commit

Permalink
Bug 1860887 - Pass ParseRecordObject parameter to InternalizeJSONProp…
Browse files Browse the repository at this point in the history
…erty and create context object r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D193471
  • Loading branch information
bthrall committed Feb 2, 2024
1 parent 619b960 commit 3c81fbf
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions js/src/builtin/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "builtin/Array.h"
#include "builtin/BigInt.h"
#include "builtin/ParseRecordObject.h"
#include "js/friend/ErrorMessages.h" // js::GetErrorMessage, JSMSG_*
#include "js/friend/StackLimits.h" // js::AutoCheckRecursionLimit
#include "js/Object.h" // JS::GetBuiltinClass
Expand Down Expand Up @@ -1720,6 +1721,7 @@ bool js::Stringify(JSContext* cx, MutableHandleValue vp, JSObject* replacer_,
/* https://262.ecma-international.org/14.0/#sec-internalizejsonproperty */
static bool InternalizeJSONProperty(JSContext* cx, HandleObject holder,
HandleId name, HandleValue reviver,
ParseRecordObject* parseRecord,
MutableHandleValue vp) {
AutoCheckRecursionLimit recursion(cx);
if (!recursion.check(cx)) {
Expand Down Expand Up @@ -1761,7 +1763,9 @@ static bool InternalizeJSONProperty(JSContext* cx, HandleObject holder,
}

/* Step 2a(iii)(1). */
if (!InternalizeJSONProperty(cx, obj, id, reviver, &newElement)) {
ParseRecordObject* elementRecord(nullptr);
if (!InternalizeJSONProperty(cx, obj, id, reviver, elementRecord,
&newElement)) {
return false;
}

Expand Down Expand Up @@ -1800,7 +1804,9 @@ static bool InternalizeJSONProperty(JSContext* cx, HandleObject holder,

/* Step 2c(ii)(1). */
id = keys[i];
if (!InternalizeJSONProperty(cx, obj, id, reviver, &newElement)) {
ParseRecordObject* entryRecord(nullptr);
if (!InternalizeJSONProperty(cx, obj, id, reviver, entryRecord,
&newElement)) {
return false;
}

Expand Down Expand Up @@ -1833,9 +1839,17 @@ static bool InternalizeJSONProperty(JSContext* cx, HandleObject holder,

RootedValue keyVal(cx, StringValue(key));
#ifdef ENABLE_JSON_PARSE_WITH_SOURCE
if (cx->realm()->creationOptions().getJSONParseWithSource()) {
RootedValue parseRecord(cx, JS::UndefinedValue());
return js::Call(cx, reviver, holder, keyVal, val, parseRecord, vp);
if (cx->realm()->creationOptions().getJSONParseWithSource() && parseRecord) {
RootedObject context(cx, NewPlainObject(cx));
if (!context) {
return false;
}
Rooted<Value> parseNode(cx, StringValue(parseRecord->parseNode));
if (!DefineDataProperty(cx, context, cx->names().source, parseNode)) {
return false;
}
RootedValue contextVal(cx, ObjectValue(*context));
return js::Call(cx, reviver, holder, keyVal, val, contextVal, vp);
}
#endif
return js::Call(cx, reviver, holder, keyVal, val, vp);
Expand All @@ -1852,7 +1866,19 @@ static bool Revive(JSContext* cx, HandleValue reviver, MutableHandleValue vp) {
}

Rooted<jsid> id(cx, NameToId(cx->names().empty_));
return InternalizeJSONProperty(cx, obj, id, reviver, vp);
ParseRecordObject snapshot;
#ifdef ENABLE_JSON_PARSE_WITH_SOURCE
// TODO: get parseNode value somehow!
Rooted<JSString*> parseNode(cx, JS_NewStringCopyZ(cx, "1"));
if (!parseNode) {
return false;
}
Rooted<Value> val(cx, ObjectValue(*obj));
snapshot.parseNode = parseNode;
snapshot.key = id;
snapshot.value = vp;
#endif
return InternalizeJSONProperty(cx, obj, id, reviver, &snapshot, vp);
}

template <typename CharT>
Expand Down

0 comments on commit 3c81fbf

Please sign in to comment.