mirror of https://github.com/gorhill/uBlock.git
Fix eslint warnings
This commit is contained in:
parent
8dc0e885b5
commit
4533f0e37e
|
@ -19,17 +19,14 @@
|
||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global indexedDB */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
import * as s14e from './s14e-serializer.js';
|
||||||
|
|
||||||
import lz4Codec from './lz4.js';
|
import lz4Codec from './lz4.js';
|
||||||
|
import { ubolog } from './console.js';
|
||||||
import webext from './webext.js';
|
import webext from './webext.js';
|
||||||
import µb from './background.js';
|
import µb from './background.js';
|
||||||
import { ubolog } from './console.js';
|
|
||||||
import * as s14e from './s14e-serializer.js';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -47,6 +44,10 @@ const keysFromGetArg = arg => {
|
||||||
|
|
||||||
let fastCache = 'indexedDB';
|
let fastCache = 'indexedDB';
|
||||||
|
|
||||||
|
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
||||||
|
const hasOwnProperty = (o, p) =>
|
||||||
|
Object.prototype.hasOwnProperty.call(o, p);
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
*
|
*
|
||||||
* Extension storage
|
* Extension storage
|
||||||
|
@ -65,7 +66,7 @@ const cacheStorage = (( ) => {
|
||||||
if ( found.length === wanted.length ) { return; }
|
if ( found.length === wanted.length ) { return; }
|
||||||
const missing = [];
|
const missing = [];
|
||||||
for ( const key of wanted ) {
|
for ( const key of wanted ) {
|
||||||
if ( outbin.hasOwnProperty(key) ) { continue; }
|
if ( hasOwnProperty(outbin, key) ) { continue; }
|
||||||
missing.push(key);
|
missing.push(key);
|
||||||
}
|
}
|
||||||
return missing;
|
return missing;
|
||||||
|
@ -107,7 +108,7 @@ const cacheStorage = (( ) => {
|
||||||
if ( argbin instanceof Object === false ) { return; }
|
if ( argbin instanceof Object === false ) { return; }
|
||||||
if ( Array.isArray(argbin) ) { return; }
|
if ( Array.isArray(argbin) ) { return; }
|
||||||
for ( const key of wanted ) {
|
for ( const key of wanted ) {
|
||||||
if ( argbin.hasOwnProperty(key) === false ) { continue; }
|
if ( hasOwnProperty(argbin, key) === false ) { continue; }
|
||||||
outbin[key] = argbin[key];
|
outbin[key] = argbin[key];
|
||||||
}
|
}
|
||||||
}).then(( ) => {
|
}).then(( ) => {
|
||||||
|
@ -165,7 +166,7 @@ const cacheStorage = (( ) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
select(api) {
|
select(api) {
|
||||||
if ( cacheAPIs.hasOwnProperty(api) === false ) { return fastCache; }
|
if ( hasOwnProperty(cacheAPIs, api) === false ) { return fastCache; }
|
||||||
fastCache = api;
|
fastCache = api;
|
||||||
for ( const k of Object.keys(cacheAPIs) ) {
|
for ( const k of Object.keys(cacheAPIs) ) {
|
||||||
if ( k === api ) { continue; }
|
if ( k === api ) { continue; }
|
||||||
|
@ -591,7 +592,7 @@ const idbStorage = (( ) => {
|
||||||
const transaction = db.transaction(STORAGE_NAME, 'readonly');
|
const transaction = db.transaction(STORAGE_NAME, 'readonly');
|
||||||
transaction.oncomplete =
|
transaction.oncomplete =
|
||||||
transaction.onerror =
|
transaction.onerror =
|
||||||
transaction.onabort = ( ) => {
|
transaction.onabort = ( ) => {
|
||||||
resolve(Promise.all(entries));
|
resolve(Promise.all(entries));
|
||||||
};
|
};
|
||||||
const table = transaction.objectStore(STORAGE_NAME);
|
const table = transaction.objectStore(STORAGE_NAME);
|
||||||
|
@ -673,7 +674,7 @@ const idbStorage = (( ) => {
|
||||||
}
|
}
|
||||||
if ( argbin instanceof Object && Array.isArray(argbin) === false ) {
|
if ( argbin instanceof Object && Array.isArray(argbin) === false ) {
|
||||||
for ( const key of keys ) {
|
for ( const key of keys ) {
|
||||||
if ( outbin.hasOwnProperty(key) ) { continue; }
|
if ( hasOwnProperty(outbin, key) ) { continue; }
|
||||||
outbin[key] = argbin[key];
|
outbin[key] = argbin[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -695,7 +696,7 @@ const idbStorage = (( ) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
return getDb().then(db => {
|
return getDb().then(db => {
|
||||||
if ( db === null ) { return; }
|
if ( db === null ) { return; }
|
||||||
db.close();
|
db.close();
|
||||||
indexedDB.deleteDatabase(STORAGE_NAME);
|
indexedDB.deleteDatabase(STORAGE_NAME);
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
*
|
*
|
||||||
* Structured-Cloneable to Unicode-Only SERIALIZER
|
* Structured-Cloneable to Unicode-Only SERIALIZER
|
||||||
|
@ -103,14 +101,14 @@ const { intToChar, intToCharCode, charCodeToInt } = (( ) => {
|
||||||
const intToCharCode = [];
|
const intToCharCode = [];
|
||||||
const charCodeToInt = [];
|
const charCodeToInt = [];
|
||||||
for ( let i = 0; i < NUMSAFECHARS; i++ ) {
|
for ( let i = 0; i < NUMSAFECHARS; i++ ) {
|
||||||
intToChar[i] = SAFECHARS.charAt(i);
|
intToChar[i] = SAFECHARS.charAt(i);
|
||||||
intToCharCode[i] = SAFECHARS.charCodeAt(i);
|
intToCharCode[i] = SAFECHARS.charCodeAt(i);
|
||||||
charCodeToInt[i] = 0;
|
charCodeToInt[i] = 0;
|
||||||
}
|
}
|
||||||
for ( let i = NUMSAFECHARS; i < 128; i++ ) {
|
for ( let i = NUMSAFECHARS; i < 128; i++ ) {
|
||||||
intToChar[i] = '';
|
intToChar[i] = '';
|
||||||
intToCharCode[i] = 0;
|
intToCharCode[i] = 0;
|
||||||
charCodeToInt[i] = 0;
|
charCodeToInt[i] = 0;
|
||||||
}
|
}
|
||||||
for ( let i = 0; i < SAFECHARS.length; i++ ) {
|
for ( let i = 0; i < SAFECHARS.length; i++ ) {
|
||||||
charCodeToInt[SAFECHARS.charCodeAt(i)] = i;
|
charCodeToInt[SAFECHARS.charCodeAt(i)] = i;
|
||||||
|
@ -287,6 +285,9 @@ const shouldCompress = (s, options) =>
|
||||||
options.compressThreshold <= s.length
|
options.compressThreshold <= s.length
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasOwnProperty = (o, p) =>
|
||||||
|
Object.prototype.hasOwnProperty.call(o, p);
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
*
|
*
|
||||||
* A large Uint is always a positive integer (can be zero), assumed to be
|
* A large Uint is always a positive integer (can be zero), assumed to be
|
||||||
|
@ -549,38 +550,38 @@ const _serialize = data => {
|
||||||
}
|
}
|
||||||
// Type name
|
// Type name
|
||||||
switch ( typeToSerializedInt[typeof data] ) {
|
switch ( typeToSerializedInt[typeof data] ) {
|
||||||
case I_STRING: {
|
case I_STRING: {
|
||||||
const length = data.length;
|
const length = data.length;
|
||||||
if ( length < NUMSAFECHARS ) {
|
if ( length < NUMSAFECHARS ) {
|
||||||
writeBuffer.push(C_STRING_SMALL + intToChar[length], data);
|
writeBuffer.push(C_STRING_SMALL + intToChar[length], data);
|
||||||
} else {
|
} else {
|
||||||
writeBuffer.push(C_STRING_LARGE + strFromLargeUint(length), data);
|
writeBuffer.push(C_STRING_LARGE + strFromLargeUint(length), data);
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case I_NUMBER:
|
return;
|
||||||
if ( isInteger(data) ) {
|
}
|
||||||
if ( data >= NUMSAFECHARS ) {
|
case I_NUMBER:
|
||||||
writeBuffer.push(C_INTEGER_LARGE_POS + strFromLargeUint(data));
|
if ( isInteger(data) ) {
|
||||||
} else if ( data > 0 ) {
|
if ( data >= NUMSAFECHARS ) {
|
||||||
writeBuffer.push(C_INTEGER_SMALL_POS + intToChar[data]);
|
writeBuffer.push(C_INTEGER_LARGE_POS + strFromLargeUint(data));
|
||||||
} else if ( data > -NUMSAFECHARS ) {
|
} else if ( data > 0 ) {
|
||||||
writeBuffer.push(C_INTEGER_SMALL_NEG + intToChar[-data]);
|
writeBuffer.push(C_INTEGER_SMALL_POS + intToChar[data]);
|
||||||
} else {
|
} else if ( data > -NUMSAFECHARS ) {
|
||||||
writeBuffer.push(C_INTEGER_LARGE_NEG + strFromLargeUint(-data));
|
writeBuffer.push(C_INTEGER_SMALL_NEG + intToChar[-data]);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const s = `${data}`;
|
writeBuffer.push(C_INTEGER_LARGE_NEG + strFromLargeUint(-data));
|
||||||
writeBuffer.push(C_FLOAT + strFromLargeUint(s.length) + s);
|
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
case I_BOOL:
|
const s = `${data}`;
|
||||||
writeBuffer.push(data ? C_BOOL_TRUE : C_BOOL_FALSE);
|
writeBuffer.push(C_FLOAT + strFromLargeUint(s.length) + s);
|
||||||
return;
|
}
|
||||||
case I_OBJECT:
|
return;
|
||||||
break;
|
case I_BOOL:
|
||||||
default:
|
writeBuffer.push(data ? C_BOOL_TRUE : C_BOOL_FALSE);
|
||||||
return;
|
return;
|
||||||
|
case I_OBJECT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const xtypeName = Object.prototype.toString.call(data);
|
const xtypeName = Object.prototype.toString.call(data);
|
||||||
const xtypeInt = xtypeToSerializedInt[xtypeName];
|
const xtypeInt = xtypeToSerializedInt[xtypeName];
|
||||||
|
@ -604,90 +605,90 @@ const _serialize = data => {
|
||||||
writeRefs.set(data, refCounter++);
|
writeRefs.set(data, refCounter++);
|
||||||
// Extended type name
|
// Extended type name
|
||||||
switch ( xtypeInt ) {
|
switch ( xtypeInt ) {
|
||||||
case I_ARRAY: {
|
case I_ARRAY: {
|
||||||
const size = data.length;
|
const size = data.length;
|
||||||
if ( size < NUMSAFECHARS ) {
|
if ( size < NUMSAFECHARS ) {
|
||||||
writeBuffer.push(C_ARRAY_SMALL + intToChar[size]);
|
writeBuffer.push(C_ARRAY_SMALL + intToChar[size]);
|
||||||
} else {
|
} else {
|
||||||
writeBuffer.push(C_ARRAY_LARGE + strFromLargeUint(size));
|
writeBuffer.push(C_ARRAY_LARGE + strFromLargeUint(size));
|
||||||
}
|
|
||||||
for ( const v of data ) {
|
|
||||||
_serialize(v);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case I_SET: {
|
for ( const v of data ) {
|
||||||
const size = data.size;
|
_serialize(v);
|
||||||
if ( size < NUMSAFECHARS ) {
|
|
||||||
writeBuffer.push(C_SET_SMALL + intToChar[size]);
|
|
||||||
} else {
|
|
||||||
writeBuffer.push(C_SET_LARGE + strFromLargeUint(size));
|
|
||||||
}
|
|
||||||
for ( const v of data ) {
|
|
||||||
_serialize(v);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case I_MAP: {
|
return;
|
||||||
const size = data.size;
|
}
|
||||||
if ( size < NUMSAFECHARS ) {
|
case I_SET: {
|
||||||
writeBuffer.push(C_MAP_SMALL + intToChar[size]);
|
const size = data.size;
|
||||||
} else {
|
if ( size < NUMSAFECHARS ) {
|
||||||
writeBuffer.push(C_MAP_LARGE + strFromLargeUint(size));
|
writeBuffer.push(C_SET_SMALL + intToChar[size]);
|
||||||
}
|
} else {
|
||||||
for ( const [ k, v ] of data ) {
|
writeBuffer.push(C_SET_LARGE + strFromLargeUint(size));
|
||||||
_serialize(k);
|
|
||||||
_serialize(v);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case I_ARRAYBUFFER: {
|
for ( const v of data ) {
|
||||||
const byteLength = data.byteLength;
|
_serialize(v);
|
||||||
writeBuffer.push(C_ARRAYBUFFER + strFromLargeUint(byteLength));
|
|
||||||
_serialize(data.maxByteLength);
|
|
||||||
const arrbuffDetails = analyzeArrayBuffer(data);
|
|
||||||
_serialize(arrbuffDetails.dense);
|
|
||||||
const str = arrbuffDetails.dense
|
|
||||||
? denseArrayBufferToStr(data, arrbuffDetails)
|
|
||||||
: sparseArrayBufferToStr(data, arrbuffDetails);
|
|
||||||
_serialize(str);
|
|
||||||
//console.log(`arrbuf size=${byteLength} content size=${arrbuffDetails.end} dense=${arrbuffDetails.dense} array size=${arrbuffDetails.dense ? arrbuffDetails.denseSize : arrbuffDetails.sparseSize} serialized size=${str.length}`);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case I_INT8ARRAY:
|
return;
|
||||||
case I_UINT8ARRAY:
|
}
|
||||||
case I_UINT8CLAMPEDARRAY:
|
case I_MAP: {
|
||||||
case I_INT16ARRAY:
|
const size = data.size;
|
||||||
case I_UINT16ARRAY:
|
if ( size < NUMSAFECHARS ) {
|
||||||
case I_INT32ARRAY:
|
writeBuffer.push(C_MAP_SMALL + intToChar[size]);
|
||||||
case I_UINT32ARRAY:
|
} else {
|
||||||
case I_FLOAT32ARRAY:
|
writeBuffer.push(C_MAP_LARGE + strFromLargeUint(size));
|
||||||
case I_FLOAT64ARRAY:
|
|
||||||
writeBuffer.push(
|
|
||||||
xtypeToSerializedChar[xtypeName],
|
|
||||||
strFromLargeUint(data.byteOffset),
|
|
||||||
strFromLargeUint(data.length)
|
|
||||||
);
|
|
||||||
_serialize(data.buffer);
|
|
||||||
return;
|
|
||||||
case I_DATAVIEW:
|
|
||||||
writeBuffer.push(C_DATAVIEW, strFromLargeUint(data.byteOffset), strFromLargeUint(data.byteLength));
|
|
||||||
_serialize(data.buffer);
|
|
||||||
return;
|
|
||||||
default: {
|
|
||||||
const keys = Object.keys(data);
|
|
||||||
const size = keys.length;
|
|
||||||
if ( size < NUMSAFECHARS ) {
|
|
||||||
writeBuffer.push(C_OBJECT_SMALL + intToChar[size]);
|
|
||||||
} else {
|
|
||||||
writeBuffer.push(C_OBJECT_LARGE + strFromLargeUint(size));
|
|
||||||
}
|
|
||||||
for ( const key of keys ) {
|
|
||||||
_serialize(key);
|
|
||||||
_serialize(data[key]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
for ( const [ k, v ] of data ) {
|
||||||
|
_serialize(k);
|
||||||
|
_serialize(v);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case I_ARRAYBUFFER: {
|
||||||
|
const byteLength = data.byteLength;
|
||||||
|
writeBuffer.push(C_ARRAYBUFFER + strFromLargeUint(byteLength));
|
||||||
|
_serialize(data.maxByteLength);
|
||||||
|
const arrbuffDetails = analyzeArrayBuffer(data);
|
||||||
|
_serialize(arrbuffDetails.dense);
|
||||||
|
const str = arrbuffDetails.dense
|
||||||
|
? denseArrayBufferToStr(data, arrbuffDetails)
|
||||||
|
: sparseArrayBufferToStr(data, arrbuffDetails);
|
||||||
|
_serialize(str);
|
||||||
|
//console.log(`arrbuf size=${byteLength} content size=${arrbuffDetails.end} dense=${arrbuffDetails.dense} array size=${arrbuffDetails.dense ? arrbuffDetails.denseSize : arrbuffDetails.sparseSize} serialized size=${str.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case I_INT8ARRAY:
|
||||||
|
case I_UINT8ARRAY:
|
||||||
|
case I_UINT8CLAMPEDARRAY:
|
||||||
|
case I_INT16ARRAY:
|
||||||
|
case I_UINT16ARRAY:
|
||||||
|
case I_INT32ARRAY:
|
||||||
|
case I_UINT32ARRAY:
|
||||||
|
case I_FLOAT32ARRAY:
|
||||||
|
case I_FLOAT64ARRAY:
|
||||||
|
writeBuffer.push(
|
||||||
|
xtypeToSerializedChar[xtypeName],
|
||||||
|
strFromLargeUint(data.byteOffset),
|
||||||
|
strFromLargeUint(data.length)
|
||||||
|
);
|
||||||
|
_serialize(data.buffer);
|
||||||
|
return;
|
||||||
|
case I_DATAVIEW:
|
||||||
|
writeBuffer.push(C_DATAVIEW, strFromLargeUint(data.byteOffset), strFromLargeUint(data.byteLength));
|
||||||
|
_serialize(data.buffer);
|
||||||
|
return;
|
||||||
|
default: {
|
||||||
|
const keys = Object.keys(data);
|
||||||
|
const size = keys.length;
|
||||||
|
if ( size < NUMSAFECHARS ) {
|
||||||
|
writeBuffer.push(C_OBJECT_SMALL + intToChar[size]);
|
||||||
|
} else {
|
||||||
|
writeBuffer.push(C_OBJECT_LARGE + strFromLargeUint(size));
|
||||||
|
}
|
||||||
|
for ( const key of keys ) {
|
||||||
|
_serialize(key);
|
||||||
|
_serialize(data[key]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -697,146 +698,146 @@ const _deserialize = ( ) => {
|
||||||
if ( readPtr >= readEnd ) { return; }
|
if ( readPtr >= readEnd ) { return; }
|
||||||
const type = charCodeToInt[readStr.charCodeAt(readPtr++)];
|
const type = charCodeToInt[readStr.charCodeAt(readPtr++)];
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
// Primitive types
|
// Primitive types
|
||||||
case I_STRING_SMALL:
|
case I_STRING_SMALL:
|
||||||
case I_STRING_LARGE: {
|
case I_STRING_LARGE: {
|
||||||
const size = type === I_STRING_SMALL
|
const size = type === I_STRING_SMALL
|
||||||
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
||||||
: deserializeLargeUint();
|
: deserializeLargeUint();
|
||||||
const beg = readPtr;
|
const beg = readPtr;
|
||||||
readPtr += size;
|
readPtr += size;
|
||||||
return readStr.slice(beg, readPtr);
|
return readStr.slice(beg, readPtr);
|
||||||
|
}
|
||||||
|
case I_ZERO:
|
||||||
|
return 0;
|
||||||
|
case I_INTEGER_SMALL_POS:
|
||||||
|
return charCodeToInt[readStr.charCodeAt(readPtr++)];
|
||||||
|
case I_INTEGER_SMALL_NEG:
|
||||||
|
return -charCodeToInt[readStr.charCodeAt(readPtr++)];
|
||||||
|
case I_INTEGER_LARGE_POS:
|
||||||
|
return deserializeLargeUint();
|
||||||
|
case I_INTEGER_LARGE_NEG:
|
||||||
|
return -deserializeLargeUint();
|
||||||
|
case I_BOOL_FALSE:
|
||||||
|
return false;
|
||||||
|
case I_BOOL_TRUE:
|
||||||
|
return true;
|
||||||
|
case I_NULL:
|
||||||
|
return null;
|
||||||
|
case I_UNDEFINED:
|
||||||
|
return;
|
||||||
|
case I_FLOAT: {
|
||||||
|
const size = deserializeLargeUint();
|
||||||
|
const beg = readPtr;
|
||||||
|
readPtr += size;
|
||||||
|
return parseFloat(readStr.slice(beg, readPtr));
|
||||||
|
}
|
||||||
|
case I_REGEXP: {
|
||||||
|
const source = _deserialize();
|
||||||
|
const flags = _deserialize();
|
||||||
|
return new RegExp(source, flags);
|
||||||
|
}
|
||||||
|
case I_DATE: {
|
||||||
|
const time = _deserialize();
|
||||||
|
return new Date(time);
|
||||||
|
}
|
||||||
|
case I_REFERENCE: {
|
||||||
|
const ref = deserializeLargeUint();
|
||||||
|
return readRefs.get(ref);
|
||||||
|
}
|
||||||
|
case I_OBJECT_SMALL:
|
||||||
|
case I_OBJECT_LARGE: {
|
||||||
|
const entries = [];
|
||||||
|
const size = type === I_OBJECT_SMALL
|
||||||
|
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
||||||
|
: deserializeLargeUint();
|
||||||
|
for ( let i = 0; i < size; i++ ) {
|
||||||
|
const k = _deserialize();
|
||||||
|
const v = _deserialize();
|
||||||
|
entries.push([ k, v ]);
|
||||||
}
|
}
|
||||||
case I_ZERO:
|
const out = Object.fromEntries(entries);
|
||||||
return 0;
|
readRefs.set(refCounter++, out);
|
||||||
case I_INTEGER_SMALL_POS:
|
return out;
|
||||||
return charCodeToInt[readStr.charCodeAt(readPtr++)];
|
}
|
||||||
case I_INTEGER_SMALL_NEG:
|
case I_ARRAY_SMALL:
|
||||||
return -charCodeToInt[readStr.charCodeAt(readPtr++)];
|
case I_ARRAY_LARGE: {
|
||||||
case I_INTEGER_LARGE_POS:
|
const out = [];
|
||||||
return deserializeLargeUint();
|
const size = type === I_ARRAY_SMALL
|
||||||
case I_INTEGER_LARGE_NEG:
|
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
||||||
return -deserializeLargeUint();
|
: deserializeLargeUint();
|
||||||
case I_BOOL_FALSE:
|
for ( let i = 0; i < size; i++ ) {
|
||||||
return false;
|
out.push(_deserialize());
|
||||||
case I_BOOL_TRUE:
|
|
||||||
return true;
|
|
||||||
case I_NULL:
|
|
||||||
return null;
|
|
||||||
case I_UNDEFINED:
|
|
||||||
return;
|
|
||||||
case I_FLOAT: {
|
|
||||||
const size = deserializeLargeUint();
|
|
||||||
const beg = readPtr;
|
|
||||||
readPtr += size;
|
|
||||||
return parseFloat(readStr.slice(beg, readPtr));
|
|
||||||
}
|
}
|
||||||
case I_REGEXP: {
|
readRefs.set(refCounter++, out);
|
||||||
const source = _deserialize();
|
return out;
|
||||||
const flags = _deserialize();
|
}
|
||||||
return new RegExp(source, flags);
|
case I_SET_SMALL:
|
||||||
|
case I_SET_LARGE: {
|
||||||
|
const entries = [];
|
||||||
|
const size = type === I_SET_SMALL
|
||||||
|
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
||||||
|
: deserializeLargeUint();
|
||||||
|
for ( let i = 0; i < size; i++ ) {
|
||||||
|
entries.push(_deserialize());
|
||||||
}
|
}
|
||||||
case I_DATE: {
|
const out = new Set(entries);
|
||||||
const time = _deserialize();
|
readRefs.set(refCounter++, out);
|
||||||
return new Date(time);
|
return out;
|
||||||
|
}
|
||||||
|
case I_MAP_SMALL:
|
||||||
|
case I_MAP_LARGE: {
|
||||||
|
const entries = [];
|
||||||
|
const size = type === I_MAP_SMALL
|
||||||
|
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
||||||
|
: deserializeLargeUint();
|
||||||
|
for ( let i = 0; i < size; i++ ) {
|
||||||
|
const k = _deserialize();
|
||||||
|
const v = _deserialize();
|
||||||
|
entries.push([ k, v ]);
|
||||||
}
|
}
|
||||||
case I_REFERENCE: {
|
const out = new Map(entries);
|
||||||
const ref = deserializeLargeUint();
|
readRefs.set(refCounter++, out);
|
||||||
return readRefs.get(ref);
|
return out;
|
||||||
|
}
|
||||||
|
case I_ARRAYBUFFER: {
|
||||||
|
const byteLength = deserializeLargeUint();
|
||||||
|
const maxByteLength = _deserialize();
|
||||||
|
let options;
|
||||||
|
if ( maxByteLength !== 0 && maxByteLength !== byteLength ) {
|
||||||
|
options = { maxByteLength };
|
||||||
}
|
}
|
||||||
case I_OBJECT_SMALL:
|
const arrbuf = new ArrayBuffer(byteLength, options);
|
||||||
case I_OBJECT_LARGE: {
|
const dense = _deserialize();
|
||||||
const entries = [];
|
const str = _deserialize();
|
||||||
const size = type === I_OBJECT_SMALL
|
if ( dense ) {
|
||||||
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
denseArrayBufferFromStr(str, arrbuf);
|
||||||
: deserializeLargeUint();
|
} else {
|
||||||
for ( let i = 0; i < size; i++ ) {
|
sparseArrayBufferFromStr(str, arrbuf);
|
||||||
const k = _deserialize();
|
|
||||||
const v = _deserialize();
|
|
||||||
entries.push([ k, v ]);
|
|
||||||
}
|
|
||||||
const out = Object.fromEntries(entries);
|
|
||||||
readRefs.set(refCounter++, out);
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
case I_ARRAY_SMALL:
|
readRefs.set(refCounter++, arrbuf);
|
||||||
case I_ARRAY_LARGE: {
|
return arrbuf;
|
||||||
const out = [];
|
}
|
||||||
const size = type === I_ARRAY_SMALL
|
case I_INT8ARRAY:
|
||||||
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
case I_UINT8ARRAY:
|
||||||
: deserializeLargeUint();
|
case I_UINT8CLAMPEDARRAY:
|
||||||
for ( let i = 0; i < size; i++ ) {
|
case I_INT16ARRAY:
|
||||||
out.push(_deserialize());
|
case I_UINT16ARRAY:
|
||||||
}
|
case I_INT32ARRAY:
|
||||||
readRefs.set(refCounter++, out);
|
case I_UINT32ARRAY:
|
||||||
return out;
|
case I_FLOAT32ARRAY:
|
||||||
}
|
case I_FLOAT64ARRAY:
|
||||||
case I_SET_SMALL:
|
case I_DATAVIEW: {
|
||||||
case I_SET_LARGE: {
|
const byteOffset = deserializeLargeUint();
|
||||||
const entries = [];
|
const length = deserializeLargeUint();
|
||||||
const size = type === I_SET_SMALL
|
const arrayBuffer = _deserialize();
|
||||||
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
const ctor = toArrayBufferViewConstructor[`${type}`];
|
||||||
: deserializeLargeUint();
|
const out = new ctor(arrayBuffer, byteOffset, length);
|
||||||
for ( let i = 0; i < size; i++ ) {
|
readRefs.set(refCounter++, out);
|
||||||
entries.push(_deserialize());
|
return out;
|
||||||
}
|
}
|
||||||
const out = new Set(entries);
|
default:
|
||||||
readRefs.set(refCounter++, out);
|
break;
|
||||||
return out;
|
|
||||||
}
|
|
||||||
case I_MAP_SMALL:
|
|
||||||
case I_MAP_LARGE: {
|
|
||||||
const entries = [];
|
|
||||||
const size = type === I_MAP_SMALL
|
|
||||||
? charCodeToInt[readStr.charCodeAt(readPtr++)]
|
|
||||||
: deserializeLargeUint();
|
|
||||||
for ( let i = 0; i < size; i++ ) {
|
|
||||||
const k = _deserialize();
|
|
||||||
const v = _deserialize();
|
|
||||||
entries.push([ k, v ]);
|
|
||||||
}
|
|
||||||
const out = new Map(entries);
|
|
||||||
readRefs.set(refCounter++, out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
case I_ARRAYBUFFER: {
|
|
||||||
const byteLength = deserializeLargeUint();
|
|
||||||
const maxByteLength = _deserialize();
|
|
||||||
let options;
|
|
||||||
if ( maxByteLength !== 0 && maxByteLength !== byteLength ) {
|
|
||||||
options = { maxByteLength };
|
|
||||||
}
|
|
||||||
const arrbuf = new ArrayBuffer(byteLength, options);
|
|
||||||
const dense = _deserialize();
|
|
||||||
const str = _deserialize();
|
|
||||||
if ( dense ) {
|
|
||||||
denseArrayBufferFromStr(str, arrbuf);
|
|
||||||
} else {
|
|
||||||
sparseArrayBufferFromStr(str, arrbuf);
|
|
||||||
}
|
|
||||||
readRefs.set(refCounter++, arrbuf);
|
|
||||||
return arrbuf;
|
|
||||||
}
|
|
||||||
case I_INT8ARRAY:
|
|
||||||
case I_UINT8ARRAY:
|
|
||||||
case I_UINT8CLAMPEDARRAY:
|
|
||||||
case I_INT16ARRAY:
|
|
||||||
case I_UINT16ARRAY:
|
|
||||||
case I_INT32ARRAY:
|
|
||||||
case I_UINT32ARRAY:
|
|
||||||
case I_FLOAT32ARRAY:
|
|
||||||
case I_FLOAT64ARRAY:
|
|
||||||
case I_DATAVIEW: {
|
|
||||||
const byteOffset = deserializeLargeUint();
|
|
||||||
const length = deserializeLargeUint();
|
|
||||||
const arrayBuffer = _deserialize();
|
|
||||||
const ctor = toArrayBufferViewConstructor[`${type}`];
|
|
||||||
const out = new ctor(arrayBuffer, byteOffset, length);
|
|
||||||
readRefs.set(refCounter++, out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
readPtr = FAILMARK;
|
readPtr = FAILMARK;
|
||||||
};
|
};
|
||||||
|
@ -1128,7 +1129,7 @@ export const getConfig = ( ) => Object.assign({}, currentConfig);
|
||||||
|
|
||||||
export const setConfig = config => {
|
export const setConfig = config => {
|
||||||
for ( const key in Object.keys(config) ) {
|
for ( const key in Object.keys(config) ) {
|
||||||
if ( defaultConfig.hasOwnProperty(key) === false ) { continue; }
|
if ( hasOwnProperty(defaultConfig, key) === false ) { continue; }
|
||||||
const val = config[key];
|
const val = config[key];
|
||||||
if ( typeof val !== typeof defaultConfig[key] ) { continue; }
|
if ( typeof val !== typeof defaultConfig[key] ) { continue; }
|
||||||
if ( (validateConfig[key])(val) === false ) { continue; }
|
if ( (validateConfig[key])(val) === false ) { continue; }
|
||||||
|
@ -1385,19 +1386,22 @@ if ( isInstanceOf(globalThis, 'DedicatedWorkerGlobalScope') ) {
|
||||||
globalThis.onmessage = ev => {
|
globalThis.onmessage = ev => {
|
||||||
const msg = ev.data;
|
const msg = ev.data;
|
||||||
switch ( msg.what ) {
|
switch ( msg.what ) {
|
||||||
case THREAD_AREYOUREADY:
|
case THREAD_AREYOUREADY:
|
||||||
setConfig(msg.config);
|
setConfig(msg.config);
|
||||||
globalThis.postMessage({ what: THREAD_IAMREADY });
|
globalThis.postMessage({ what: THREAD_IAMREADY });
|
||||||
break;
|
break;
|
||||||
case THREAD_SERIALIZE:
|
case THREAD_SERIALIZE: {
|
||||||
const result = serialize(msg.data, msg.options);
|
const result = serialize(msg.data, msg.options);
|
||||||
globalThis.postMessage({ id: msg.id, size: msg.size, result });
|
globalThis.postMessage({ id: msg.id, size: msg.size, result });
|
||||||
break;
|
break;
|
||||||
case THREAD_DESERIALIZE: {
|
}
|
||||||
const result = deserialize(msg.data);
|
case THREAD_DESERIALIZE: {
|
||||||
globalThis.postMessage({ id: msg.id, size: msg.size, result });
|
const result = deserialize(msg.data);
|
||||||
break;
|
globalThis.postMessage({ id: msg.id, size: msg.size, result });
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue