Skip to content

Commit 44c01d0

Browse files
committed
feat: new api (JSON.jsonify)
1 parent 685c2c2 commit 44c01d0

File tree

7 files changed

+1239
-1179
lines changed

7 files changed

+1239
-1179
lines changed

lib/json.ht

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
external abstract class JSON {
22
static function parse(object)
33

4+
static function jsonify(object)
5+
46
static function stringify(object)
57

68
static function deepcopy(object)

lib/object.ht

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Object {
3030

3131
function hasOwnProperty(key: string) => this.containsKey(key)
3232

33-
function toJSON() -> Map => JSON.parse(this)
33+
function toJSON() -> Map => JSON.jsonify(this)
3434

3535
function toString() -> string => JSON.stringify(this)
3636
}

lib/value.ht

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ external class Iterable {
326326
/// Returns a new `Iterator` that allows iterating the Iterable's elements.
327327
get iterator -> Iterator
328328

329-
function toJSON() -> Map
329+
function toJSON()
330330

331331
/// The current elements of this iterable modified by [toElement].
332332
function map(toElement: (any) -> any) -> Iterable

packages/hetu_script/lib/binding/class_binding.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,12 +1014,14 @@ class HTJSONClassBinding extends HTExternalClass {
10141014
@override
10151015
dynamic memberGet(String id, {String? from, bool ignoreUndefined = false}) {
10161016
switch (id) {
1017-
case 'JSON.stringify':
1018-
return ({positionalArgs, namedArgs}) =>
1019-
lexicon.stringify(positionalArgs.first);
10201017
case 'JSON.parse':
10211018
return ({positionalArgs, namedArgs}) =>
10221019
jsonDecode(positionalArgs.first);
1020+
case 'JSON.jsonify':
1021+
return ({positionalArgs, namedArgs}) => jsonify(positionalArgs.first);
1022+
case 'JSON.stringify':
1023+
return ({positionalArgs, namedArgs}) =>
1024+
lexicon.stringify(positionalArgs.first);
10231025
case 'JSON.deepcopy':
10241026
return ({positionalArgs, namedArgs}) => deepCopy(positionalArgs.first);
10251027
default:

0 commit comments

Comments
 (0)