* Used to read some kind of host object, i.e. an * object that is created by native C++ bindings. * @returns {any}
()
| 473 | * @returns {any} |
| 474 | */ |
| 475 | _readHostObject() { |
| 476 | const typeIndex = this.readUint32(); |
| 477 | const ctor = arrayBufferViewIndexToType(typeIndex); |
| 478 | const byteLength = this.readUint32(); |
| 479 | const byteOffset = this._readRawBytes(byteLength); |
| 480 | const BYTES_PER_ELEMENT = ctor.BYTES_PER_ELEMENT || 1; |
| 481 | |
| 482 | const offset = this.buffer.byteOffset + byteOffset; |
| 483 | if (offset % BYTES_PER_ELEMENT === 0) { |
| 484 | return new ctor(this.buffer.buffer, |
| 485 | offset, |
| 486 | byteLength / BYTES_PER_ELEMENT); |
| 487 | } |
| 488 | // Copy to an aligned buffer first. |
| 489 | const buffer_copy = Buffer.allocUnsafe(byteLength); |
| 490 | buffer_copy.set(new Uint8Array(this.buffer.buffer, this.buffer.byteOffset + byteOffset, byteLength)); |
| 491 | return new ctor(buffer_copy.buffer, |
| 492 | buffer_copy.byteOffset, |
| 493 | byteLength / BYTES_PER_ELEMENT); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /** |
nothing calls this directly
no test coverage detected