From d5ecac4d0fa175646f7c3a2f21e3bb1bbe6944df Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 12 Dec 2024 12:23:58 -0500 Subject: [PATCH] dev: update deprecated use of __proto__ --- src/backend/src/codex/CodeModel.js | 25 ------------------------- src/backend/src/codex/Sequence.js | 7 +++---- src/backend/src/config.js | 10 +++++----- src/backend/src/util/context.js | 2 +- 4 files changed, 9 insertions(+), 35 deletions(-) delete mode 100644 src/backend/src/codex/CodeModel.js diff --git a/src/backend/src/codex/CodeModel.js b/src/backend/src/codex/CodeModel.js deleted file mode 100644 index d771621ca..000000000 --- a/src/backend/src/codex/CodeModel.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2024 Puter Technologies Inc. - * - * This file is part of Puter. - * - * Puter is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -class CodeModel { - static create () {} -} - -module.exports = { - CodeModel, -}; diff --git a/src/backend/src/codex/Sequence.js b/src/backend/src/codex/Sequence.js index 86e981a85..ca4d2f419 100644 --- a/src/backend/src/codex/Sequence.js +++ b/src/backend/src/codex/Sequence.js @@ -109,7 +109,7 @@ class Sequence { async run (values) { // Initialize scope values = values || this.thisArg?.values || {}; - this.scope_.__proto__ = values; + Object.setPrototypeOf(this.scope_, values); // Run sequence for ( ; this.i < this.steps.length ; this.i++ ) { @@ -126,9 +126,8 @@ class Sequence { const parent_scope = this.scope_; this.scope_ = {}; // We could do Object.assign(this.scope_, parent_scope), but - // setting __proto__ is faster because it leverages the optimizations - // of the JS engine for the prototype chain. - this.scope_.__proto__ = parent_scope; + // setting the prototype should be faster (in theory) + Object.setPrototypeOf(this.scope_, parent_scope); if ( this.sequence_.options_.record_history ) { this.value_history_.push(this.scope_); diff --git a/src/backend/src/config.js b/src/backend/src/config.js index 39eab6b93..06662efb0 100644 --- a/src/backend/src/config.js +++ b/src/backend/src/config.js @@ -160,7 +160,7 @@ let config_to_export; // load_config() may replace const config_pointer = {}; { - config_pointer.__proto__ = config; + Object.setPrototypeOf(config_pointer, config); config_to_export = config_pointer; } @@ -171,14 +171,14 @@ const config_pointer = {}; let replacement_config = { ...o, }; - replacement_config = deep_proto_merge(replacement_config, config_pointer.__proto__, { + replacement_config = deep_proto_merge(replacement_config, Object.getPrototypeOf(config_pointer), { preserve_flag: true, }) - config_pointer.__proto__ = replacement_config; + Object.setPrototypeOf(config_pointer, replacement_config); }; const config_api = { load_config }; - config_api.__proto__ = config_to_export; + Object.setPrototypeOf(config_api, config_to_export); config_to_export = config_api; } @@ -209,7 +209,7 @@ const config_pointer = {}; const config_runtime_values = { $: 'runtime-values' }; - config_runtime_values.__proto__ = config_to_export; + Object.setPrototypeOf(config_runtime_values, config_to_export); config_to_export = config_runtime_values // These can be difficult to find and cause painful diff --git a/src/backend/src/util/context.js b/src/backend/src/util/context.js index 3430e15c7..f7a2ffcbd 100644 --- a/src/backend/src/util/context.js +++ b/src/backend/src/util/context.js @@ -132,7 +132,7 @@ class Context { this.parent_ = opt_parent; if ( opt_parent ) { - values.__proto__ = opt_parent.values_; + Object.setPrototypeOf(values, opt_parent.values_); for ( const k in values ) { const parent_val = opt_parent.values_[k]; if ( parent_val instanceof Context ) {