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]); |