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

Side by Side Diff: src/json.js

Issue 1123353004: Revert of Wrap runtime.js in a function. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « src/i18n.js ('k') | src/macros.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var $jsonSerializeAdapter; 5 var $jsonSerializeAdapter;
6 6
7 (function() { 7 (function() {
8 8
9 "use strict"; 9 "use strict";
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return JSON_NUMBER_TO_STRING(value); 147 return JSON_NUMBER_TO_STRING(value);
148 } else if (IS_BOOLEAN(value)) { 148 } else if (IS_BOOLEAN(value)) {
149 return value ? "true" : "false"; 149 return value ? "true" : "false";
150 } else if (IS_NULL(value)) { 150 } else if (IS_NULL(value)) {
151 return "null"; 151 return "null";
152 } else if (IS_SPEC_OBJECT(value) && !(typeof value == "function")) { 152 } else if (IS_SPEC_OBJECT(value) && !(typeof value == "function")) {
153 // Non-callable object. If it's a primitive wrapper, it must be unwrapped. 153 // Non-callable object. If it's a primitive wrapper, it must be unwrapped.
154 if (IS_ARRAY(value)) { 154 if (IS_ARRAY(value)) {
155 return SerializeArray(value, replacer, stack, indent, gap); 155 return SerializeArray(value, replacer, stack, indent, gap);
156 } else if (IS_NUMBER_WRAPPER(value)) { 156 } else if (IS_NUMBER_WRAPPER(value)) {
157 value = $toNumber(value); 157 value = ToNumber(value);
158 return JSON_NUMBER_TO_STRING(value); 158 return JSON_NUMBER_TO_STRING(value);
159 } else if (IS_STRING_WRAPPER(value)) { 159 } else if (IS_STRING_WRAPPER(value)) {
160 return %QuoteJSONString($toString(value)); 160 return %QuoteJSONString(ToString(value));
161 } else if (IS_BOOLEAN_WRAPPER(value)) { 161 } else if (IS_BOOLEAN_WRAPPER(value)) {
162 return %_ValueOf(value) ? "true" : "false"; 162 return %_ValueOf(value) ? "true" : "false";
163 } else { 163 } else {
164 return SerializeObject(value, replacer, stack, indent, gap); 164 return SerializeObject(value, replacer, stack, indent, gap);
165 } 165 }
166 } 166 }
167 // Undefined or a callable object. 167 // Undefined or a callable object.
168 return UNDEFINED; 168 return UNDEFINED;
169 } 169 }
170 170
171 171
172 function JSONStringify(value, replacer, space) { 172 function JSONStringify(value, replacer, space) {
173 if (%_ArgumentsLength() == 1) { 173 if (%_ArgumentsLength() == 1) {
174 return %BasicJSONStringify(value); 174 return %BasicJSONStringify(value);
175 } 175 }
176 if (IS_OBJECT(space)) { 176 if (IS_OBJECT(space)) {
177 // Unwrap 'space' if it is wrapped 177 // Unwrap 'space' if it is wrapped
178 if (IS_NUMBER_WRAPPER(space)) { 178 if (IS_NUMBER_WRAPPER(space)) {
179 space = $toNumber(space); 179 space = ToNumber(space);
180 } else if (IS_STRING_WRAPPER(space)) { 180 } else if (IS_STRING_WRAPPER(space)) {
181 space = $toString(space); 181 space = ToString(space);
182 } 182 }
183 } 183 }
184 var gap; 184 var gap;
185 if (IS_NUMBER(space)) { 185 if (IS_NUMBER(space)) {
186 space = $max(0, $min($toInteger(space), 10)); 186 space = $max(0, $min(ToInteger(space), 10));
187 gap = %_SubString(" ", 0, space); 187 gap = %_SubString(" ", 0, space);
188 } else if (IS_STRING(space)) { 188 } else if (IS_STRING(space)) {
189 if (space.length > 10) { 189 if (space.length > 10) {
190 gap = %_SubString(space, 0, 10); 190 gap = %_SubString(space, 0, 10);
191 } else { 191 } else {
192 gap = space; 192 gap = space;
193 } 193 }
194 } else { 194 } else {
195 gap = ""; 195 gap = "";
196 } 196 }
197 if (IS_ARRAY(replacer)) { 197 if (IS_ARRAY(replacer)) {
198 // Deduplicate replacer array items. 198 // Deduplicate replacer array items.
199 var property_list = new InternalArray(); 199 var property_list = new InternalArray();
200 var seen_properties = { __proto__: null }; 200 var seen_properties = { __proto__: null };
201 var seen_sentinel = {}; 201 var seen_sentinel = {};
202 var length = replacer.length; 202 var length = replacer.length;
203 for (var i = 0; i < length; i++) { 203 for (var i = 0; i < length; i++) {
204 var item = replacer[i]; 204 var item = replacer[i];
205 if (IS_STRING_WRAPPER(item)) { 205 if (IS_STRING_WRAPPER(item)) {
206 item = $toString(item); 206 item = ToString(item);
207 } else { 207 } else {
208 if (IS_NUMBER_WRAPPER(item)) item = $toNumber(item); 208 if (IS_NUMBER_WRAPPER(item)) item = ToNumber(item);
209 if (IS_NUMBER(item)) item = %_NumberToString(item); 209 if (IS_NUMBER(item)) item = %_NumberToString(item);
210 } 210 }
211 if (IS_STRING(item) && seen_properties[item] != seen_sentinel) { 211 if (IS_STRING(item) && seen_properties[item] != seen_sentinel) {
212 property_list.push(item); 212 property_list.push(item);
213 // We cannot use true here because __proto__ needs to be an object. 213 // We cannot use true here because __proto__ needs to be an object.
214 seen_properties[item] = seen_sentinel; 214 seen_properties[item] = seen_sentinel;
215 } 215 }
216 } 216 }
217 replacer = property_list; 217 replacer = property_list;
218 } 218 }
(...skipping 14 matching lines...) Expand all
233 // JSON Builtins 233 // JSON Builtins
234 234
235 $jsonSerializeAdapter = function(key, object) { 235 $jsonSerializeAdapter = function(key, object) {
236 var holder = {}; 236 var holder = {};
237 holder[key] = object; 237 holder[key] = object;
238 // No need to pass the actual holder since there is no replacer function. 238 // No need to pass the actual holder since there is no replacer function.
239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); 239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", "");
240 } 240 }
241 241
242 })(); 242 })();
OLDNEW
« no previous file with comments | « src/i18n.js ('k') | src/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698