Browse Source

HashedCollection >> #jsonLiteralized.

Herby Vojčík 2 years ago
parent
commit
6d4c7784a0
2 changed files with 29 additions and 0 deletions
  1. 23 0
      lang/src/Kernel-Collections.js
  2. 6 0
      lang/src/Kernel-Collections.st

+ 23 - 0
lang/src/Kernel-Collections.js

@@ -3596,6 +3596,29 @@ return self;
 }; }),
 $globals.HashedCollection);
 
+$core.addMethod(
+$core.method({
+selector: "jsonLiteralized",
+protocol: "converting",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "jsonLiteralized\x0a\x09^ JSON parse: (JSON stringify: self)",
+referencedClasses: ["JSON"],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["parse:", "stringify:"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($globals.JSON)._parse_($recv($globals.JSON)._stringify_(self));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"jsonLiteralized",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.HashedCollection);
+
 $core.addMethod(
 $core.method({
 selector: "keys",

+ 6 - 0
lang/src/Kernel-Collections.st

@@ -878,6 +878,12 @@ removeKey: aKey ifAbsent: aBlock
 		ifAbsent: [ aBlock value ]
 ! !
 
+!HashedCollection methodsFor: 'converting'!
+
+jsonLiteralized
+	^ JSON parse: (JSON stringify: self)
+! !
+
 !HashedCollection methodsFor: 'enumerating'!
 
 keysDo: aBlock