Browse Source

create empty object whose prototype is null

Yana Rose 4 years ago
parent
commit
a00277b315
2 changed files with 6 additions and 6 deletions
  1. 2 2
      src/viewer/helpers/export.ts
  2. 4 4
      src/viewer/helpers/preset.ts

+ 2 - 2
src/viewer/helpers/export.ts

@@ -57,7 +57,7 @@ function getDecorator(plugin: PluginContext, root: string): string {
 }
 
 function extractStructureDataFromState(plugin: PluginContext): { [k: string]: Structure } {
-    const content: { [k: string]: Structure } = {};
+    const content: { [k: string]: Structure } = Object.create(null);
     const cells = plugin.state.data.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure));
     for (let i = 0; i < cells.length; i++) {
         const c = cells[i];
@@ -73,7 +73,7 @@ function extractStructureDataFromState(plugin: PluginContext): { [k: string]: St
 }
 
 export function encodeStructureData(plugin: PluginContext): { [k: string]: Uint8Array } {
-    const content: { [k: string]: Uint8Array } = {};
+    const content: { [k: string]: Uint8Array } = Object.create(null);
     const structures = extractStructureDataFromState(plugin);
     for (const [key, structure] of Object.entries(structures)) {
         const filename = `${key}.cif`;

+ 4 - 4
src/viewer/helpers/preset.ts

@@ -152,13 +152,13 @@ export const RcsbSuperpositionRepresentationPreset = StructureRepresentationPres
     async apply(ref, params, plugin) {
 
         const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
-        if (!structureCell) return {};
+        if (!structureCell) return Object.create(null);
 
         const structure = structureCell.obj!.data;
         const cartoonProps = {sizeFactor: structure.isCoarseGrained ? 0.8 : 0.2};
 
-        let components = {};
-        let representations = {};
+        let components = Object.create(null);
+        let representations = Object.create(null);
         for (const expr of params.selectionExpressions) {
 
             const comp = await plugin.builders.structure.tryCreateComponentFromExpression(structureCell, expr.expression, expr.label, { label: expr.label });
@@ -237,7 +237,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
             structureProperties = await _structureProperties.commit();
 
             // adding coloring lookup scheme
-            structure.data!.inheritedPropertyData.colors = {};
+            structure.data!.inheritedPropertyData.colors = Object.create(null);
             for (const repr of p.representation) {
                 if (repr.name === 'color') {
                     const colorValue = repr.value;