Skip to content

Commit

Permalink
JSON2 library was updated to version of June 12, 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
Taritsyn committed Nov 20, 2018
1 parent 1c46aae commit 4a65499
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
3 changes: 2 additions & 1 deletion NuGet/MsieJavaScriptEngine.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet).</description>
<summary>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).</summary>
<releaseNotes>Improved performance of debugging in ActiveScript modes.</releaseNotes>
<releaseNotes>1. Improved performance of debugging in ActiveScript modes;
2. JSON2 library was updated to version of June 12, 2017.</releaseNotes>
<copyright>Copyright (c) 2012-2018 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
<language>en-US</language>
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>
Expand Down
3 changes: 2 additions & 1 deletion NuGet/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
=============
RELEASE NOTES
=============
Improved performance of debugging in ActiveScript modes.
1. Improved performance of debugging in ActiveScript modes;
2. JSON2 library was updated to version of June 12, 2017.

============
PROJECT SITE
Expand Down
94 changes: 59 additions & 35 deletions src/MsieJavaScriptEngine/Resources/json2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// json2.js
// 2016-10-28
// 2017-06-12
// Public Domain.
// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
// See http://www.JSON.org/js.html
// This code should be minified before deployment.
// See http://javascript.crockford.com/jsmin.html

// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
// NOT CONTROL.
Expand Down Expand Up @@ -113,25 +110,31 @@
// a =
// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
// if (a) {
// return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
// +a[5], +a[6]));
// return new Date(Date.UTC(
// +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]
// ));
// }
// return value;
// }
// return value;
// });

// myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
// var d;
// if (typeof value === "string" &&
// value.slice(0, 5) === "Date(" &&
// value.slice(-1) === ")") {
// d = new Date(value.slice(5, -1));
// if (d) {
// return d;
// myData = JSON.parse(
// "[\"Date(09/09/2001)\"]",
// function (key, value) {
// var d;
// if (
// typeof value === "string"
// && value.slice(0, 5) === "Date("
// && value.slice(-1) === ")"
// ) {
// d = new Date(value.slice(5, -1));
// if (d) {
// return d;
// }
// }
// return value;
// }
// return value;
// });
// );

// This is a reference implementation. You are free to copy, modify, or
// redistribute.
Expand Down Expand Up @@ -167,7 +170,7 @@ if (typeof JSON !== "object") {

function f(n) {
// Format integers to have at least two digits.
return n < 10
return (n < 10)
? "0" + n
: n;
}
Expand All @@ -181,12 +184,20 @@ if (typeof JSON !== "object") {
Date.prototype.toJSON = function () {

return isFinite(this.valueOf())
? this.getUTCFullYear() + "-" +
f(this.getUTCMonth() + 1) + "-" +
f(this.getUTCDate()) + "T" +
f(this.getUTCHours()) + ":" +
f(this.getUTCMinutes()) + ":" +
f(this.getUTCSeconds()) + "Z"
? (
this.getUTCFullYear()
+ "-"
+ f(this.getUTCMonth() + 1)
+ "-"
+ f(this.getUTCDate())
+ "T"
+ f(this.getUTCHours())
+ ":"
+ f(this.getUTCMinutes())
+ ":"
+ f(this.getUTCSeconds())
+ "Z"
)
: null;
};

Expand Down Expand Up @@ -234,8 +245,11 @@ if (typeof JSON !== "object") {

// If the value has a toJSON method, call it to obtain a replacement value.

if (value && typeof value === "object" &&
typeof value.toJSON === "function") {
if (
value
&& typeof value === "object"
&& typeof value.toJSON === "function"
) {
value = value.toJSON(key);
}

Expand All @@ -256,7 +270,7 @@ if (typeof JSON !== "object") {

// JSON numbers must be finite. Encode non-finite numbers as null.

return isFinite(value)
return (isFinite(value))
? String(value)
: "null";

Expand Down Expand Up @@ -304,7 +318,14 @@ if (typeof JSON !== "object") {
v = partial.length === 0
? "[]"
: gap
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
? (
"[\n"
+ gap
+ partial.join(",\n" + gap)
+ "\n"
+ mind
+ "]"
)
: "[" + partial.join(",") + "]";
gap = mind;
return v;
Expand All @@ -320,7 +341,7 @@ if (typeof JSON !== "object") {
v = str(k, value);
if (v) {
partial.push(quote(k) + (
gap
(gap)
? ": "
: ":"
) + v);
Expand All @@ -336,7 +357,7 @@ if (typeof JSON !== "object") {
v = str(k, value);
if (v) {
partial.push(quote(k) + (
gap
(gap)
? ": "
: ":"
) + v);
Expand Down Expand Up @@ -400,9 +421,10 @@ if (typeof JSON !== "object") {
// Otherwise, throw an error.

rep = replacer;
if (replacer && typeof replacer !== "function" &&
(typeof replacer !== "object" ||
typeof replacer.length !== "number")) {
if (replacer && typeof replacer !== "function" && (
typeof replacer !== "object"
|| typeof replacer.length !== "number"
)) {
throw new Error("JSON.stringify");
}

Expand Down Expand Up @@ -456,8 +478,10 @@ if (typeof JSON !== "object") {
rx_dangerous.lastIndex = 0;
if (rx_dangerous.test(text)) {
text = text.replace(rx_dangerous, function (a) {
return "\\u" +
("0000" + a.charCodeAt(0).toString(16)).slice(-4);
return (
"\\u"
+ ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
);
});
}

Expand Down

0 comments on commit 4a65499

Please sign in to comment.