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

Side by Side Diff: src/json.js

Issue 1065863003: Use array literals instead of array constructor in native javascript. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase and fix Created 5 years, 8 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/harmony-typedarray.js ('k') | src/math.js » ('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 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declarations have been made 7 // This file relies on the fact that the following declarations have been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Array = global.Array; 9 // var $Array = global.Array;
10 // var $String = global.String; 10 // var $String = global.String;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 var unfiltered = %ParseJson(TO_STRING_INLINE(text)); 42 var unfiltered = %ParseJson(TO_STRING_INLINE(text));
43 if (IS_SPEC_FUNCTION(reviver)) { 43 if (IS_SPEC_FUNCTION(reviver)) {
44 return Revive({'': unfiltered}, '', reviver); 44 return Revive({'': unfiltered}, '', reviver);
45 } else { 45 } else {
46 return unfiltered; 46 return unfiltered;
47 } 47 }
48 } 48 }
49 49
50 function SerializeArray(value, replacer, stack, indent, gap) { 50 function SerializeArray(value, replacer, stack, indent, gap) {
51 if (!%PushIfAbsent(stack, value)) { 51 if (!%PushIfAbsent(stack, value)) {
52 throw MakeTypeError('circular_structure', $Array()); 52 throw MakeTypeError('circular_structure', []);
53 } 53 }
54 var stepback = indent; 54 var stepback = indent;
55 indent += gap; 55 indent += gap;
56 var partial = new InternalArray(); 56 var partial = new InternalArray();
57 var len = value.length; 57 var len = value.length;
58 for (var i = 0; i < len; i++) { 58 for (var i = 0; i < len; i++) {
59 var strP = JSONSerialize($String(i), value, replacer, stack, 59 var strP = JSONSerialize($String(i), value, replacer, stack,
60 indent, gap); 60 indent, gap);
61 if (IS_UNDEFINED(strP)) { 61 if (IS_UNDEFINED(strP)) {
62 strP = "null"; 62 strP = "null";
63 } 63 }
64 partial.push(strP); 64 partial.push(strP);
65 } 65 }
66 var final; 66 var final;
67 if (gap == "") { 67 if (gap == "") {
68 final = "[" + partial.join(",") + "]"; 68 final = "[" + partial.join(",") + "]";
69 } else if (partial.length > 0) { 69 } else if (partial.length > 0) {
70 var separator = ",\n" + indent; 70 var separator = ",\n" + indent;
71 final = "[\n" + indent + partial.join(separator) + "\n" + 71 final = "[\n" + indent + partial.join(separator) + "\n" +
72 stepback + "]"; 72 stepback + "]";
73 } else { 73 } else {
74 final = "[]"; 74 final = "[]";
75 } 75 }
76 stack.pop(); 76 stack.pop();
77 return final; 77 return final;
78 } 78 }
79 79
80 function SerializeObject(value, replacer, stack, indent, gap) { 80 function SerializeObject(value, replacer, stack, indent, gap) {
81 if (!%PushIfAbsent(stack, value)) { 81 if (!%PushIfAbsent(stack, value)) {
82 throw MakeTypeError('circular_structure', $Array()); 82 throw MakeTypeError('circular_structure', []);
83 } 83 }
84 var stepback = indent; 84 var stepback = indent;
85 indent += gap; 85 indent += gap;
86 var partial = new InternalArray(); 86 var partial = new InternalArray();
87 if (IS_ARRAY(replacer)) { 87 if (IS_ARRAY(replacer)) {
88 var length = replacer.length; 88 var length = replacer.length;
89 for (var i = 0; i < length; i++) { 89 for (var i = 0; i < length; i++) {
90 if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) { 90 if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) {
91 var p = replacer[i]; 91 var p = replacer[i];
92 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); 92 var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 217
218 // ------------------------------------------------------------------- 218 // -------------------------------------------------------------------
219 219
220 function SetUpJSON() { 220 function SetUpJSON() {
221 %CheckIsBootstrapping(); 221 %CheckIsBootstrapping();
222 222
223 %AddNamedProperty($JSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); 223 %AddNamedProperty($JSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM);
224 224
225 // Set up non-enumerable properties of the JSON object. 225 // Set up non-enumerable properties of the JSON object.
226 InstallFunctions($JSON, DONT_ENUM, $Array( 226 InstallFunctions($JSON, DONT_ENUM, [
227 "parse", JSONParse, 227 "parse", JSONParse,
228 "stringify", JSONStringify 228 "stringify", JSONStringify
229 )); 229 ]);
230 } 230 }
231 231
232 SetUpJSON(); 232 SetUpJSON();
233 233
234 234
235 // ------------------------------------------------------------------- 235 // -------------------------------------------------------------------
236 // JSON Builtins 236 // JSON Builtins
237 237
238 function JSONSerializeAdapter(key, object) { 238 function JSONSerializeAdapter(key, object) {
239 var holder = {}; 239 var holder = {};
240 holder[key] = object; 240 holder[key] = object;
241 // No need to pass the actual holder since there is no replacer function. 241 // No need to pass the actual holder since there is no replacer function.
242 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); 242 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", "");
243 } 243 }
OLDNEW
« no previous file with comments | « src/harmony-typedarray.js ('k') | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698