1e41f4b71Sopenharmony_ci# ArkCompiler子系统Changelog
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## cl.arkcompiler.1 JSON.parse解析非法字符串行为变更
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci**访问级别**
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci公开接口
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci**变更原因**
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciJSON.parse解析非法字符串未抛JS异常,表现与预期及ECMA规范不一致
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci**变更影响**
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci该变更为不兼容性变更。
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ciconst strData = `{"k1": "hello", "k2": 3}`;
19e41f4b71Sopenharmony_ciconst strErr = strData.substring(0, strData.length - 2); // `{"k1": "hello", "k2": `
20e41f4b71Sopenharmony_ciJSON.parse(strErr);
21e41f4b71Sopenharmony_ci```
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci变更前:JSON.parse解析非法字符串`strErr`能够正常解析,未抛出JS异常。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci变更后:JSON.parse解析非法字符串`strErr`抛出JS异常。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**起始API Level**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci12
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**变更发生版本**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci5.0 Beta3
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**变更的接口/组件**
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ciJSON.parse/ASON.parse/util.json.parse
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**适配指导**
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci针对JSON.parse解析非法字符串的异常场景,开发者需要保证传入的字符串为合法字符串,或者使用try-catch捕获异常。
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## cl.arkcompiler.2 JSON.parse解析浮点数下溢或-0行为变更
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**访问级别**
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci公开接口
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**变更原因**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ciJSON.parse相关接口解析字符串含有浮点数下溢或-0的情况,表现与规范不一致。
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**变更影响**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci该变更为不兼容性变更。
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci变更前:
58e41f4b71Sopenharmony_ci`JSON.parse('123.456e-789');` 返回 `-Infinity`,是错误结果。
59e41f4b71Sopenharmony_ci`1/JSON.parse('-0');` 返回 `Infinity`,是错误结果。
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci变更后:
62e41f4b71Sopenharmony_ci`JSON.parse('123.456e-789');` 返回 `0`,是正确结果。
63e41f4b71Sopenharmony_ci`1/JSON.parse('-0');` 返回 `-Infinity`,是正确结果。
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**起始API Level**
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci12
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**变更发生版本**
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci5.0 Beta3
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**变更的接口/组件**
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ciJSON.parse/ASON.parse/util.json.parse
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**适配指导**
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci对于开发者,排查代码中是否存在对JSON.parse相关接口传入下溢的浮点数字符串与-0的情况,如果存在该现象,则排查代码逻辑是否能适配正确的值。
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci## cl.arkcompiler.3 TextEncoder.encodeInto()接口变更
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**访问级别**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci公开接口
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**变更原因**
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ciTextEncoder.encodeInto编码字符串,当字符串中每多一个'\0'字符,返回的数组长度会增加2,长度异常。
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**变更影响**
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci该变更为不兼容性变更。
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci```
96e41f4b71Sopenharmony_ciconst arr = encoder.encodeInto('\0ab');
97e41f4b71Sopenharmony_ciarr.length;
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci变更前:arr = [0x00, 0x61, 0x62, 0x00], arr.length 为4
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci变更后:arr = [0x00, 0x61, 0x62], arr.length 为3
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**起始API Level**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci9
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**变更发生版本**
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci5.0 Beta3
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**变更的接口/组件**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ciTextEncoder.encodeInto
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**适配指导**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci针对TextEncoder.encodeInto编码字符串时,注意返回的数组长度。