@muze-nl/od-jsontag 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/od-jsontag",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "On Demand JSONTag: parse/serialize large datastructures on demand, useful for sharing data between threads",
5
5
  "type": "module",
6
6
  "author": "Auke van Slooten <auke@muze.nl>",
package/src/serialize.mjs CHANGED
@@ -6,6 +6,7 @@ import * as odJSONTag from './jsontag.mjs'
6
6
  //
7
7
  const encoder = new TextEncoder()
8
8
  const decoder = new TextDecoder()
9
+ const realJSON = JSON // in case someone redefines JSON as JSONTag later
9
10
 
10
11
  function stringToSAB(strData) {
11
12
  const buffer = encoder.encode(strData)
@@ -61,7 +62,7 @@ export default function serialize(value, options={}) {
61
62
  if (odJSONTag.isNull(value)) {
62
63
  value = 'null'
63
64
  } else {
64
- value = JSON.stringify(''+value)
65
+ value = realJSON.stringify(''+value)
65
66
  }
66
67
  prop = typeString + value
67
68
  break
@@ -84,7 +85,7 @@ export default function serialize(value, options={}) {
84
85
  if (odJSONTag.isNull(value)) {
85
86
  value = 'null'
86
87
  } else {
87
- value = JSON.stringify(value)
88
+ value = realJSON.stringify(value)
88
89
  }
89
90
  prop = typeString + value
90
91
  break
@@ -138,7 +139,7 @@ export default function serialize(value, options={}) {
138
139
  let value = object[key]
139
140
  let prop = stringifyValue(value, false, current)
140
141
  let enumerable = object.propertyIsEnumerable(key) ? '' : '#'
141
- props.push(enumerable+'"'+key+'":'+prop)
142
+ props.push(enumerable+realJSON.stringify(key)+':'+prop) //FIXME: how does key get escaped?
142
143
  }
143
144
  result = odJSONTag.getTypeString(object)+'{'+props.join(',')+'}'
144
145
  return result
@@ -166,7 +167,11 @@ export default function serialize(value, options={}) {
166
167
  let skipCount = 0
167
168
  let result = []
168
169
  while(currentSource<resultArray.length) {
169
- if (resultArray[currentSource][isChanged] || !resultArray[currentSource][isProxy]) {
170
+ if (!resultArray[currentSource]) {
171
+ //FIXME: should not happen, this means that there is no complete
172
+ //od-jsontag file, only patches?
173
+ skipCount++
174
+ } else if (resultArray[currentSource][isChanged] || !resultArray[currentSource][isProxy]) {
170
175
  if (skipCount) {
171
176
  result[currentResult] = encoder.encode('+'+skipCount)
172
177
  skipCount = 0