Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: src/js/json.js

Issue 1506933003: JSON.parse: properly deal with reviver result (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/js/v8natives.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/json.js
diff --git a/src/js/json.js b/src/js/json.js
index 38c46af6d617f41332126f6195cbb45e8c553958..d42b8c794a77887d4991b7a2686bd4d246f3adac 100644
--- a/src/js/json.js
+++ b/src/js/json.js
@@ -17,6 +17,7 @@ var MakeTypeError;
var MaxSimple;
var MinSimple;
var ObjectHasOwnProperty;
+var ObjectKeys;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
@@ -24,28 +25,32 @@ utils.Import(function(from) {
MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
+ ObjectKeys = from.ObjectKeys;
});
// -------------------------------------------------------------------
-function Revive(holder, name, reviver) {
+function InternalizeJSONProperty(holder, name, reviver) {
var val = holder[name];
- if (IS_OBJECT(val)) {
+ if (IS_OBJECT(val) && val !== null) {
if (IS_ARRAY(val)) {
var length = val.length;
for (var i = 0; i < length; i++) {
- var newElement = Revive(val, %_NumberToString(i), reviver);
- val[i] = newElement;
+ var newElement =
+ InternalizeJSONProperty(val, %_NumberToString(i), reviver);
+ if (IS_UNDEFINED(newElement)) {
+ delete val[i];
+ } else {
+ val[i] = newElement;
+ }
}
} else {
- for (var p in val) {
- if (HAS_OWN_PROPERTY(val, p)) {
- var newElement = Revive(val, p, reviver);
- if (IS_UNDEFINED(newElement)) {
- delete val[p];
- } else {
- val[p] = newElement;
- }
+ for (var p of ObjectKeys(val)) {
+ var newElement = InternalizeJSONProperty(val, p, reviver);
+ if (IS_UNDEFINED(newElement)) {
+ delete val[p];
+ } else {
+ val[p] = newElement;
}
}
}
@@ -57,7 +62,7 @@ function Revive(holder, name, reviver) {
function JSONParse(text, reviver) {
var unfiltered = %ParseJson(text);
if (IS_CALLABLE(reviver)) {
- return Revive({'': unfiltered}, '', reviver);
+ return InternalizeJSONProperty({'': unfiltered}, '', reviver);
} else {
return unfiltered;
}
« no previous file with comments | « no previous file | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698