Project import generated by Copybara

PiperOrigin-RevId: 299970447
pull/7267/head
Rafi Kamal 5 years ago committed by Copybara-Service
parent 460376190b
commit 4fa3c8e883
  1. 9
      js/experimental/runtime/kernel/buffer_decoder.js
  2. 8
      js/experimental/runtime/kernel/buffer_decoder_test.js
  3. 2
      js/experimental/runtime/kernel/indexer.js
  4. 3
      js/experimental/runtime/kernel/writer.js

@ -279,15 +279,14 @@ class BufferDecoder {
}
/**
* Skips over a varint at a given index.
* @param {number} index Start of the data.
* Skips over a varint from the current cursor position.
* @package
*/
skipVarint(index) {
this.cursor_ = index;
skipVarint() {
const startIndex = this.cursor_;
while (this.dataView_.getUint8(this.cursor_++) & 0x80) {
}
checkCriticalPositionIndex(this.cursor_, index + 10);
checkCriticalPositionIndex(this.cursor_, startIndex + 10);
}
/**

@ -41,7 +41,7 @@ describe('Skip varint does', () => {
it('skip a varint', () => {
const bufferDecoder =
BufferDecoder.fromArrayBuffer(createArrayBuffer(0x01));
bufferDecoder.skipVarint(0);
bufferDecoder.skipVarint();
expect(bufferDecoder.cursor()).toBe(1);
});
@ -50,13 +50,13 @@ describe('Skip varint does', () => {
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
if (CHECK_CRITICAL_STATE) {
expect(() => bufferDecoder.skipVarint(0)).toThrow();
expect(() => bufferDecoder.skipVarint()).toThrow();
} else {
// Note in unchecked mode we produce invalid output for invalid inputs.
// This test just documents our behavior in those cases.
// These values might change at any point and are not considered
// what the implementation should be doing here.
bufferDecoder.skipVarint(0);
bufferDecoder.skipVarint();
expect(bufferDecoder.cursor()).toBe(11);
}
});
@ -64,7 +64,7 @@ describe('Skip varint does', () => {
it('fail when varint is beyond end of underlying array', () => {
const bufferDecoder =
BufferDecoder.fromArrayBuffer(createArrayBuffer(0x80, 0x80));
expect(() => bufferDecoder.skipVarint(0)).toThrow();
expect(() => bufferDecoder.skipVarint()).toThrow();
});
});

@ -85,7 +85,7 @@ function skipField_(bufferDecoder, wireType, fieldNumber) {
case WireType.VARINT:
checkCriticalElementIndex(
bufferDecoder.cursor(), bufferDecoder.endIndex());
bufferDecoder.skipVarint(bufferDecoder.cursor());
bufferDecoder.skipVarint();
return false;
case WireType.FIXED64:
bufferDecoder.skip(8);

@ -451,7 +451,8 @@ class Writer {
getLength_(bufferDecoder, start, wireType) {
switch (wireType) {
case WireType.VARINT:
bufferDecoder.skipVarint(start);
bufferDecoder.setCursor(start);
bufferDecoder.skipVarint();
return bufferDecoder.cursor() - start;
case WireType.FIXED64:
return 8;

Loading…
Cancel
Save