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 1775403008: Replace PushIfAbsent by a Stack object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months 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 | « src/js/array.js ('k') | src/objects.h » ('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 ddd081bab11bf7dfa5c0fcef7385c247e56443f3..c6dbed9cbbf7f0923bc446387f6f9c7f700f8d27 100644
--- a/src/js/json.js
+++ b/src/js/json.js
@@ -19,6 +19,10 @@ var MakeTypeError;
var MaxSimple;
var MinSimple;
var ObjectHasOwnProperty;
+var Stack;
+var StackHas;
+var StackPop;
+var StackPush;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
@@ -26,6 +30,10 @@ utils.Import(function(from) {
MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
+ Stack = from.Stack;
+ StackHas = from.StackHas;
+ StackPop = from.StackPop;
+ StackPush = from.StackPush;
});
// -------------------------------------------------------------------
@@ -78,7 +86,8 @@ function JSONParse(text, reviver) {
function SerializeArray(value, replacer, stack, indent, gap) {
- if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure);
+ if (StackHas(stack, value)) throw MakeTypeError(kCircularStructure);
+ StackPush(stack, value);
var stepback = indent;
indent += gap;
var partial = new InternalArray();
@@ -101,13 +110,14 @@ function SerializeArray(value, replacer, stack, indent, gap) {
} else {
final = "[]";
}
- stack.pop();
+ StackPop(stack);
return final;
}
function SerializeObject(value, replacer, stack, indent, gap) {
- if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure);
+ if (StackHas(stack, value)) throw MakeTypeError(kCircularStructure);
+ StackPush(stack, value);
var stepback = indent;
indent += gap;
var partial = new InternalArray();
@@ -146,7 +156,7 @@ function SerializeObject(value, replacer, stack, indent, gap) {
} else {
final = "{}";
}
- stack.pop();
+ StackPop(stack);
return final;
}
@@ -241,7 +251,7 @@ function JSONStringify(value, replacer, space) {
if (!IS_CALLABLE(replacer) && !property_list && !gap && !IS_PROXY(value)) {
return %BasicJSONStringify(value);
}
- return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap);
+ return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap);
}
// -------------------------------------------------------------------
@@ -279,7 +289,7 @@ function JsonSerializeAdapter(key, object) {
var holder = {};
holder[key] = object;
// No need to pass the actual holder since there is no replacer function.
- return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", "");
+ return JSONSerialize(key, holder, UNDEFINED, new Stack(), "", "");
}
%InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]);
« no previous file with comments | « src/js/array.js ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698