| 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; | |
| 15 var GlobalJSON = global.JSON; | 14 var GlobalJSON = global.JSON; |
| 16 var GlobalSet = global.Set; | 15 var GlobalSet = global.Set; |
| 17 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
| 18 var MakeTypeError; | 17 var MakeTypeError; |
| 19 var MaxSimple; | 18 var MaxSimple; |
| 20 var MinSimple; | 19 var MinSimple; |
| 21 var ObjectHasOwnProperty; | 20 var ObjectHasOwnProperty; |
| 22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 21 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 23 | 22 |
| 24 utils.Import(function(from) { | 23 utils.Import(function(from) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 240 |
| 242 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); | 241 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); |
| 243 | 242 |
| 244 // Set up non-enumerable properties of the JSON object. | 243 // Set up non-enumerable properties of the JSON object. |
| 245 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ | 244 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ |
| 246 "parse", JSONParse, | 245 "parse", JSONParse, |
| 247 "stringify", JSONStringify | 246 "stringify", JSONStringify |
| 248 ]); | 247 ]); |
| 249 | 248 |
| 250 // ------------------------------------------------------------------- | 249 // ------------------------------------------------------------------- |
| 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 // ------------------------------------------------------------------- | |
| 269 // JSON Builtins | 250 // JSON Builtins |
| 270 | 251 |
| 271 function JsonSerializeAdapter(key, object) { | 252 function JsonSerializeAdapter(key, object) { |
| 272 var holder = {}; | 253 var holder = {}; |
| 273 holder[key] = object; | 254 holder[key] = object; |
| 274 // No need to pass the actual holder since there is no replacer function. | 255 // No need to pass the actual holder since there is no replacer function. |
| 275 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 256 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 276 } | 257 } |
| 277 | 258 |
| 278 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 259 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
| 279 | 260 |
| 280 }) | 261 }) |
| OLD | NEW |