How to use typed_array method in wpt

Best JavaScript code snippet using wpt

bignumber.js

Source:bignumber.js Github

copy

Full Screen

1/**2 * BigNumber3 * @author Malte Pagel4 */5function BigNumber (byte_length, bytes_per_entry, src_typed_array) {6 7 var typed_array;8 var myself = this;9 10 /* */11 12 function set_bit (bit, collection) {13 14 collection = collection || typed_array;15 16 if ( !bit || bit > bits * collection.length )17 return;18 19 var entry, single_bit;20 for ( var i = bit; i <= bits * collection.length; i++ ) {21 entry = collection.length - parseInt( (i - 1) / bits ) - 1;22 single_bit = (i - 1) % bits;23 if ( collection[entry] & (1 << single_bit) ) {24 collection[entry] ^= 1 << single_bit;25 continue;26 }27 collection[entry] |= 1 << single_bit;28 break;29 }30 }31 this.set_bit = set_bit;32 function unset_bit (bit, collection) {33 34 collection = collection || typed_array;35 36 if ( !bit || bit > bits * collection.length )37 return;38 39 var entry, single_bit;40 entry = collection.length - parseInt( (bit - 1) / bits ) - 1;41 single_bit = (bit - 1) % bits;42 if ( collection[entry] & (1 << single_bit) ) {43 collection[entry] ^= 1 << single_bit;44 return;45 }46 47 collection[entry] |= 1 << single_bit;48 49 for ( var i = (bit + 1); i <= bits * collection.length; i++ ) {50 entry = collection.length - parseInt( (i - 1) / bits ) - 1;51 single_bit = (i - 1) % bits;52 if ( collection[entry] & (1 << single_bit) ) {53 collection[entry] ^= 1 << single_bit;54 break;55 }56 collection[entry] |= 1 << single_bit;57 }58 }59 this.unset_bit = unset_bit;60 61 this.negate = function () {62 for ( var i = 0; i < typed_array.length; i++ )63 typed_array[i] = (~typed_array[i]) & MAX_VALUE;64 };65 this.twos_complement = function () {66 for ( var i = 0; i < typed_array.length; i++ )67 typed_array[i] = (~typed_array[i]) & MAX_VALUE;68 set_bit(1);69 };70 71 this.or = function (bignum) {72 var bignum_collection = bignum.to_collection();73 var length = Math.max(bignum_collection.length, typed_array.length);74 var result = myself.copy(length);75 var result_collection = result.to_collection();76 for ( var i = 0; i < length; i++ ) {77 if ( i < bignum_collection.length && i < typed_array.length )78 result_collection[length - i - 1] = bignum_collection[bignum_collection.length - i - 1] | typed_array[typed_array.length - i - 1];79 else {80 if ( length == typed_array.length )81 break;82 result_collection[length - i - 1] = bignum_collection[bignum_collection.length - i - 1];83 }84 }85 return reduce(result);86 };87 this.xor = function (bignum) {88 var bignum_collection = bignum.to_collection();89 var length = Math.max(bignum_collection.length, typed_array.length);90 var result = myself.copy(length);91 var result_collection = result.to_collection();92 for ( var i = 0; i < length; i++ ) {93 if ( i < bignum_collection.length && i < typed_array.length )94 result_collection[length - i - 1] = bignum_collection[bignum_collection.length - i - 1] ^ typed_array[typed_array.length - i - 1];95 else {96 if ( length == typed_array.length )97 result_collection[length - i - 1] = typed_array[typed_array.length - i - 1] ^ 0;98 else99 result_collection[length - i - 1] = bignum_collection[bignum_collection.length - i - 1] ^ 0;100 }101 }102 return reduce(result);103 };104 this.and = function (bignum, do_not_reduce) {105 var bignum_collection = bignum.to_collection();106 var length = Math.max(bignum_collection.length, typed_array.length);107 var result = myself.copy(length);108 var result_collection = result.to_collection();109 for ( var i = 0; i < length; i++ ) {110 if ( i < bignum_collection.length && i < typed_array.length )111 result_collection[length - i - 1] = bignum_collection[bignum_collection.length - i - 1] & typed_array[typed_array.length - i - 1];112 else113 result_collection[length - i - 1] = 0;114 }115 if ( do_not_reduce )116 return result;117 return reduce(result);118 };119 120 function shift_left (bit) {121 122 var i;123 var entry = parseInt( bit / bits );124 if ( entry ) {125 for ( i = 0; i < typed_array.length - entry; i++ ) {126 typed_array[i] = typed_array[i + entry];127 typed_array[i + entry] = 0;128 }129 }130 bit %= bits;131 if ( bit ) {132 var tmp;133 for ( i = 0; i < typed_array.length; i++ ) {134 tmp = typed_array[i] << bit;135 typed_array[i] = tmp & MAX_VALUE;136 if ( i )137 typed_array[i - 1] |= tmp >> bits;138 }139 }140 }141 function shift_right (bit) {142 143 var i;144 var entry = parseInt( bit / bits );145 if ( entry ) {146 for ( i = typed_array.length - 1; i >= entry; i-- ) {147 typed_array[i] = typed_array[i - entry];148 typed_array[i - entry] = 0;149 }150 if ( entry * 2 >= typed_array.length ) {151 for ( i = 0; i < entry; i++ )152 typed_array[i] = 0;153 }154 }155 bit %= bits;156 if ( bit ) {157 var tmp;158 for ( i = typed_array.length - 1; i >= 0; i-- ) {159 if ( i < typed_array.length - 1 )160 typed_array[i + 1] |= (typed_array[i] << (bits - bit)) & MAX_VALUE;161 typed_array[i] >>= bit;162 }163 }164 }165 166 function plus (first, second) {167 var result, overflow;168 do {169 result = first ^ second;170 overflow = (first & second) << 1;171 first = result;172 second = overflow;173 } while (overflow);174 return result;175 }176 function minus (first, second) {177 178 var result, overflow;179 var next_bit = 0;180 181 if ( !(first & 1) && !(second & 1) ) {182 first |= 1;183 second |= 1;184 }185 186 if ( second & 1 ) {187 second = ((~second) | 1) & MAX_VALUE;188 result = plus(first, second);189 next_bit = (result & ONE_ENTRY) ? 0 : ONE_ENTRY;190 result &= MAX_VALUE;191 }192 else {193 do {194 result = (first ^ second) & MAX_VALUE;195 overflow = (result & second) << 1;196 next_bit = next_bit || (overflow & ONE_ENTRY);197 first = result;198 second = overflow;199 } while (overflow);200 }201 202 return ( result | next_bit );203 }204 205 function add (first_col, second_col) {206 207 var loops = Math.min(first_col.length, second_col.length);208 var i, first_index, second_index, tmp_sum;209 for ( i = 1; i <= loops; i++ ) {210 first_index = first_col.length - i;211 second_index = second_col.length - i;212 if ( !first_col[first_index] && !second_col[second_index] )213 continue;214 tmp_sum = plus(first_col[first_index], second_col[second_index]);215 first_col[first_index] = tmp_sum & MAX_VALUE;216 if ( tmp_sum >> bits )217 set_bit( i * bits + 1, first_col );218 }219 }220 221 function subtract (first_col, second_col) {222 223 var i, tmp_sub;224 var positive = compare(first_col, second_col);225 if ( positive <= 0 ) {226 for ( i = 0; i < first_col.length; i++ ) {227 first_col[i] = 0;228 }229 return;230 }231 for ( i = first_col.length - 1; i >= 0; i-- ) {232 if ( !first_col[i] && !second_col[i] )233 continue;234 tmp_sub = minus(first_col[i], second_col[i]);235 first_col[i] = tmp_sub & MAX_VALUE;236 if ( tmp_sub >> bits )237 set_bit( (first_col.length - i) * bits + 1, second_col );238 }239 }240 241 function multiplicate (factor1, factor2) {242 243 var multiplicator_col = factor2.to_collection();244 245 var multiplicator_index, bit, to_add;246 var additions = [];247 for ( var i = 0; i < multiplicator_col.length; i++ ) {248 multiplicator_index = multiplicator_col.length - i - 1;249 if ( !multiplicator_col[multiplicator_index] )250 continue;251 for ( bit = 0; bit < bits; bit++ ) {252 if ( !(multiplicator_col[multiplicator_index] & (1 << bit)) )253 continue;254 to_add = factor1.copy(typed_array.length * bytes_per_entry);255 to_add.shift_by(i * bits + bit);256 additions.push(to_add);257 }258 }259 260 myself.increase_by.apply(null, additions);261 }262 263 function divide (dividend, divisor, result) {264 265 var dividend_col = dividend.to_collection();266 var divisor_col = divisor.to_collection();267 268 var bit, dividend_msb;269 for ( bit = bits; bit >= 1; bit-- ) {270 if ( dividend_col[0] & (1 << (bit - 1)) ) {271 dividend_msb = bit;272 break;273 }274 }275 if ( dividend_msb )276 dividend_msb += (dividend_col.length - 1) * bits;277 if ( !divisor.msb ) {278 for ( bit = bits; bit >= 1; bit-- ) {279 if ( divisor_col[0] & (1 << (bit - 1)) ) {280 divisor.msb = bit;281 break;282 }283 }284 divisor.msb += (divisor_col.length - 1) * bits;285 }286 287 var shift = dividend_msb - divisor.msb;288 289 if ( !dividend_msb || shift < 0 || (shift == 0 && compare(dividend_col, divisor_col) < 0) ) {290 result.modulo = dividend;291 return;292 }293 294 var long_divisor = divisor.copy(dividend_col.length * bytes_per_entry);295 long_divisor.shift_by(shift);296 if ( shift && compare(dividend_col, long_divisor.to_collection()) < 0 ) {297 long_divisor.shift_by(-1);298 shift--;299 }300 301 set_bit(shift + 1, result.to_collection());302 dividend.decrease_by(long_divisor);303 divide(reduce(dividend), divisor, result);304 }305 306 function sqrt (src) {307 308 var src_collection = src.to_collection();309 310 var core;311 for ( var i = bits - 2; i >= 0; i -= 2 ) {312 if ( src_collection[0] & (3 << i) ) {313 core = i + 1;314 break;315 }316 }317 if ( core == null )318 return;319 core += (src_collection.length - 1) * bits;320 unset_bit(core, src_collection);321 core++;322 core /= 2;323 set_bit(core);324 325 var tmp_result, do_it;326 for ( var bit = (core - 1); bit >= 1; bit-- ) {327 tmp_result = myself.copy(src_collection.length * bytes_per_entry);328 tmp_result.shift_by(bit);329 set_bit(bit * 2 - 1, tmp_result.to_collection());330 do_it = compare( src_collection, tmp_result.to_collection() );331 if ( do_it < 0 )332 continue;333 set_bit(bit);334 if ( !do_it )335 return;336 src.decrease_by(tmp_result);337 }338 }339 340 function pow (base, exponent) {341 var exp_col = exponent.to_collection();342 if ( exp_col.length == 1 ) {343 if ( !exp_col[0] ) {344 var result = new BigNumber(1, typed_array.BYTES_PER_ELEMENT);345 result.from_number(1);346 return result;347 }348 if ( !(exp_col[0] ^ 1) )349 return reduce(base);350 }351 if ( exp_col[exp_col.length - 1] & 1 || (exp_col.length == 1 && !(exp_col[0] ^ 2)) ) {352 unset_bit(1, exp_col);353 return base.multiplicate(pow(base, exponent));354 }355 var two = new BigNumber(1, typed_array.BYTES_PER_ELEMENT);356 two.from_number(2);357 exponent.shift_by(-1);358 return pow(pow(base, two), reduce(exponent));359 }360 361 function mod_pow (base, exponent, modulo) {362 var exp_col = exponent.to_collection();363 if ( exp_col.length == 1 ) {364 if ( !exp_col[0] ) {365 var result = new BigNumber(1, typed_array.BYTES_PER_ELEMENT);366 result.from_number(1);367 return result;368 }369 if ( !(exp_col[0] ^ 1) )370 return base.mod(modulo);371 }372 if ( exp_col[exp_col.length - 1] & 1 || (exp_col.length == 1 && !(exp_col[0] ^ 2)) ) {373 unset_bit(1, exp_col);374 return base.mod(modulo).multiplicate(mod_pow(base, exponent, modulo)).mod(modulo);375 }376 var two = new BigNumber(1, typed_array.BYTES_PER_ELEMENT);377 two.from_number(2);378 exponent.shift_by(-1);379 return mod_pow(mod_pow(base, two, modulo), reduce(exponent), modulo);380 }381 382 383 function compare (first_col, second_col) {384 385 var i;386 var first_start = first_col.length;387 var second_start = second_col.length;388 for ( i = 0; i < first_col.length; i++ ) {389 if ( !first_col[i] )390 continue;391 first_start = i;392 break;393 }394 for ( i = 0; i < second_col.length; i++ ) {395 if ( !second_col[i] )396 continue;397 second_start = i;398 break;399 }400 if ( (first_col.length - first_start) != (second_col.length - second_start) )401 return (first_col.length - first_start) - (second_col.length - second_start);402 403 for ( i = 0; i < first_col.length - first_start; i++ ) {404 if ( !(first_col[i + first_start] ^ second_col[i + second_start]) )405 continue;406 if ( !(minus(first_col[i + first_start], second_col[i + second_start]) & ONE_ENTRY) )407 return 1;408 return -1;409 }410 411 return 0;412 }413 414 function reduce (big_number) {415 416 var collection = big_number.to_collection();417 if ( collection[0] )418 return big_number;419 var i, start;420 for ( i = 0; i < collection.length; i++ ) {421 if ( !collection[i] )422 continue;423 start = i;424 break;425 }426 if ( start == null )427 return new BigNumber(bytes_per_entry, collection.BYTES_PER_ELEMENT);428 var result = new BigNumber((collection.length - start) * bytes_per_entry, collection.BYTES_PER_ELEMENT);429 var result_collection = result.to_collection();430 result_collection.set(collection.slice(start));431 432 return result;433 }434 435 /* */436 437 this.shift_by = function (bit) {438 if ( bit > 0 )439 shift_left(bit);440 if ( bit < 0 )441 shift_right(0 - bit);442 };443 444 this.increase_by = function () {445 var args = arguments.callee.arguments;446 for ( var i = 0; i < args.length; i++ )447 add(typed_array, args[i].to_collection());448 };449 this.add = function () {450 var args = arguments.callee.arguments;451 var big_numbers_to_collection = [];452 var length = typed_array.length;453 var tmp, i;454 for ( i = 0; i < args.length; i++ ) {455 tmp = args[i].to_collection();456 big_numbers_to_collection.push(tmp);457 if ( tmp.length > length )458 length = tmp.length;459 }460 length = bytes_per_entry * (length + 1 + ((big_numbers_to_collection.length + 1) >> bits));461 var result = myself.copy(length);462 var result_col = result.to_collection();463 for ( i = 0; i < big_numbers_to_collection.length; i++ )464 add(result_col, big_numbers_to_collection[i]);465 return reduce(result);466 };467 468 this.decrease_by = function () {469 var args = arguments.callee.arguments;470 var to_subtract = args[0].copy();471 if ( args.length > 1 ) {472 for ( var i = 1; i < args.length; i++ )473 to_subtract = to_subtract.add(args[i]);474 }475 subtract(typed_array, reduce(to_subtract).copy(typed_array.length * bytes_per_entry).to_collection());476 };477 this.subtract = function () {478 var result = myself.copy();479 result.decrease_by.apply(null, arguments.callee.arguments);480 return reduce(result);481 };482 483 this.multiplicate = function (arg1, arg2) {484 if ( arguments.callee.arguments.length > 1 ) {485 multiplicate(arg1, arg2);486 return;487 }488 var multiplicator_collection = arg1.to_collection();489 var result_bytes = (typed_array.length + multiplicator_collection.length) * bytes_per_entry;490 var result = new BigNumber(result_bytes, typed_array.BYTES_PER_ELEMENT);491 if ( compare(typed_array, multiplicator_collection) >= 0 )492 result.multiplicate(myself, arg1);493 else494 result.multiplicate(arg1, myself);495 return reduce(result);496 };497 498 this.divide = function (bignum, do_not_reduce) {499 var dividend = reduce(myself.copy());500 var dividend_collection = dividend.to_collection();501 var divisor = reduce(bignum);502 var divisor_collection = divisor.to_collection();503 if ( dividend_collection.length < divisor_collection.length || (divisor_collection.length == 1 && !divisor_collection[0]) )504 return new BigNumber(1, typed_array.BYTES_PER_ELEMENT);505 var result_bytes = (dividend_collection.length - divisor_collection.length) * bytes_per_entry + 1;506 var result = new BigNumber(result_bytes, typed_array.BYTES_PER_ELEMENT);507 divisor.msb = null;508 var redundant = divide(dividend, divisor, result);509 if ( do_not_reduce )510 return result;511 return reduce(result);512 };513 this.mod = function (bignum) {514 var result = myself.divide(bignum, true);515 return result.modulo || reduce(myself.copy());516 };517 518 this.sqrt = function (src) {519 if ( src ) {520 sqrt(src);521 return;522 }523 var result = new BigNumber(typed_array.length + 1, typed_array.BYTES_PER_ELEMENT);524 result.sqrt(reduce(myself.copy()));525 return reduce(result);526 };527 528 this.pow = function (raw_exp) {529 if ( (typeof raw_exp).toUpperCase() == "NUMBER" ) {530 var long_exp = new BigNumber(8, typed_array.BYTES_PER_ELEMENT);531 long_exp.from_number(raw_exp);532 }533 else534 var long_exp = raw_exp.copy();535 var exp = reduce(long_exp);536 var base = myself.copy();537 return pow(base, exp);538 };539 540 this.mod_pow = function (raw_exp, raw_mod) {541 if ( (typeof raw_exp).toUpperCase() == "NUMBER" ) {542 var long_exp = new BigNumber(8, typed_array.BYTES_PER_ELEMENT);543 long_exp.from_number(raw_exp);544 }545 else546 var long_exp = raw_exp.copy();547 var exp = reduce(long_exp);548 if ( (typeof raw_mod).toUpperCase() == "NUMBER" ) {549 var long_mod = new BigNumber(8, typed_array.BYTES_PER_ELEMENT);550 long_mod.from_number(raw_mod);551 }552 else553 var long_mod = raw_mod.copy();554 var mod = reduce(long_mod);555 var base = myself.copy();556 return mod_pow(base, exp, mod);557 };558 559 /* */560 561 function different_base_formatted_string (input_base, output_base, collection, output_characters) {562 563 var base = input_base || ONE_ENTRY;564 output_base = output_base || 10;565 566 var i, started;567 var input = collection || [];568 if ( !input.length ) {569 for ( i = 0; i < typed_array.length; i++ ) {570 if ( !started && !typed_array[i] )571 continue;572 started = true;573 input.push( typed_array[i] );574 }575 }576 var output = [];577 var rest;578 var position = 0;579 while ( position < input.length ) {580 rest = 0;581 for ( i = 0; i < input.length; i++ ) {582 rest = rest * base + input[i];583 input[i] = parseInt(rest / output_base);584 rest -= input[i] * output_base;585 if ( !input[i] && i == position )586 position++;587 }588 if ( output_characters )589 output.push( output_characters[rest] );590 else591 output.push( rest );592 }593 594 output.reverse();595 596 return output.join("");597 }598 this.copy = function (bytes) {599 bytes = (bytes && bytes >= buffer.byteLength) ? bytes : buffer.byteLength;600 return new BigNumber(bytes, typed_array.BYTES_PER_ELEMENT, typed_array);601 };602 603 /* */604 605 this.from_number = function (number) {606 607 var counter = typed_array.length - 1;608 609 typed_array[counter] = number & MAX_VALUE;610 while ( number && counter ) {611 counter--;612 number = number >> bits;613 typed_array[counter] = number & MAX_VALUE;614 }615 };616 this.from_hex = function (mixed) {617 618 var src = [];619 var i;620 var src_string = "";621 if ( (typeof mixed).toUpperCase() == "OBJECT" && mixed.length ) {622 for ( i = 0; i < mixed.length; i++ )623 src_string += mixed[i];624 }625 else626 src_string = mixed.toLowerCase().replace(/[^\da-f]/g, "");627 628 src = src_string.split("");629 630 if ( !src )631 return;632 633 var counter = typed_array.length;634 var tmp_number, number;635 var shift = 0;636 for ( i = src.length - 1; i >= 0; i-- ) {637 tmp_number = parseInt(src[i], 16);638 if ( !(shift % bits) ) {639 if ( number )640 typed_array[counter] = number;641 shift = 0;642 number = 0;643 counter--;644 }645 number += tmp_number << shift;646 shift += 4;647 }648 649 typed_array[counter] = number;650 };651 this.from_decimal = function (string) {652 var collection = string.split("").map(function(int){return parseInt(int)});653 var output_characters = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" ];654 var translated = different_base_formatted_string(10, 16, collection, output_characters);655 myself.from_hex(translated);656 };657 this.from_base64 = function (string) {658 var asciified = atob(string).split("");659 var char_number, index;660 for ( var i = 0; i < asciified.length && i < byte_length; i++ ) {661 char_number = asciified[asciified.length - i - 1].charCodeAt(0);662 index = typed_array.length - parseInt(i / bytes_per_entry) - 1;663 if ( bytes_per_entry == 2 && i % 2 )664 char_number <<= 8;665 typed_array[index] += char_number;666 }667 };668 669 /* */670 671 // Javascript limitations to be regarded - eventually will slowly return string672 this.to_number = function () {673 674 var shift = 0;675 676 if ( typed_array.length * bits >= 32 )677 return different_base_formatted_string() || "0";678 679 var number = 0;680 for ( var i = typed_array.length - 1; i >= 0; i-- ) {681 number += typed_array[i] << shift;682 shift += bits;683 }684 685 return number;686 };687 this.to_collection = function () {688 return typed_array;689 };690 this.to_hex = function () {691 692 var hex_digits_per_entry = bytes_per_entry * 2;693 694 var hex_number = "";695 var tmp_hex;696 for ( var i = 0; i < typed_array.length; i++ ) {697 tmp_hex = typed_array[i].toString(16);698 while ( tmp_hex.length < hex_digits_per_entry )699 tmp_hex = "0" + tmp_hex;700 hex_number += tmp_hex;701 }702 703 var copied = hex_number;704 705 do {706 hex_number = copied;707 copied = hex_number.replace(/^00/, "")708 } while ( copied != hex_number );709 710 return hex_number;711 };712 this.to_base64 = function () {713 var aciified = to_ascii();714 return btoa(aciified);715 };716 function to_ascii () {717 718 var recognised = false;719 var i, number, tmp_collection;720 var result = "";721 for ( i = 0; i < typed_array.length; i++ ) {722 if ( typed_array[i] )723 recognised = true;724 if ( !recognised )725 continue;726 number = typed_array[i];727 tmp_collection = [];728 while ( number ) {729 tmp_collection.unshift(number & 255);730 number = number >> 8;731 }732 result += String.fromCharCode.apply(null, tmp_collection);733 }734 735 return result;736 }737 738 /* */739 740 741 742 /**743 * Constructor744 */745 while ( bytes_per_entry && byte_length % bytes_per_entry )746 byte_length++;747 748 var buffer = new ArrayBuffer(byte_length);749 750 if ( !bytes_per_entry || (bytes_per_entry != 1 && bytes_per_entry != 2) ) {751 if ( buffer.byteLength >= 2 && !(buffer.byteLength & 1) )752 bytes_per_entry = 2;753 else754 bytes_per_entry = 1;755 }756 757 if ( bytes_per_entry == 2 )758 typed_array = new Uint16Array(buffer);759 else760 typed_array = new Uint8Array(buffer);761 bytes_per_entry = typed_array.BYTES_PER_ELEMENT;762 763 if ( src_typed_array ) {764 var offset = typed_array.length - src_typed_array.length;765 typed_array.set(src_typed_array, offset);766 }767 768 var bits = bytes_per_entry * 8;769 var MAX_VALUE = 255;770 for ( var i = 1; i < bytes_per_entry; i++ ) {771 MAX_VALUE <<= 8;772 MAX_VALUE += 255;773 }774 var ONE_ENTRY = 1 << bits;...

Full Screen

Full Screen

fast-api-sequences.js

Source:fast-api-sequences.js Github

copy

Full Screen

...106})();107// ----------- Test different TypedArray functions. -----------108// ----------- add_all_<TYPE>_typed_array -----------109// `add_all_<TYPE>_typed_array` have the following signature:110// double add_all_<TYPE>_typed_array(bool /*should_fallback*/, FastApiTypedArray<TYPE>)111(function () {112 function int32_test() {113 let typed_array = new Int32Array([-42, 1, 2, 3]);114 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,115 typed_array);116 }117 ExpectFastCall(int32_test, -36);118})();119(function () {120 function uint32_test() {121 let typed_array = new Uint32Array([1, 2, 3]);122 return fast_c_api.add_all_uint32_typed_array(false /* should_fallback */,123 typed_array);124 }125 ExpectFastCall(uint32_test, 6);126})();127(function () {128 function float32_test() {129 let typed_array = new Float32Array([1.3, 2.4, 3.5]);130 return fast_c_api.add_all_float32_typed_array(false /* should_fallback */,131 typed_array);132 }133 if (fast_c_api.supports_fp_params) {134 ExpectFastCall(float32_test, 7.2);135 } else {136 ExpectSlowCall(float32_test, 7.2);137 }138})();139(function () {140 function float64_test() {141 let typed_array = new Float64Array([1.3, 2.4, 3.5]);142 return fast_c_api.add_all_float64_typed_array(false /* should_fallback */,143 typed_array);144 }145 if (fast_c_api.supports_fp_params) {146 ExpectFastCall(float64_test, 7.2);147 } else {148 ExpectSlowCall(float64_test, 7.2);149 }150})();151// ----------- TypedArray tests in various conditions -----------152// Detached backing store.153(function () {154 function detached_typed_array_test() {155 let typed_array = new Int32Array([-42, 1, 2, 3]);156 %ArrayBufferDetach(typed_array.buffer);157 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,158 typed_array);159 }160 ExpectSlowCall(detached_typed_array_test, 0);161})();162// Detached, non-externalised backing store.163(function () {164 function detached_non_ext_typed_array_test() {165 let typed_array = new Int32Array(large_array);166 %ArrayBufferDetach(typed_array.buffer);167 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,168 typed_array);169 }170 ExpectSlowCall(detached_non_ext_typed_array_test, 0);171})();172// Detaching the backing store after the function is optimised.173(function() {174 let typed_array = new Int32Array([-42, 1, 2, 3]);175 let expected = -36;176 function detached_later_typed_array_test() {177 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,178 typed_array);179 }180 %PrepareFunctionForOptimization(detached_later_typed_array_test);181 let result = detached_later_typed_array_test();182 assertEquals(expected, result);183 fast_c_api.reset_counts();184 %OptimizeFunctionOnNextCall(detached_later_typed_array_test);185 result = detached_later_typed_array_test();186 assertEquals(expected, result);187 assertOptimized(detached_later_typed_array_test);188 assertEquals(1, fast_c_api.fast_call_count());189 assertEquals(0, fast_c_api.slow_call_count());190 fast_c_api.reset_counts();191 // Detaching the backing store after the function was optimised should192 // not lead to a deopt, but rather follow the slow path.193 %ArrayBufferDetach(typed_array.buffer);194 result = detached_later_typed_array_test();195 assertOptimized(detached_later_typed_array_test);196 assertEquals(0, fast_c_api.fast_call_count());197 assertEquals(1, fast_c_api.slow_call_count());198 assertEquals(0, result);199})();200// Externalised backing store.201(function () {202 function shared_array_buffer_ta_test() {203 let sab = new SharedArrayBuffer(16);204 let typed_array = new Int32Array(sab);205 typed_array.set([-42, 1, 2, 3]);206 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,207 typed_array);208 }209 ExpectSlowCall(shared_array_buffer_ta_test, -36);210})();211// Externalised backing store.212(function () {213 function shared_array_buffer_ext_ta_test() {214 let sab = new SharedArrayBuffer(400);215 let typed_array = new Int32Array(sab);216 typed_array.set(large_array);217 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,218 typed_array);219 }220 ExpectSlowCall(shared_array_buffer_ext_ta_test, 4950);221})();222// Empty TypedArray.223(function () {224 function int32_test() {225 let typed_array = new Int32Array(0);226 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,227 typed_array);228 }229 ExpectFastCall(int32_test, 0);230})();231// Invalid argument types instead of a TypedArray.232(function () {233 function invalid_test(arg) {234 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,235 arg);236 }237 %PrepareFunctionForOptimization(invalid_test);238 invalid_test(new Int32Array(0));239 %OptimizeFunctionOnNextCall(invalid_test);240 assert_throws_and_optimized(invalid_test, 42);241 assert_throws_and_optimized(invalid_test, {});242 assert_throws_and_optimized(invalid_test, 'string');243 assert_throws_and_optimized(invalid_test, Symbol());244})();245// Passing `null` instead of a TypedArray in a non-overloaded function.246(function () {247 function null_test(arg) {248 return fast_c_api.add_all_int32_typed_array(false /* should_fallback */,249 arg);250 }251 %PrepareFunctionForOptimization(null_test);252 null_test(new Int32Array(0));253 %OptimizeFunctionOnNextCall(null_test);254 assert_throws_and_optimized(null_test, null);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var x = new Uint8Array([1, 2, 3]);2var y = new Uint8Array([1, 2, 3]);3var z = new Uint8Array([1, 2, 3]);4var w = new Uint8Array([1, 2, 3]);5var a = new Uint8Array([1, 2, 3]);6var b = new Uint8Array([1, 2, 3]);7var c = new Uint8Array([1, 2, 3]);8var d = new Uint8Array([1, 2, 3]);9var e = new Uint8Array([1, 2, 3]);10var f = new Uint8Array([1, 2, 3]);11var g = new Uint8Array([1, 2, 3]);12var h = new Uint8Array([1, 2, 3]);13var i = new Uint8Array([1, 2, 3]);14var j = new Uint8Array([1, 2, 3]);15var k = new Uint8Array([1, 2, 3]);16var l = new Uint8Array([1, 2, 3]);17var m = new Uint8Array([1, 2, 3]);18var n = new Uint8Array([1, 2, 3]);19var o = new Uint8Array([1, 2, 3]);20var p = new Uint8Array([1, 2, 3]);21var q = new Uint8Array([1, 2, 3]);22var r = new Uint8Array([1, 2, 3]);23var s = new Uint8Array([1, 2, 3]);24var t = new Uint8Array([1, 2, 3]);25var u = new Uint8Array([1, 2, 3]);26var v = new Uint8Array([1, 2, 3]);27var w = new Uint8Array([1, 2, 3]);28var x = new Uint8Array([1, 2, 3]);29var y = new Uint8Array([1, 2, 3]);30var z = new Uint8Array([1, 2, 3]);31var a = new Uint8Array([1, 2, 3]);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpage');2var page = wpt.create();3 console.log("Status: " + status);4 if(status === "success") {5 page.render('google.png');6 }7 phantom.exit();8});9var wpt = require('webpage');10var page = wpt.create();11 console.log("Status: " + status);12 if(status === "success") {13 page.render('google.png');14 }15 phantom.exit();16});17var wpt = require('webpage');18var page = wpt.create();19 console.log("Status: " + status);20 if(status === "success") {21 page.render('google.png');22 }23 phantom.exit();24});25var wpt = require('webpage');26var page = wpt.create();27 console.log("Status: " + status);28 if(status === "success") {29 page.render('google.png');30 }31 phantom.exit();32});33var wpt = require('webpage');34var page = wpt.create();35 console.log("Status: " + status);36 if(status === "success") {37 page.render('google.png');38 }39 phantom.exit();40});41var wpt = require('webpage');42var page = wpt.create();43 console.log("Status: " + status);44 if(status === "success") {45 page.render('google.png');46 }47 phantom.exit();48});49var wpt = require('webpage');50var page = wpt.create();

Full Screen

Using AI Code Generation

copy

Full Screen

1var typed_array = require('typed_array');2var assert = require('assert');3var t = new typed_array.Uint8Array(10);4assert.equal(t.length, 10);5assert.equal(t.byteLength, 10);6assert.equal(t.byteOffset, 0);7assert.equal(t[0], 0);8assert.equal(t[9], 0);9t[0] = 1;10t[9] = 1;11assert.equal(t[0], 1);12assert.equal(t[9], 1);13t[0] = 256;14t[9] = 256;15assert.equal(t[0], 0);16assert.equal(t[9], 0);17t[0] = -1;18t[9] = -1;19assert.equal(t[0], 255);20assert.equal(t[9], 255);21t[0] = 1.1;22t[9] = 1.1;23assert.equal(t[0], 1);24assert.equal(t[9], 1);25t[0] = "1";26t[9] = "1";27assert.equal(t[0], 1);28assert.equal(t[9], 1);29t[0] = "1.1";30t[9] = "1.1";31assert.equal(t[0], 1);32assert.equal(t[9], 1);33t[0] = "1.9";34t[9] = "1.9";35assert.equal(t[0], 1);36assert.equal(t[9], 1);37t[0] = "a";38t[9] = "a";39assert.equal(t[0], 0);40assert.equal(t[9], 0);41t[0] = true;42t[9] = true;43assert.equal(t[0], 1);44assert.equal(t[9], 1);45t[0] = false;46t[9] = false;47assert.equal(t[0], 0);48assert.equal(t[9], 0);49t[0] = undefined;50t[9] = undefined;51assert.equal(t[0], 0);52assert.equal(t[9], 0);53t[0] = null;54t[9] = null;55assert.equal(t[0], 0);56assert.equal(t[9], 0);57t[0] = {};58t[9] = {};

Full Screen

Using AI Code Generation

copy

Full Screen

1var typed_array = new Uint8Array(1000);2typed_array[0] = 1;3typed_array[1] = 2;4typed_array[999] = 1000;5var typed_array2 = new Uint8Array(1000);6typed_array2[0] = 1;7typed_array2[1] = 2;8typed_array2[999] = 1000;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var fs = require('fs');3var path = require('path');4var util = require('util');5var test = require('tape');6var data = fs.readFileSync(path.join(__dirname, 'test.png'));7var data64 = new Buffer(data).toString('base64');8var options = {9 script: 'document.getElementById("test").innerHTML = "Hello World";'10};11test('wpt-api', function (t) {12 t.plan(1);13 t.error(err, 'no error');14 console.log(data);15 });16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var typed_array = new Uint8Array(3);2var data_view = new DataView(typed_array.buffer);3var buffer = typed_array.buffer;4var blob = new Blob([buffer]);5var file = new File([blob], "test.js");6var worker = new Worker("worker.js");7worker.postMessage(typed_array);8worker.postMessage(data_view);9worker.postMessage(buffer);10worker.postMessage(blob);11worker.postMessage(file);12onmessage = function (e) {13 var typed_array = new Uint8Array(e.data);14 var data_view = new DataView(e.data);15 var buffer = e.data;16 var blob = new Blob([buffer]);17 var file = new File([blob], "test.js");18 postMessage([typed_array, data_view, buffer, blob, file]);19};20var typed_array = new Uint8Array(3);21var data_view = new DataView(typed_array.buffer);22var buffer = typed_array.buffer;23var blob = new Blob([buffer]);24var file = new File([blob], "test.js");25var worker = new Worker("worker.js");26worker.postMessage(typed_array, [typed_array.buffer]);27worker.postMessage(data

Full Screen

Using AI Code Generation

copy

Full Screen

1var str = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';2var str2 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';3var str3 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';4var str4 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';5var str5 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';6var str6 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';7var str7 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';8var str8 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';9var str9 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';10var str10 = 'Hi, my name is "Bob" and I\'m a JavaScript developer.';11var start = Date.now();12for (var i = 0; i < 100000; i++) {13 wptexturize(str);14}15var end = Date.now();16console.log('wptexturize took', end - start, 'ms');17var start = Date.now();18for (var i = 0; i < 100000; i++) {19 wptexturize(str2);20}21var end = Date.now();22console.log('wptexturize took', end - start, 'ms');23var start = Date.now();24for (var i = 0; i < 100000; i++) {25 wptexturize(str3);26}27var end = Date.now();28console.log('wptexturize took', end - start, 'ms');29var start = Date.now();30for (var i = 0; i < 100000; i++) {31 wptexturize(str4);32}33var end = Date.now();34console.log('wptexturize took', end - start, 'ms');35var start = Date.now();36for (var i = 0; i < 100000; i++) {37 wptexturize(str5);38}39var end = Date.now();40console.log('wptexturize took', end - start, 'ms');41var start = Date.now();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful