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

Unified Diff: src/json.js

Issue 5614004: Use the PushIfAbsent function for the JSON stringify stack.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 | « src/array.js ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
===================================================================
--- src/json.js (revision 5940)
+++ src/json.js (working copy)
@@ -66,21 +66,10 @@
}
}
-function StackContains(stack, val) {
- var length = stack.length;
- for (var i = 0; i < length; i++) {
- if (stack[i] === val) {
- return true;
- }
- }
- return false;
-}
-
function SerializeArray(value, replacer, stack, indent, gap) {
- if (StackContains(stack, value)) {
+ if (!%PushIfAbsent(stack, value)) {
throw MakeTypeError('circular_structure', []);
}
- stack.push(value);
var stepback = indent;
indent += gap;
var partial = [];
@@ -108,10 +97,9 @@
}
function SerializeObject(value, replacer, stack, indent, gap) {
- if (StackContains(stack, value)) {
+ if (!%PushIfAbsent(stack, value)) {
throw MakeTypeError('circular_structure', []);
}
- stack.push(value);
var stepback = indent;
indent += gap;
var partial = [];
@@ -197,10 +185,9 @@
function BasicSerializeArray(value, stack, builder) {
- if (StackContains(stack, value)) {
+ if (!%PushIfAbsent(stack, value)) {
throw MakeTypeError('circular_structure', []);
}
- stack.push(value);
builder.push("[");
var len = value.length;
for (var i = 0; i < len; i++) {
@@ -220,10 +207,9 @@
function BasicSerializeObject(value, stack, builder) {
- if (StackContains(stack, value)) {
+ if (!%PushIfAbsent(stack, value)) {
throw MakeTypeError('circular_structure', []);
}
- stack.push(value);
builder.push("{");
for (var p in value) {
if (%HasLocalProperty(value, p)) {
« no previous file with comments | « src/array.js ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698