Skip to content

Commit

Permalink
fix: Disallow Object.fromEntries in Tizen
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 17, 2024
1 parent d66446f commit 244ec64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
8 changes: 8 additions & 0 deletions build/conformance.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,11 @@ requirement: {
error_message:
"Using \"Array.flat\" is not allowed because is not supported on Tizen 3."
}

requirement: {
type: BANNED_PROPERTY_CALL
value: "Object.prototype.fromEntries"
error_message:
"Using \"Object.fromEntries\" is not allowed because is not supported on "
"Tizen 3."
}
34 changes: 17 additions & 17 deletions lib/util/config_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,23 @@ shaka.util.ConfigUtils = class {
};

const changes = (object, base) => {
return Object.fromEntries(
Object.entries(object).reduce((acc, [key, value]) => {
// eslint-disable-next-line no-prototype-builtins
if (!base.hasOwnProperty(key)) {
acc.push([key, value]);
} else if (isObject(value) && isObject(base[key])) {
const diff = changes(value, base[key]);
if (Object.keys(diff).length > 0 || !isObject(diff)) {
acc.push([key, diff]);
}
} else if (isArrayEmpty(value) && isArrayEmpty(base[key])) {
// Do nothing if both are empty arrays
} else if (value !== base[key]) {
acc.push([key, value]);
}
return acc;
}, []));
return Object.keys(object).reduce((acc, key) => {
const value = object[key];
// eslint-disable-next-line no-prototype-builtins
if (!base.hasOwnProperty(key)) {
acc[key] = value;
} else if (isObject(value) && isObject(base[key])) {
const diff = changes(value, base[key]);
if (Object.keys(diff).length > 0 || !isObject(diff)) {
acc[key] = diff;
}
} else if (isArrayEmpty(value) && isArrayEmpty(base[key])) {
// Do nothing if both are empty arrays
} else if (value !== base[key]) {
acc[key] = value;
}
return acc;
}, {});
};

const diff = changes(object, base);
Expand Down

0 comments on commit 244ec64

Please sign in to comment.