mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
ArrayStorage refactoring
This commit is contained in:
Vendored
+12
-5
@@ -6773,7 +6773,7 @@ var StringLiteralReplacer = StringLiteralReplacer_1 = function (_AbstractReplace
|
||||
}
|
||||
var indexOfValue = this.stringArrayStorage.getLength();
|
||||
var hexadecimalIndex = "" + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(indexOfValue);
|
||||
this.stringArrayStorage.set(null, value);
|
||||
this.stringArrayStorage.set(this.stringArrayStorage.getLength(), value);
|
||||
this.stringLiteralHexadecimalIndexCache.set(value, hexadecimalIndex);
|
||||
return hexadecimalIndex;
|
||||
}
|
||||
@@ -7599,6 +7599,8 @@ var RandomGeneratorUtils_1 = __webpack_require__(9);
|
||||
var ArrayStorage = function () {
|
||||
function ArrayStorage() {
|
||||
(0, _classCallCheck3.default)(this, ArrayStorage);
|
||||
|
||||
this.storageLength = 0;
|
||||
}
|
||||
|
||||
(0, _createClass3.default)(ArrayStorage, [{
|
||||
@@ -7618,7 +7620,7 @@ var ArrayStorage = function () {
|
||||
}, {
|
||||
key: "getLength",
|
||||
value: function getLength() {
|
||||
return this.storage.length;
|
||||
return this.storageLength;
|
||||
}
|
||||
}, {
|
||||
key: "getStorage",
|
||||
@@ -7649,14 +7651,19 @@ var ArrayStorage = function () {
|
||||
}, {
|
||||
key: "set",
|
||||
value: function set(key, value) {
|
||||
this.storage.push(value);
|
||||
if (key === this.storageLength) {
|
||||
this.storage.push(value);
|
||||
} else {
|
||||
this.storage.splice(key, 0, value);
|
||||
}
|
||||
this.storageLength++;
|
||||
}
|
||||
}]);
|
||||
return ArrayStorage;
|
||||
}();
|
||||
tslib_1.__decorate([Initializable_1.initializable(), tslib_1.__metadata("design:type", String)], ArrayStorage.prototype, "storageId", void 0);
|
||||
tslib_1.__decorate([Initializable_1.initializable(), tslib_1.__metadata("design:type", Array)], ArrayStorage.prototype, "storage", void 0);
|
||||
ArrayStorage = tslib_1.__decorate([inversify_1.injectable(), tslib_1.__metadata("design:paramtypes", [])], ArrayStorage);
|
||||
tslib_1.__decorate([Initializable_1.initializable(), tslib_1.__metadata("design:type", String)], ArrayStorage.prototype, "storageId", void 0);
|
||||
ArrayStorage = tslib_1.__decorate([inversify_1.injectable()], ArrayStorage);
|
||||
exports.ArrayStorage = ArrayStorage;
|
||||
|
||||
/***/ }),
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@
|
||||
"tslint": "4.3.1",
|
||||
"tslint-loader": "3.3.0",
|
||||
"typescript": "2.1.5",
|
||||
"webpack": "2.2.0-rc.5",
|
||||
"webpack": "2.2.0-rc.6",
|
||||
"webpack-node-externals": "1.5.4"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ export interface IStorage <T> extends IInitializable {
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
set (key: string | number | null, value: T): void;
|
||||
set (key: string | number, value: T): void;
|
||||
|
||||
/**
|
||||
* @returns string
|
||||
|
||||
@@ -105,7 +105,7 @@ export class StringLiteralReplacer extends AbstractReplacer {
|
||||
const indexOfValue: number = this.stringArrayStorage.getLength();
|
||||
const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${Utils.decToHex(indexOfValue)}`;
|
||||
|
||||
this.stringArrayStorage.set(null, value);
|
||||
this.stringArrayStorage.set(this.stringArrayStorage.getLength(), value);
|
||||
this.stringLiteralHexadecimalIndexCache.set(value, hexadecimalIndex);
|
||||
|
||||
return hexadecimalIndex;
|
||||
|
||||
@@ -8,6 +8,12 @@ import { RandomGeneratorUtils } from '../utils/RandomGeneratorUtils';
|
||||
|
||||
@injectable()
|
||||
export abstract class ArrayStorage <T> implements IStorage <T> {
|
||||
/**
|
||||
* @type {T[]}
|
||||
*/
|
||||
@initializable()
|
||||
protected storage: T[];
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -15,10 +21,9 @@ export abstract class ArrayStorage <T> implements IStorage <T> {
|
||||
protected storageId: string;
|
||||
|
||||
/**
|
||||
* @type {T[]}
|
||||
* @type {number}
|
||||
*/
|
||||
@initializable()
|
||||
protected storage: T[];
|
||||
private storageLength: number = 0;
|
||||
|
||||
/**
|
||||
* @param key
|
||||
@@ -46,7 +51,7 @@ export abstract class ArrayStorage <T> implements IStorage <T> {
|
||||
* @returns {number}
|
||||
*/
|
||||
public getLength (): number {
|
||||
return this.storage.length;
|
||||
return this.storageLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +92,13 @@ export abstract class ArrayStorage <T> implements IStorage <T> {
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public set (key: string | null, value: T): void {
|
||||
this.storage.push(value);
|
||||
public set (key: number, value: T): void {
|
||||
if (key === this.storageLength) {
|
||||
this.storage.push(value);
|
||||
} else {
|
||||
this.storage.splice(key, 0, value);
|
||||
}
|
||||
|
||||
this.storageLength++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user