OLD | NEW |
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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
| 14 var GlobalDate = global.Date; |
14 var GlobalJSON = global.JSON; | 15 var GlobalJSON = global.JSON; |
15 var GlobalSet = global.Set; | 16 var GlobalSet = global.Set; |
16 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; |
17 var MakeTypeError; | 18 var MakeTypeError; |
18 var MaxSimple; | 19 var MaxSimple; |
19 var MinSimple; | 20 var MinSimple; |
20 var ObjectHasOwnProperty; | 21 var ObjectHasOwnProperty; |
21 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
22 | 23 |
23 utils.Import(function(from) { | 24 utils.Import(function(from) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 241 |
241 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); | 242 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); |
242 | 243 |
243 // Set up non-enumerable properties of the JSON object. | 244 // Set up non-enumerable properties of the JSON object. |
244 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ | 245 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ |
245 "parse", JSONParse, | 246 "parse", JSONParse, |
246 "stringify", JSONStringify | 247 "stringify", JSONStringify |
247 ]); | 248 ]); |
248 | 249 |
249 // ------------------------------------------------------------------- | 250 // ------------------------------------------------------------------- |
| 251 // Date.toJSON |
| 252 |
| 253 // 20.3.4.37 Date.prototype.toJSON ( key ) |
| 254 function DateToJSON(key) { |
| 255 var o = TO_OBJECT(this); |
| 256 var tv = TO_PRIMITIVE_NUMBER(o); |
| 257 if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { |
| 258 return null; |
| 259 } |
| 260 return o.toISOString(); |
| 261 } |
| 262 |
| 263 // Set up non-enumerable functions of the Date prototype object. |
| 264 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ |
| 265 "toJSON", DateToJSON |
| 266 ]); |
| 267 |
| 268 // ------------------------------------------------------------------- |
250 // JSON Builtins | 269 // JSON Builtins |
251 | 270 |
252 function JsonSerializeAdapter(key, object) { | 271 function JsonSerializeAdapter(key, object) { |
253 var holder = {}; | 272 var holder = {}; |
254 holder[key] = object; | 273 holder[key] = object; |
255 // No need to pass the actual holder since there is no replacer function. | 274 // No need to pass the actual holder since there is no replacer function. |
256 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 275 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
257 } | 276 } |
258 | 277 |
259 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 278 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
260 | 279 |
261 }) | 280 }) |
OLD | NEW |