Parcourir la source

Enforce readonly setting registry values.

Afshin Darian il y a 6 ans
Parent
commit
2f20ba17df

+ 8 - 7
packages/coreutils/src/settingregistry.ts

@@ -12,6 +12,7 @@ import {
   JSONObject,
   JSONValue,
   ReadonlyJSONObject,
+  ReadonlyJSONValue,
   Token
 } from '@phosphor/coreutils';
 
@@ -225,7 +226,7 @@ export namespace ISettingRegistry {
     /**
      * The composite of user settings and extension defaults.
      */
-    readonly composite: JSONObject;
+    readonly composite: ReadonlyJSONObject;
 
     /*
      * The plugin name.
@@ -245,7 +246,7 @@ export namespace ISettingRegistry {
     /**
      * The user settings.
      */
-    readonly user: JSONObject;
+    readonly user: ReadonlyJSONObject;
 
     /**
      * The published version of the NPM package containing these settings.
@@ -273,7 +274,7 @@ export namespace ISettingRegistry {
      *
      * @returns The setting value.
      */
-    get(key: string): { composite: JSONValue; user: JSONValue };
+    get(key: string): { composite: ReadonlyJSONValue; user: ReadonlyJSONValue };
 
     /**
      * Remove a single setting.
@@ -817,7 +818,7 @@ export class Settings implements ISettingRegistry.ISettings {
   /**
    * The composite of user settings and extension defaults.
    */
-  get composite(): JSONObject {
+  get composite(): ReadonlyJSONObject {
     return this._composite;
   }
 
@@ -845,7 +846,7 @@ export class Settings implements ISettingRegistry.ISettings {
   /**
    * The user settings.
    */
-  get user(): JSONObject {
+  get user(): ReadonlyJSONObject {
     return this._user;
   }
 
@@ -855,7 +856,7 @@ export class Settings implements ISettingRegistry.ISettings {
   readonly plugin: string;
 
   /**
-   * The system registry instance used by the settings manager.
+   * The setting registry instance used as a back-end for these settings.
    */
   readonly registry: SettingRegistry;
 
@@ -905,7 +906,7 @@ export class Settings implements ISettingRegistry.ISettings {
    * This method returns synchronously because it uses a cached copy of the
    * plugin settings that is synchronized with the registry.
    */
-  get(key: string): { composite: JSONValue; user: JSONValue } {
+  get(key: string): { composite: ReadonlyJSONValue; user: ReadonlyJSONValue } {
     const { composite, user } = this;
 
     return {

+ 1 - 1
packages/settingeditor/src/pluginlist.tsx

@@ -271,7 +271,7 @@ namespace Private {
     selection: string,
     node: HTMLElement
   ): void {
-    const plugins = sortPlugins(registry.plugins).filter(plugin => {
+    const plugins = sortPlugins(registry.plugins.slice()).filter(plugin => {
       const { schema } = plugin;
       const editable = Object.keys(schema.properties || {}).length > 0;
       const extensible = schema.additionalProperties !== false;

+ 3 - 3
packages/shortcuts-extension/src/index.ts

@@ -7,7 +7,7 @@ import { ISettingRegistry } from '@jupyterlab/coreutils';
 
 import { CommandRegistry } from '@phosphor/commands';
 
-import { JSONObject, JSONValue } from '@phosphor/coreutils';
+import { ReadonlyJSONObject, ReadonlyJSONValue } from '@phosphor/coreutils';
 
 import { DisposableSet, IDisposable } from '@phosphor/disposable';
 
@@ -80,7 +80,7 @@ namespace Private {
    */
   export function loadShortcuts(
     commands: CommandRegistry,
-    composite: JSONObject
+    composite: ReadonlyJSONObject
   ): void {
     if (disposables) {
       disposables.dispose();
@@ -100,7 +100,7 @@ namespace Private {
    * Normalize potential keyboard shortcut options.
    */
   function normalizeOptions(
-    value: JSONValue | Partial<CommandRegistry.IKeyBindingOptions>
+    value: ReadonlyJSONValue | Partial<CommandRegistry.IKeyBindingOptions>
   ): CommandRegistry.IKeyBindingOptions | undefined {
     if (!value || typeof value !== 'object') {
       return undefined;