Skip to content

Commit 013fe25

Browse files
committed
JSON2 library was updated to version of October 30, 2022
1 parent 2ad66f0 commit 013fe25

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<IncludeSymbols>true</IncludeSymbols>
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
28-
<PackageReleaseNotes>In JsRT modes, `JsVariantToValue` and `JsValueToVariant` native methods are no longer used for embedding objects and types.</PackageReleaseNotes>
28+
<PackageReleaseNotes>1. In JsRT modes, `JsVariantToValue` and `JsValueToVariant` native methods are no longer used for embedding objects and types;
29+
2. JSON2 library was updated to version of October 30, 2022.</PackageReleaseNotes>
2930
<NeutralLanguage>en-US</NeutralLanguage>
3031
<PackageOutputPath>../../nuget</PackageOutputPath>
3132
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/Resources/json2.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// json2.js
2-
// 2017-06-12
2+
// 2022-10-30
33
// Public Domain.
44
// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
55

@@ -231,6 +231,29 @@ if (typeof JSON !== "object") {
231231
}
232232

233233

234+
// This variable is initialized with an empty array every time
235+
// JSON.stringify() is invoked and checked by the str() function. It's
236+
// used to keep references to object structures and capture cyclic
237+
// objects. Every new object is checked for its existence in this
238+
// array. If it's found it means the JSON object is cyclic and we have
239+
// to stop execution and throw a TypeError accordingly the ECMA262
240+
// (see NOTE 1 by the link https://tc39.es/ecma262/#sec-json.stringify).
241+
242+
var seen;
243+
244+
// Emulate [].includes(). It's actual for old-fashioned JScript.
245+
246+
function includes(array, value) {
247+
var i;
248+
for (i = 0; i < array.length; i += 1) {
249+
if (value === array[i]) {
250+
return true;
251+
}
252+
}
253+
return false;
254+
}
255+
256+
234257
function str(key, holder) {
235258

236259
// Produce a string from holder[key].
@@ -295,6 +318,16 @@ if (typeof JSON !== "object") {
295318
return "null";
296319
}
297320

321+
// Check the value is not circular object. Otherwise throw TypeError.
322+
323+
if (includes(seen, value)) {
324+
throw new TypeError("Converting circular structure to JSON");
325+
}
326+
327+
// Keep the value for the further check on circular references.
328+
329+
seen.push(value);
330+
298331
// Make an array to hold the partial results of stringifying this object value.
299332

300333
gap += indent;
@@ -428,6 +461,10 @@ if (typeof JSON !== "object") {
428461
throw new Error("JSON.stringify");
429462
}
430463

464+
// Initialize the reference keeper.
465+
466+
seen = [];
467+
431468
// Make a fake root object containing our value under the key of "".
432469
// Return the result of stringifying the value.
433470

src/MsieJavaScriptEngine/readme.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
In JsRT modes, `JsVariantToValue` and `JsValueToVariant` native methods are no
25-
longer used for embedding objects and types.
24+
1. In JsRT modes, `JsVariantToValue` and `JsValueToVariant` native methods are
25+
no longer used for embedding objects and types;
26+
2. JSON2 library was updated to version of October 30, 2022.
2627

2728
============
2829
PROJECT SITE

0 commit comments

Comments
 (0)