Best JavaScript code snippet using wpt
Stream.js
Source:Stream.js
1/*2Stream3https://github.com/audiocogs/aurora.js4*/5(function() {6 var decodeString, float64, float64Fallback, float80, nativeEndian;7 var buf = new ArrayBuffer(16),8 uint8 = new Uint8Array(buf),9 int8 = new Int8Array(buf),10 uint16 = new Uint16Array(buf),11 int16 = new Int16Array(buf),12 uint32 = new Uint32Array(buf),13 int32 = new Int32Array(buf),14 float32 = new Float32Array(buf);15 if (typeof Float64Array !== "undefined" && Float64Array !== null) {16 float64 = new Float64Array(buf);17 }18 nativeEndian = new Uint16Array(new Uint8Array([0x12, 0x34]).buffer)[0] === 0x3412;19 function UnderflowError() {20 this.name = 'UnderflowError';21 }22 function Stream(list) {23 this.list = list;24 this.localOffset = 0;25 this.offset = 0;26 }27 Stream.fromBuffer = function(buffer) {28 var list;29 list = new BufferList;30 list.append(buffer);31 return new Stream(list);32 };33 Stream.prototype.copy = function() {34 var result;35 result = new Stream(this.list.copy());36 result.localOffset = this.localOffset;37 result.offset = this.offset;38 return result;39 };40 Stream.prototype.available = function(bytes) {41 return bytes <= this.list.availableBytes - this.localOffset;42 };43 Stream.prototype.remainingBytes = function() {44 return this.list.availableBytes - this.localOffset;45 };46 Stream.prototype.advance = function(bytes) {47 if (!this.available(bytes)) {48 throw new UnderflowError();49 }50 this.localOffset += bytes;51 this.offset += bytes;52 while (this.list.first && this.localOffset >= this.list.first.length) {53 this.localOffset -= this.list.first.length;54 this.list.advance();55 }56 return this;57 };58 Stream.prototype.rewind = function(bytes) {59 if (bytes > this.offset) {60 throw new UnderflowError();61 }62 if (!this.list.first) {63 this.list.rewind();64 this.localOffset = this.list.first.length;65 }66 this.localOffset -= bytes;67 this.offset -= bytes;68 while (this.list.first.prev && this.localOffset < 0) {69 this.list.rewind();70 this.localOffset += this.list.first.length;71 }72 return this;73 };74 Stream.prototype.seek = function(position) {75 if (position > this.offset) {76 return this.advance(position - this.offset);77 } else if (position < this.offset) {78 return this.rewind(this.offset - position);79 }80 };81 Stream.prototype.readUInt8 = function() {82 var a;83 if (!this.available(1)) {84 throw new UnderflowError();85 }86 a = this.list.first.data[this.localOffset];87 this.localOffset += 1;88 this.offset += 1;89 if (this.localOffset === this.list.first.length) {90 this.localOffset = 0;91 this.list.advance();92 }93 return a;94 };95 Stream.prototype.peekUInt8 = function(offset) {96 var buffer;97 if (offset == null) {98 offset = 0;99 }100 if (!this.available(offset + 1)) {101 throw new UnderflowError();102 }103 offset = this.localOffset + offset;104 buffer = this.list.first;105 while (buffer) {106 if (buffer.length > offset) {107 return buffer.data[offset];108 }109 offset -= buffer.length;110 buffer = buffer.next;111 }112 return 0;113 };114 Stream.prototype.read = function(bytes, littleEndian) {115 var i, _i, _j, _ref;116 if (littleEndian == null) {117 littleEndian = false;118 }119 if (littleEndian === nativeEndian) {120 for (i = _i = 0; _i < bytes; i = _i += 1) {121 uint8[i] = this.readUInt8();122 }123 } else {124 for (i = _j = _ref = bytes - 1; _j >= 0; i = _j += -1) {125 uint8[i] = this.readUInt8();126 }127 }128 };129 Stream.prototype.peek = function(bytes, offset, littleEndian) {130 var i, _i, _j;131 if (littleEndian == null) {132 littleEndian = false;133 }134 if (littleEndian === nativeEndian) {135 for (i = _i = 0; _i < bytes; i = _i += 1) {136 uint8[i] = this.peekUInt8(offset + i);137 }138 } else {139 for (i = _j = 0; _j < bytes; i = _j += 1) {140 uint8[bytes - i - 1] = this.peekUInt8(offset + i);141 }142 }143 };144 Stream.prototype.readInt8 = function() {145 this.read(1);146 return int8[0];147 };148 Stream.prototype.peekInt8 = function(offset) {149 if (offset == null) {150 offset = 0;151 }152 this.peek(1, offset);153 return int8[0];154 };155 Stream.prototype.readUInt16 = function(littleEndian) {156 this.read(2, littleEndian);157 return uint16[0];158 };159 Stream.prototype.peekUInt16 = function(offset, littleEndian) {160 if (offset == null) {161 offset = 0;162 }163 this.peek(2, offset, littleEndian);164 return uint16[0];165 };166 Stream.prototype.readInt16 = function(littleEndian) {167 this.read(2, littleEndian);168 return int16[0];169 };170 Stream.prototype.peekInt16 = function(offset, littleEndian) {171 if (offset == null) {172 offset = 0;173 }174 this.peek(2, offset, littleEndian);175 return int16[0];176 };177 Stream.prototype.readUInt24 = function(littleEndian) {178 if (littleEndian) {179 return this.readUInt16(true) + (this.readUInt8() << 16);180 } else {181 return (this.readUInt16() << 8) + this.readUInt8();182 }183 };184 Stream.prototype.peekUInt24 = function(offset, littleEndian) {185 if (offset == null) {186 offset = 0;187 }188 if (littleEndian) {189 return this.peekUInt16(offset, true) + (this.peekUInt8(offset + 2) << 16);190 } else {191 return (this.peekUInt16(offset) << 8) + this.peekUInt8(offset + 2);192 }193 };194 Stream.prototype.readInt24 = function(littleEndian) {195 if (littleEndian) {196 return this.readUInt16(true) + (this.readInt8() << 16);197 } else {198 return (this.readInt16() << 8) + this.readUInt8();199 }200 };201 Stream.prototype.peekInt24 = function(offset, littleEndian) {202 if (offset == null) {203 offset = 0;204 }205 if (littleEndian) {206 return this.peekUInt16(offset, true) + (this.peekInt8(offset + 2) << 16);207 } else {208 return (this.peekInt16(offset) << 8) + this.peekUInt8(offset + 2);209 }210 };211 Stream.prototype.readUInt32 = function(littleEndian) {212 this.read(4, littleEndian);213 return uint32[0];214 };215 Stream.prototype.peekUInt32 = function(offset, littleEndian) {216 if (offset == null) {217 offset = 0;218 }219 this.peek(4, offset, littleEndian);220 return uint32[0];221 };222 Stream.prototype.readInt32 = function(littleEndian) {223 this.read(4, littleEndian);224 return int32[0];225 };226 Stream.prototype.peekInt32 = function(offset, littleEndian) {227 if (offset == null) {228 offset = 0;229 }230 this.peek(4, offset, littleEndian);231 return int32[0];232 };233 Stream.prototype.readFloat32 = function(littleEndian) {234 this.read(4, littleEndian);235 return float32[0];236 };237 Stream.prototype.peekFloat32 = function(offset, littleEndian) {238 if (offset == null) {239 offset = 0;240 }241 this.peek(4, offset, littleEndian);242 return float32[0];243 };244 Stream.prototype.readFloat64 = function(littleEndian) {245 this.read(8, littleEndian);246 if (float64) {247 return float64[0];248 } else {249 return float64Fallback();250 }251 };252 float64Fallback = function() {253 var exp, frac, high, low, out, sign;254 low = uint32[0], high = uint32[1];255 if (!high || high === 0x80000000) {256 return 0.0;257 }258 sign = 1 - (high >>> 31) * 2;259 exp = (high >>> 20) & 0x7ff;260 frac = high & 0xfffff;261 if (exp === 0x7ff) {262 if (frac) {263 return NaN;264 }265 return sign * Infinity;266 }267 exp -= 1023;268 out = (frac | 0x100000) * Math.pow(2, exp - 20);269 out += low * Math.pow(2, exp - 52);270 return sign * out;271 };272 Stream.prototype.peekFloat64 = function(offset, littleEndian) {273 if (offset == null) {274 offset = 0;275 }276 this.peek(8, offset, littleEndian);277 if (float64) {278 return float64[0];279 } else {280 return float64Fallback();281 }282 };283 Stream.prototype.readFloat80 = function(littleEndian) {284 this.read(10, littleEndian);285 return float80();286 };287 float80 = function() {288 var a0, a1, exp, high, low, out, sign;289 high = uint32[0], low = uint32[1];290 a0 = uint8[9];291 a1 = uint8[8];292 sign = 1 - (a0 >>> 7) * 2;293 exp = ((a0 & 0x7F) << 8) | a1;294 if (exp === 0 && low === 0 && high === 0) {295 return 0;296 }297 if (exp === 0x7fff) {298 if (low === 0 && high === 0) {299 return sign * Infinity;300 }301 return NaN;302 }303 exp -= 16383;304 out = low * Math.pow(2, exp - 31);305 out += high * Math.pow(2, exp - 63);306 return sign * out;307 };308 Stream.prototype.peekFloat80 = function(offset, littleEndian) {309 if (offset == null) {310 offset = 0;311 }312 this.peek(10, offset, littleEndian);313 return float80();314 };315 Stream.prototype.readBuffer = function(length) {316 var i, result, to, _i;317 result = Buffer.allocate(length);318 to = result.data;319 for (i = _i = 0; _i < length; i = _i += 1) {320 to[i] = this.readUInt8();321 }322 return result;323 };324 Stream.prototype.peekBuffer = function(offset, length) {325 var i, result, to, _i;326 if (offset == null) {327 offset = 0;328 }329 result = BufferJS.allocate(length);330 to = result.data;331 for (i = _i = 0; _i < length; i = _i += 1) {332 to[i] = this.peekUInt8(offset + i);333 }334 return result;335 };336 Stream.prototype.readSingleBuffer = function(length) {337 var result;338 result = this.list.first.slice(this.localOffset, length);339 this.advance(result.length);340 return result;341 };342 Stream.prototype.peekSingleBuffer = function(offset, length) {343 var result;344 result = this.list.first.slice(this.localOffset + offset, length);345 return result;346 };347 Stream.prototype.readString = function(length, encoding) {348 if (encoding == null) {349 encoding = 'ascii';350 }351 return decodeString.call(this, 0, length, encoding, true);352 };353 Stream.prototype.peekString = function(offset, length, encoding) {354 if (offset == null) {355 offset = 0;356 }357 if (encoding == null) {358 encoding = 'ascii';359 }360 return decodeString.call(this, offset, length, encoding, false);361 };362 decodeString = function(offset, length, encoding, advance) {363 var b1, b2, b3, b4, bom, c, end, littleEndian, nullEnd, pt, result, w1, w2;364 encoding = encoding.toLowerCase();365 nullEnd = length === null ? 0 : -1;366 if (length == null) {367 length = Infinity;368 }369 end = offset + length;370 result = '';371 switch (encoding) {372 case 'ascii':373 case 'latin1':374 while (offset < end && (c = this.peekUInt8(offset++)) !== nullEnd) {375 result += String.fromCharCode(c);376 }377 break;378 case 'utf8':379 case 'utf-8':380 while (offset < end && (b1 = this.peekUInt8(offset++)) !== nullEnd) {381 if ((b1 & 0x80) === 0) {382 result += String.fromCharCode(b1);383 } else if ((b1 & 0xe0) === 0xc0) {384 b2 = this.peekUInt8(offset++) & 0x3f;385 result += String.fromCharCode(((b1 & 0x1f) << 6) | b2);386 } else if ((b1 & 0xf0) === 0xe0) {387 b2 = this.peekUInt8(offset++) & 0x3f;388 b3 = this.peekUInt8(offset++) & 0x3f;389 result += String.fromCharCode(((b1 & 0x0f) << 12) | (b2 << 6) | b3);390 } else if ((b1 & 0xf8) === 0xf0) {391 b2 = this.peekUInt8(offset++) & 0x3f;392 b3 = this.peekUInt8(offset++) & 0x3f;393 b4 = this.peekUInt8(offset++) & 0x3f;394 pt = (((b1 & 0x0f) << 18) | (b2 << 12) | (b3 << 6) | b4) - 0x10000;395 result += String.fromCharCode(0xd800 + (pt >> 10), 0xdc00 + (pt & 0x3ff));396 }397 }398 break;399 case 'utf16-be':400 case 'utf16be':401 case 'utf16le':402 case 'utf16-le':403 case 'utf16bom':404 case 'utf16-bom':405 switch (encoding) {406 case 'utf16be':407 case 'utf16-be':408 littleEndian = false;409 break;410 case 'utf16le':411 case 'utf16-le':412 littleEndian = true;413 break;414 case 'utf16bom':415 case 'utf16-bom':416 if (length < 2 || (bom = this.peekUInt16(offset)) === nullEnd) {417 if (advance) {418 this.advance(offset += 2);419 }420 return result;421 }422 littleEndian = bom === 0xfffe;423 offset += 2;424 }425 while (offset < end && (w1 = this.peekUInt16(offset, littleEndian)) !== nullEnd) {426 offset += 2;427 if (w1 < 0xd800 || w1 > 0xdfff) {428 result += String.fromCharCode(w1);429 } else {430 if (w1 > 0xdbff) {431 throw new Error("Invalid utf16 sequence.");432 }433 w2 = this.peekUInt16(offset, littleEndian);434 if (w2 < 0xdc00 || w2 > 0xdfff) {435 throw new Error("Invalid utf16 sequence.");436 }437 result += String.fromCharCode(w1, w2);438 offset += 2;439 }440 }441 if (w1 === nullEnd) {442 offset += 2;443 }444 break;445 default:446 throw new Error("Unknown encoding: " + encoding);447 }448 if (advance) {449 this.advance(offset);450 }451 return result;452 };453 window.Stream = Stream;...
threads.js
Source:threads.js
...13 var sp = Debug.evaluate("((CTL_TASK_t*)"+x+")->stack_pointer");14 var a = new Array();15 for (i=4;i<=15;i++) // r4-r15 saved16 {17 a[i] = TargetInterface.peekUint16(sp);18 sp += 2;19 }20 a[3] = 0; // r3 isn't saved 21 a[2] = TargetInterface.peekUint16(sp); // sr+pc22 a[0] = (a[2]&0xf000)<<4;23 a[2] &= 0x0fff;24 sp += 2;25 a[0] |= TargetInterface.peekUint16(sp); // pc26 sp += 2;27 a[1] = sp; // r1/sp28 return a;29}30function setregs(x, a)31{32 var sp = a[1];33 sp -= 2;34 TargetInterface.pokeUint16(sp, a[0]); // pc35 sp -= 2;36 var srpc = (a[2] & 0x0fff)+((a[0] >> 4) & 0xf000);37 TargetInterface.pokeUint16(sp, srpc); // sr+pc38 for (i=15;i>=4;i--)39 {...
StreamReader.ts
Source:StreamReader.ts
...35 public peekByte() {36 return this.peekUint8()37 }38 public readUint16() {39 const v = this.peekUint16()40 this.pointer += 241 return v42 }43 public peekUint16() {44 return this.view.getUint16(this.pointer)45 }46 public readLine() {47 let char = ''48 let result = ''49 while (char !== '\n') {50 result += char51 char = String.fromCharCode(this.readUint8())52 }53 return result54 }...
Using AI Code Generation
1const { ReadableStream, WritableStream, CountQueuingStrategy, ByteLengthQueuingStrategy } = require('web-streams-polyfill/ponyfill');2const rs = new ReadableStream({3 start(controller) {4 controller.enqueue(new Uint8Array([65, 66, 67, 68, 69, 70, 71, 72]));5 controller.close();6 }7});8rs.pipeThrough(new TextDecoderStream())9 .pipeTo(new WritableStream({10 write(chunk) {11 console.log(chunk);12 },13 close() {14 console.log('done');15 }16 }));
Using AI Code Generation
1var ab = new ArrayBuffer(2);2var u16 = new Uint16Array(ab);3u16[0] = 0x1234;4var u8 = new Uint8Array(ab);5assert_equals(u8.peekUint16(), 0x1234);6assert_equals(u8.peekUint16(0), 0x1234);7assert_equals(u8.peekUint16(1), 0x3400);8assert_equals(u8.peekUint16(2), 0x1234);9assert_equals(u8.peekUint16(3), 0x3400);10assert_equals(u8.peekUint16(4), 0x1234);11assert_equals(u8.peekUint16(5), 0x3400);12assert_equals(u8.peekUint16(6), 0x1234);13assert_equals(u8.peekUint16(7), 0x3400);14assert_equals(u8.peekUint16(8), 0x1234);15assert_equals(u8.peekUint16(9), 0x3400);16assert_equals(u8.peekUint16(10), 0x1234);17assert_equals(u8.peekUint16(11), 0x3400);18assert_equals(u8.peekUint16(12), 0x1234);19assert_equals(u8.peekUint16(13), 0x3400);20assert_equals(u8.peekUint16(14), 0x1234);21assert_equals(u8.peekUint16(15), 0x3400);22assert_equals(u8.peekUint16(16), 0x1234);23assert_equals(u8.peekUint16(17), 0x3400);24assert_equals(u8.peekUint16(18), 0x1234);25assert_equals(u8.peekUint16(19), 0x3400);26assert_equals(u8.peekUint16(20), 0x1234);27assert_equals(u8.peekUint16(21), 0x3400);28assert_equals(u8.peekUint16(22), 0x1234);29assert_equals(u8.peekUint16(23), 0x3400);30assert_equals(u8.peekUint16(24), 0x1234);31assert_equals(u8.peekUint16(25), 0x3400);32assert_equals(u8.peekUint16(26), 0x1234);33assert_equals(u8.peekUint16(27),
Using AI Code Generation
1function peekUint16Test() {2 var arrayBuffer = new ArrayBuffer(16);3 var int16View = new Int16Array(arrayBuffer);4 var uint16View = new Uint16Array(arrayBuffer);5 var dataView = new DataView(arrayBuffer);6 var littleEndian = true;7 var bigEndian = false;8 for (var i = 0; i < int16View.length; i++) {9 int16View[i] = i;10 }11 for (var i = 0; i < int16View.length; i++) {12 assert_equals(dataView.peekUint16(i * 2, littleEndian), i);13 assert_equals(dataView.peekUint16(i * 2, bigEndian), i);14 }15 for (var i = int16View.length - 1; i >= 0; i--) {16 assert_equals(dataView.peekUint16(i * 2, littleEndian), i);17 assert_equals(dataView.peekUint16(i * 2, bigEndian), i);18 }19 for (var i = 0; i < uint16View.length; i++) {20 assert_equals(dataView.peekUint16(i * 2, littleEndian), uint16View[i]);21 assert_equals(dataView.peekUint16(i * 2, bigEndian), uint16View[i]);22 }23 for (var i = uint16View.length - 1; i >= 0; i--) {24 assert_equals(dataView.peekUint16(i * 2, littleEndian), uint16View[i]);25 assert_equals(dataView.peekUint16(i * 2, bigEndian), uint16View[i]);26 }27 for (var i = 0; i < int16View.length; i++) {28 assert_equals(dataView.peekUint16(i * 2, littleEndian), int16View[i]);29 assert_equals(dataView.peekUint16(i * 2, bigEndian), int16View[i]);30 }
Using AI Code Generation
1var wpt = require('wpt');2var buf = new Buffer(4);3buf.writeUInt16BE(0x1234, 0);4buf.writeUInt16BE(0x5678, 2);5var peek = wpt.peekUint16(buf, 2);6console.log(peek);7## peekUint32(buf, offset)8var wpt = require('wpt');9var buf = new Buffer(8);10buf.writeUInt32BE(0x12345678, 0);11buf.writeUInt32BE(0x9abcdef0, 4);12var peek = wpt.peekUint32(buf, 4);13console.log(peek);14## peekInt8(buf, offset)15var wpt = require('wpt');16var buf = new Buffer(2);17buf.writeInt8(0x12, 0);18buf.writeInt8(0x34, 1);19var peek = wpt.peekInt8(buf, 1);20console.log(peek);21## peekInt16(buf, offset)
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Albert Einstein');3wp.peekUint16(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10## peekUint32(callback)11var wptools = require('wptools');12var wp = new wptools('Albert Einstein');13wp.peekUint32(function(err, data) {14 if (err) {15 console.log('Error: ' + err);16 } else {17 console.log(data);18 }19});20## peekUint64(callback)21var wptools = require('wptools');22var wp = new wptools('Albert Einstein');23wp.peekUint64(function(err, data) {24 if (err) {25 console.log('Error: ' + err);26 } else {27 console.log(data);28 }29});30## peekUint128(callback)31var wptools = require('wptools');32var wp = new wptools('Albert Einstein');33wp.peekUint128(function(err, data) {34 if (err) {35 console.log('Error: ' + err);36 } else {37 console.log(data);38 }39});40## peekUint256(callback)41var wptools = require('wptools');42var wp = new wptools('Albert Einstein');43wp.peekUint256(function(err, data) {44 if (err) {45 console.log('Error: ' + err);46 } else {47 console.log(data);48 }49});50## peekUint512(callback)51var wptools = require('wptools');52var wp = new wptools('Albert Einstein');53wp.peekUint512(function(err, data) {54 if (err) {55 console.log('Error: ' + err
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt();3var buffer = new Buffer(4);4buffer[0] = 0x12;5buffer[1] = 0x34;6buffer[2] = 0x56;7buffer[3] = 0x78;8var val = wpt.peekUint16(buffer, 0, true);9val = wpt.peekUint16(buffer, 0, false);10## peekUint32(buffer, offset, littleEndian)11var wpt = require('wpt');12var wpt = new wpt();13var buffer = new Buffer(4);14buffer[0] = 0x12;15buffer[1] = 0x34;16buffer[2] = 0x56;17buffer[3] = 0x78;18var val = wpt.peekUint32(buffer, 0, true);19val = wpt.peekUint32(buffer, 0, false);20## peekInt8(buffer, offset)21var wpt = require('wpt');22var wpt = new wpt();23var buffer = new Buffer(4);24buffer[0] = 0x12;25buffer[1] = 0x34;26buffer[2] = 0x56;27buffer[3] = 0x78;28var val = wpt.peekInt8(buffer, 0);29## peekInt16(buffer, offset, littleEndian)30var wpt = require('wpt');
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var location = 'Dulles:Chrome';4wpt.runTest(url, {location: location}, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 wpt.getTestResults(data.data.testId, function(err, data) {10 if (err) {11 console.log(err);12 } else {13 console.log(data);14 }15 });16 }17});
Using AI Code Generation
1var wpt = require('webpage').create();2var fs = require('fs');3var page = require('webpage').create();4var output = 'output.png';5var width = 1024;6var height = 768;7var page = require('webpage').create();8page.viewportSize = { width: width, height: height };9page.open(url, function(status) {10 if (status !== 'success') {11 console.log('Unable to load the address!');12 } else {13 window.setTimeout(function() {14 page.render(output);15 phantom.exit();16 }, 200);17 }18});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!