[dart2wasm] Correctly handle null when jsifying maps.

Change-Id: Ibda04bf6012447dcab86079da8d4d41771e8e9bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262102
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
This commit is contained in:
Joshua Litt 2022-09-30 21:09:29 +00:00 committed by Commit Queue
parent 577e34df43
commit 29de68d38e
2 changed files with 16 additions and 9 deletions

View file

@ -37,8 +37,7 @@ dynamic jsify(Object? object) {
o is Float32List ||
o is Float64List ||
o is ByteBuffer ||
o is ByteData ||
o is num) {
o is ByteData) {
return JSValue.box(jsifyRaw(o));
}
@ -46,9 +45,9 @@ dynamic jsify(Object? object) {
JSValue convertedMap = newObject<JSValue>();
convertedObjects[o] = convertedMap;
for (final key in o.keys) {
JSValue convertedKey = convert(key) as JSValue;
setPropertyRaw(convertedMap.toExternRef(), convertedKey.toExternRef(),
(convert(o[key]) as JSValue).toExternRef());
JSValue? convertedKey = convert(key) as JSValue?;
setPropertyRaw(convertedMap.toExternRef(), convertedKey?.toExternRef(),
(convert(o[key]) as JSValue?)?.toExternRef());
}
return convertedMap;
} else if (o is Iterable) {

View file

@ -140,9 +140,11 @@ void deepConversionsTest() {
['a', 'b', 'c'], dartify(jsify(['a', 'b', 'c'])) as List<Object?>);
_expectRecEquals(
{
'null': 'foo',
'foo': null,
'a': 1,
'b': true,
'c': [1, 2, 3],
'c': [1, 2, 3, null],
'd': 'foo',
'e': {
'f': 2,
@ -150,9 +152,11 @@ void deepConversionsTest() {
},
},
dartify(jsify({
'null': 'foo',
'foo': null,
'a': 1,
'b': true,
'c': [1, 2, 3],
'c': [1, 2, 3, null],
'd': 'foo',
'e': {
'f': 2,
@ -194,9 +198,11 @@ void deepConversionsTest() {
globalThis.e = true;
globalThis.f = function () { return 'hello world'; };
globalThis.g = {
null: 'foo',
'foo': null,
'a': 1,
'b': true,
'c': [1, 2, 3],
'c': [1, 2, 3, null],
'd': 'foo',
'e': {'f': 2, 'g': [2, 4, 6]},
};
@ -229,9 +235,11 @@ void deepConversionsTest() {
Expect.equals(2.5, getProperty(gt, 'd'));
Expect.equals(true, getProperty(gt, 'e'));
_expectRecEquals({
'null': 'foo',
'foo': null,
'a': 1,
'b': true,
'c': [1, 2, 3],
'c': [1, 2, 3, null],
'd': 'foo',
'e': {
'f': 2,