@gjsify/v8 0.3.20 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
package/lib/esm/heap.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";function
|
|
2
|
-
`)){let n=/^(\w+):\s+(\d+)(\s+kB)?/.exec(e);n&&t.set(n[1],parseInt(n[2])*(n[3]?1024:1))}}catch{}return t}function
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";function readProcStatus(){let t=new Map;try{let[n,r]=e.file_get_contents(`/proc/self/status`);if(!n||!r)return t;let i=new TextDecoder().decode(r);for(let e of i.split(`
|
|
2
|
+
`)){let n=/^(\w+):\s+(\d+)(\s+kB)?/.exec(e);n&&t.set(n[1],parseInt(n[2])*(n[3]?1024:1))}}catch{}return t}function getHeapStatistics(){let e=readProcStatus();return{total_heap_size:e.get(`VmSize`)??0,total_heap_size_executable:0,total_physical_size:e.get(`VmRSS`)??0,total_available_size:0,used_heap_size:e.get(`VmRSS`)??0,heap_size_limit:0,malloced_memory:e.get(`VmData`)??0,peak_malloced_memory:e.get(`VmPeak`)??0,does_zap_garbage:0,number_of_native_contexts:0,number_of_detached_contexts:0,total_global_handles_size:0,used_global_handles_size:0,external_memory:0}}export{getHeapStatistics};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getHeapStatistics as e}from"./heap.js";import{DefaultDeserializer as t,DefaultSerializer as n,Deserializer as r,Serializer as i}from"./serdes.js";function
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{getHeapStatistics as e}from"./heap.js";import{DefaultDeserializer as t,DefaultSerializer as n,Deserializer as r,Serializer as i}from"./serdes.js";function serialize(e){let t=new n;return t.writeHeader(),t.writeValue(e),t.releaseBuffer()}function deserialize(e){let n=new t(e);return n.readHeader(),n.readValue()}function getHeapSpaceStatistics(){return[]}function getHeapCodeStatistics(){return{code_and_metadata_size:0,bytecode_and_metadata_size:0,external_script_source_size:0,cpu_profiler_metadata_size:0}}function setFlagsFromString(e){}function getHeapSnapshot(e){return null}function writeHeapSnapshot(e){return``}function isStringOneByteRepresentation(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}var GCProfiler=class{#e=!1;#t=0;start(){this.#e||(this.#e=!0,this.#t=Date.now())}stop(){if(this.#e){this.#e=!1;try{let e=globalThis.imports?.system;typeof e?.gc==`function`&&e.gc()}catch{}return{version:1,startTime:this.#t,endTime:Date.now(),stats:[]}}}[Symbol.dispose](){this.stop()}},SyncCPUProfileHandle=class{stop(){}[Symbol.dispose](){this.stop()}};function startCpuProfile(){return new SyncCPUProfileHandle}var a={getHeapStatistics:e,getHeapSpaceStatistics,getHeapCodeStatistics,setFlagsFromString,getHeapSnapshot,writeHeapSnapshot,serialize,deserialize,isStringOneByteRepresentation,Serializer:i,Deserializer:r,DefaultSerializer:n,DefaultDeserializer:t,GCProfiler,startCpuProfile};export{t as DefaultDeserializer,n as DefaultSerializer,r as Deserializer,GCProfiler,i as Serializer,SyncCPUProfileHandle,a as default,deserialize,getHeapCodeStatistics,getHeapSnapshot,getHeapSpaceStatistics,e as getHeapStatistics,isStringOneByteRepresentation,serialize,setFlagsFromString,startCpuProfile,writeHeapSnapshot};
|
package/lib/esm/serdes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as e}from"node:buffer";function
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Buffer as e}from"node:buffer";function writeVarint(e,t){for(t>>>=0;t>=128;)e.push(t&127|128),t>>>=7;e.push(t)}function readVarint(e,t){let n=0,r=0,i;do{if(t>=e.length)throw Error(`Unexpected end of buffer reading varint`);i=e[t++],n|=(i&127)<<r,r+=7}while(i&128);return[n>>>0,t]}function zigZagEncode(e){return e>=0?e*2:-e*2-1}function zigZagDecode(e){return e&1?-(e>>>1)-1:e>>>1}function writeFloat64(e,t){let n=new DataView(new ArrayBuffer(8));n.setFloat64(0,t,!0);for(let t=0;t<8;t++)e.push(n.getUint8(t))}function readFloat64(e,t){if(t+8>e.length)throw Error(`ReadDouble() failed`);return[new DataView(e.buffer,e.byteOffset+t,8).getFloat64(0,!0),t+8]}function isOneByte(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!1;return!0}function typedArrayToIndex(e){let t=Object.prototype.toString.call(e);return t===`[object Int8Array]`?0:t===`[object Uint8Array]`?1:t===`[object Uint8ClampedArray]`?2:t===`[object Int16Array]`?3:t===`[object Uint16Array]`?4:t===`[object Int32Array]`?5:t===`[object Uint32Array]`?6:t===`[object Float32Array]`?7:t===`[object Float64Array]`?8:t===`[object DataView]`?9:t===`[object BigInt64Array]`?11:t===`[object BigUint64Array]`?12:-1}function indexToTypedArray(t){switch(t){case 0:return Int8Array;case 1:return Uint8Array;case 2:return Uint8ClampedArray;case 3:return Int16Array;case 4:return Uint16Array;case 5:return Int32Array;case 6:return Uint32Array;case 7:return Float32Array;case 8:return Float64Array;case 9:return DataView;case 10:return e;case 11:return BigInt64Array;case 12:return BigUint64Array}}var Serializer=class{_bytes=[];_seen=[];_treatAbvAsHostObjects=!1;_getDataCloneError=Error;writeHeader(){this._bytes.push(255),writeVarint(this._bytes,15)}writeValue(t){if(typeof t==`object`&&t){let e=this._seen.indexOf(t);if(e!==-1){this._bytes.push(94),writeVarint(this._bytes,e);return}}if(t===void 0)this._bytes.push(95);else if(t===null)this._bytes.push(48);else if(t===!0)this._bytes.push(84);else if(t===!1)this._bytes.push(70);else if(typeof t==`number`)Number.isInteger(t)&&t>=-(2**31)&&t<=2**32-1?t>=0?(this._bytes.push(85),writeVarint(this._bytes,t)):(this._bytes.push(73),writeVarint(this._bytes,zigZagEncode(t))):(this._bytes.push(78),writeFloat64(this._bytes,t));else if(typeof t==`bigint`)this._writeBigInt(t);else if(typeof t==`string`)this._writeString(t);else if(typeof t==`object`){let n=t;if(t instanceof Date)this._seen.push(n),this._bytes.push(68),writeFloat64(this._bytes,t.getTime());else if(t instanceof RegExp)this._seen.push(n),this._bytes.push(82),this._writeString(t.source),writeVarint(this._bytes,regExpFlagsToInt(t));else if(t instanceof ArrayBuffer){this._seen.push(n);let e=new Uint8Array(t);this._bytes.push(66),writeVarint(this._bytes,e.length);for(let t=0;t<e.length;t++)this._bytes.push(e[t])}else if(this._treatAbvAsHostObjects&&(ArrayBuffer.isView(t)||e.isBuffer(t)))this._seen.push(n),this._bytes.push(92),this._writeHostObject(n);else if(Array.isArray(t)){this._seen.push(n);let e=t;this._bytes.push(65),writeVarint(this._bytes,e.length);for(let t=0;t<e.length;t++)this.writeValue(e[t]);this._bytes.push(36),writeVarint(this._bytes,0),writeVarint(this._bytes,e.length)}else{this._seen.push(n),this._bytes.push(111);let e=Object.keys(n);for(let t of e)this._writeString(t),this.writeValue(n[t]);this._bytes.push(123),writeVarint(this._bytes,e.length)}}else throw new this._getDataCloneError(`${String(t)} could not be cloned.`)}releaseBuffer(){let t=e.from(this._bytes);return this._bytes=[],this._seen=[],t}writeUint32(e){writeVarint(this._bytes,e>>>0)}writeUint64(e,t){writeVarint(this._bytes,e>>>0),writeVarint(this._bytes,t>>>0)}writeDouble(e){writeFloat64(this._bytes,e)}writeRawBytes(e){if(!ArrayBuffer.isView(e))throw TypeError(`source must be a TypedArray or a DataView`);let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);for(let e=0;e<t.length;e++)this._bytes.push(t[e])}_writeHostObject(e){throw new this._getDataCloneError(`Unserializable host object: ${Object.prototype.toString.call(e)}`)}_setTreatArrayBufferViewsAsHostObjects(e){this._treatAbvAsHostObjects=e}_writeString(e){if(isOneByte(e)){this._bytes.push(34),writeVarint(this._bytes,e.length);for(let t=0;t<e.length;t++)this._bytes.push(e.charCodeAt(t)&255)}else{let t=new TextEncoder().encode(e);this._bytes.push(99),writeVarint(this._bytes,t.length);for(let e=0;e<t.length;e++)this._bytes.push(t[e])}}_writeBigInt(e){this._bytes.push(90);let t=e<0n,n=t?-e:e,r=[],i=n;for(;i>0n;)r.push(Number(i&4294967295n)),r.push(Number(i>>32n&4294967295n)),i>>=64n;let a=r.length<<1|!!t;writeVarint(this._bytes,a);for(let e of r)this._bytes.push(e&255),this._bytes.push(e>>8&255),this._bytes.push(e>>16&255),this._bytes.push(e>>24&255);r.length}},Deserializer=class{_pos=0;_wireVersion=0;_seen=[];buffer;constructor(t){if(!ArrayBuffer.isView(t)&&!(t instanceof ArrayBuffer))throw TypeError(`buffer must be a TypedArray or a DataView`);t instanceof ArrayBuffer?this.buffer=e.from(t):this.buffer=e.from(t.buffer,t.byteOffset,t.byteLength)}readHeader(){if(this.buffer[this._pos]!==255)throw Error(`ReadHeader() failed`);this._pos++;let[e,t]=readVarint(this.buffer,this._pos);return this._wireVersion=e,this._pos=t,!0}getWireFormatVersion(){return this._wireVersion}readValue(){if(this._pos>=this.buffer.length)throw Error(`Unexpected end of buffer`);let e=this.buffer[this._pos++];switch(e){case 95:return;case 48:return null;case 84:return!0;case 70:return!1;case 73:{let[e,t]=readVarint(this.buffer,this._pos);return this._pos=t,zigZagDecode(e)}case 85:{let[e,t]=readVarint(this.buffer,this._pos);return this._pos=t,e>>>0}case 78:{let[e,t]=readFloat64(this.buffer,this._pos);return this._pos=t,e}case 90:return this._readBigInt();case 34:{let[e,t]=readVarint(this.buffer,this._pos);this._pos=t;let n=``;for(let t=0;t<e;t++)n+=String.fromCharCode(this.buffer[this._pos++]);return n}case 99:{let[e,t]=readVarint(this.buffer,this._pos);this._pos=t;let n=this.buffer.slice(this._pos,this._pos+e);return this._pos+=e,new TextDecoder().decode(n)}case 68:{let[e,t]=readFloat64(this.buffer,this._pos);this._pos=t;let n=new Date(e);return this._seen.push(n),n}case 82:{let e=this.readValue(),[t,n]=readVarint(this.buffer,this._pos);this._pos=n;let r=intToRegExpFlags(t),i=new RegExp(e,r);return this._seen.push(i),i}case 66:{let[e,t]=readVarint(this.buffer,this._pos);this._pos=t;let n=new ArrayBuffer(e),r=new Uint8Array(n);for(let t=0;t<e;t++)r[t]=this.buffer[this._pos++];return this._seen.push(n),n}case 94:{let[e,t]=readVarint(this.buffer,this._pos);if(this._pos=t,e>=this._seen.length)throw Error(`Invalid object reference`);return this._seen[e]}case 65:{let[e,t]=readVarint(this.buffer,this._pos);this._pos=t;let n=Array(e);this._seen.push(n);for(let t=0;t<e;t++)n[t]=this.readValue();if(this.buffer[this._pos]!==36)throw Error(`Expected kEndDenseArray`);this._pos++;let[,r]=readVarint(this.buffer,this._pos);this._pos=r;let[,i]=readVarint(this.buffer,this._pos);return this._pos=i,n}case 111:{let e={};for(this._seen.push(e);this.buffer[this._pos]!==123;){let t=this.readValue();e[t]=this.readValue()}this._pos++;let[,t]=readVarint(this.buffer,this._pos);return this._pos=t,e}case 92:{let e=this._readHostObject();return e!=null&&this._seen.push(e),e}default:throw Error(`Unknown tag 0x${e.toString(16).padStart(2,`0`)} at position ${this._pos-1}`)}}readUint32(){let[e,t]=readVarint(this.buffer,this._pos);return this._pos=t,e>>>0}readUint64(){let[e,t]=readVarint(this.buffer,this._pos),[n,r]=readVarint(this.buffer,t);return this._pos=r,[e>>>0,n>>>0]}readDouble(){let[e,t]=readFloat64(this.buffer,this._pos);return this._pos=t,e}_readRawBytes(e){let t=this._pos;if(this._pos+=e,this._pos>this.buffer.length)throw Error(`Unexpected end of buffer reading raw bytes`);return t}readRawBytes(t){let n=this._readRawBytes(t);return e.from(this.buffer.buffer,this.buffer.byteOffset+n,t)}_readHostObject(){throw Error(`No host object deserializer installed`)}_readBigInt(){let[e,t]=readVarint(this.buffer,this._pos);this._pos=t;let n=(e&1)==1,r=e>>1,i=0n;for(let e=0;e<r;e++){let t=this.buffer[this._pos]|this.buffer[this._pos+1]<<8|this.buffer[this._pos+2]<<16|this.buffer[this._pos+3]<<24;this._pos+=4,i|=BigInt(t>>>0)<<BigInt(e*32)}return n?-i:i}};function regExpFlagsToInt(e){let t=0;return e.global&&(t|=1),e.ignoreCase&&(t|=2),e.multiline&&(t|=4),e.sticky&&(t|=8),e.unicode&&(t|=16),e.dotAll&&(t|=32),e.hasIndices&&(t|=64),e.unicodeSets&&(t|=128),t}function intToRegExpFlags(e){let t=``;return e&1&&(t+=`g`),e&2&&(t+=`i`),e&4&&(t+=`m`),e&8&&(t+=`y`),e&16&&(t+=`u`),e&32&&(t+=`s`),e&64&&(t+=`d`),e&128&&(t+=`v`),t}var DefaultSerializer=class extends Serializer{constructor(){super(),this._setTreatArrayBufferViewsAsHostObjects(!0)}_writeHostObject(t){let n;if(e.isBuffer(t))n=10;else if(n=typedArrayToIndex(t),n===-1)throw new this._getDataCloneError(`Unserializable host object: ${Object.prototype.toString.call(t)}`);this.writeUint32(n),this.writeUint32(t.byteLength),this.writeRawBytes(new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}},DefaultDeserializer=class extends Deserializer{_readHostObject(){let t=this.readUint32(),n=this.readUint32(),r=this._readRawBytes(n);if(t===10){let t=e.allocUnsafe(n);return this.buffer.copy(t,0,this.buffer.byteOffset+r,this.buffer.byteOffset+r+n),t}let i=indexToTypedArray(t);if(!i)throw Error(`Unknown TypedArray type index ${t}`);let a=i.BYTES_PER_ELEMENT??1,o=n/a,s=this.buffer.byteOffset+r;if(s%a===0)return new i(this.buffer.buffer,s,o);let c=e.allocUnsafe(n);return this.buffer.copy(c,0,this.buffer.byteOffset+r,this.buffer.byteOffset+r+n),new i(c.buffer,c.byteOffset,o)}};export{DefaultDeserializer,DefaultSerializer,Deserializer,Serializer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/v8",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Node.js v8 module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"v8"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@gjsify/cli": "^0.
|
|
34
|
-
"@gjsify/unit": "^0.
|
|
33
|
+
"@gjsify/cli": "^0.4.0",
|
|
34
|
+
"@gjsify/unit": "^0.4.0",
|
|
35
35
|
"@types/node": "^25.6.2",
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
}
|