You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2024/10/19 10:19:48 UTC
(couchdb) 04/04: feat: use Object.freeze() instead of homegrown seal() to support SM>91
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch feat/spidermonkey-merge-parade
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 5438e7ff53652c573ea1e16ee217f5d2996f2912
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Sat Oct 19 11:57:10 2024 +0200
feat: use Object.freeze() instead of homegrown seal() to support SM>91
---
share/server/loop.js | 16 ++++++++--------
share/server/util.js | 27 +++++++++++++++++++--------
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/share/server/loop.js b/share/server/loop.js
index 6f8bc5c0f..1a5cab843 100644
--- a/share/server/loop.js
+++ b/share/server/loop.js
@@ -178,13 +178,13 @@ var Loop = function() {
};
// Seal all the globals to prevent modification.
-seal(Couch, true);
-seal(JSON, true);
-seal(Mime, true);
-seal(Render, true);
-seal(Filter, true);
-seal(Views, true);
-seal(isArray, true);
-seal(log, true);
+deepFreeze(Couch);
+deepFreeze(JSON);
+deepFreeze(Mime);
+deepFreeze(Render);
+deepFreeze(Filter);
+deepFreeze(Views);
+deepFreeze(isArray);
+deepFreeze(log);
Loop();
diff --git a/share/server/util.js b/share/server/util.js
index a459bf2e8..a6d8d2a48 100644
--- a/share/server/util.js
+++ b/share/server/util.js
@@ -116,14 +116,7 @@ var Couch = {
"Expression does not eval to a function. (" + source.toString() + ")"]);
};
},
- recursivelySeal : function(obj) {
- seal(obj);
- for (var propname in obj) {
- if (typeof obj[propname] == "object") {
- arguments.callee(obj[propname]);
- }
- }
- }
+ recursivelySeal : deepFreeze
};
function errstr(e) {
@@ -154,3 +147,21 @@ function log(message) {
function isArray(obj) {
return toString.call(obj) === "[object Array]";
}
+
+function deepFreeze(object) {
+ if (Object.isFrozen(object)) {
+ return object;
+ }
+ Object.freeze(object);
+ // Retrieve the property names defined on object
+ const propNames = Reflect.ownKeys(object);
+
+ // Freeze properties before freezing self
+ for (const name of propNames) {
+ const value = object[name];
+
+ if (((value && typeof value === "object") || typeof value === "function")) {
+ deepFreeze(value);
+ }
+ }
+}