Best JavaScript code snippet using wpt
grow.any.js
Source:grow.any.js
1// META: global=window,dedicatedworker,jsshell2// META: script=/wasm/jsapi/memory/assertions.js3test(() => {4 const argument = { "initial": 0 };5 const memory = new WebAssembly.Memory(argument);6 assert_throws_js(TypeError, () => memory.grow());7}, "Missing arguments");8test(t => {9 const thisValues = [10 undefined,11 null,12 true,13 "",14 Symbol(),15 1,16 {},17 WebAssembly.Memory,18 WebAssembly.Memory.prototype,19 ];20 const argument = {21 valueOf: t.unreached_func("Should not touch the argument (valueOf)"),22 toString: t.unreached_func("Should not touch the argument (toString)"),23 };24 const fn = WebAssembly.Memory.prototype.grow;25 for (const thisValue of thisValues) {26 assert_throws_js(TypeError, () => fn.call(thisValue, argument), `this=${format_value(thisValue)}`);27 }28}, "Branding");29test(() => {30 const argument = { "initial": 0 };31 const memory = new WebAssembly.Memory(argument);32 const oldMemory = memory.buffer;33 assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");34 const result = memory.grow(2);35 assert_equals(result, 0);36 const newMemory = memory.buffer;37 assert_not_equals(oldMemory, newMemory);38 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");39 assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");40}, "Zero initial");41test(() => {42 const argument = { "initial": { valueOf() { return 0 } } };43 const memory = new WebAssembly.Memory(argument);44 const oldMemory = memory.buffer;45 assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");46 const result = memory.grow({ valueOf() { return 2 } });47 assert_equals(result, 0);48 const newMemory = memory.buffer;49 assert_not_equals(oldMemory, newMemory);50 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");51 assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");52}, "Zero initial with valueOf");53test(() => {54 const argument = { "initial": 3 };55 const memory = new WebAssembly.Memory(argument);56 const oldMemory = memory.buffer;57 assert_ArrayBuffer(oldMemory, { "size": 3 }, "Buffer before growing");58 const result = memory.grow(2);59 assert_equals(result, 3);60 const newMemory = memory.buffer;61 assert_not_equals(oldMemory, newMemory);62 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");63 assert_ArrayBuffer(newMemory, { "size": 5 }, "New buffer after growing");64}, "Non-zero initial");65test(() => {66 const argument = { "initial": 0, "maximum": 2 };67 const memory = new WebAssembly.Memory(argument);68 const oldMemory = memory.buffer;69 assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");70 const result = memory.grow(2);71 assert_equals(result, 0);72 const newMemory = memory.buffer;73 assert_not_equals(oldMemory, newMemory);74 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");75 assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");76}, "Zero initial with respected maximum");77test(() => {78 const argument = { "initial": 0, "maximum": 2 };79 const memory = new WebAssembly.Memory(argument);80 const oldMemory = memory.buffer;81 assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");82 const result = memory.grow(1);83 assert_equals(result, 0);84 const newMemory = memory.buffer;85 assert_not_equals(oldMemory, newMemory);86 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing once");87 assert_ArrayBuffer(newMemory, { "size": 1 }, "New buffer after growing once");88 const result2 = memory.grow(1);89 assert_equals(result2, 1);90 const newestMemory = memory.buffer;91 assert_not_equals(newMemory, newestMemory);92 assert_ArrayBuffer(oldMemory, { "detached": true }, "New buffer after growing twice");93 assert_ArrayBuffer(newMemory, { "detached": true }, "New buffer after growing twice");94 assert_ArrayBuffer(newestMemory, { "size": 2 }, "Newest buffer after growing twice");95}, "Zero initial with respected maximum grown twice");96test(() => {97 const argument = { "initial": 1, "maximum": 2 };98 const memory = new WebAssembly.Memory(argument);99 const oldMemory = memory.buffer;100 assert_ArrayBuffer(oldMemory, { "size": 1 }, "Buffer before growing");101 assert_throws_js(RangeError, () => memory.grow(2));102 assert_equals(memory.buffer, oldMemory);103 assert_ArrayBuffer(memory.buffer, { "size": 1 }, "Buffer before trying to grow");104}, "Zero initial growing too much");105const outOfRangeValues = [106 undefined,107 NaN,108 Infinity,109 -Infinity,110 -1,111 0x100000000,112 0x1000000000,113 "0x100000000",114 { valueOf() { return 0x100000000; } },115];116for (const value of outOfRangeValues) {117 test(() => {118 const argument = { "initial": 0 };119 const memory = new WebAssembly.Memory(argument);120 assert_throws_js(TypeError, () => memory.grow(value));121 }, `Out-of-range argument: ${format_value(value)}`);122}123test(() => {124 const argument = { "initial": 0 };125 const memory = new WebAssembly.Memory(argument);126 const oldMemory = memory.buffer;127 assert_ArrayBuffer(oldMemory, { "size": 0 }, "Buffer before growing");128 const result = memory.grow(2, {});129 assert_equals(result, 0);130 const newMemory = memory.buffer;131 assert_not_equals(oldMemory, newMemory);132 assert_ArrayBuffer(oldMemory, { "detached": true }, "Old buffer after growing");133 assert_ArrayBuffer(newMemory, { "size": 2 }, "New buffer after growing");134}, "Stray argument");135test(() => {136 const argument = { "initial": 1, "maximum": 2, "shared": true };137 const memory = new WebAssembly.Memory(argument);138 const oldMemory = memory.buffer;139 assert_ArrayBuffer(oldMemory, { "size": 1, "shared": true }, "Buffer before growing");140 const result = memory.grow(1);141 assert_equals(result, 1);142 const newMemory = memory.buffer;143 assert_not_equals(oldMemory, newMemory);144 assert_ArrayBuffer(oldMemory, { "size": 1, "shared": true }, "Old buffer after growing");145 assert_ArrayBuffer(newMemory, { "size": 2, "shared": true }, "New buffer after growing");146 // The old and new buffers must have the same value for the147 // [[ArrayBufferData]] internal slot.148 const oldArray = new Uint8Array(oldMemory);149 const newArray = new Uint8Array(newMemory);150 assert_equals(oldArray[0], 0, "old first element");151 assert_equals(newArray[0], 0, "new first element");152 oldArray[0] = 1;153 assert_equals(oldArray[0], 1, "old first element");154 assert_equals(newArray[0], 1, "new first element");...
index.js
Source:index.js
1/*2Licensed to the Apache Software Foundation (ASF) under one or more3contributor license agreements. See the NOTICE file distributed with4this work for additional information regarding copyright ownership.5The ASF licenses this file to You under the Apache License, Version 2.06(the "License"); you may not use this file except in compliance with7the License. You may obtain a copy of the License at8http://www.apache.org/licenses/LICENSE-2.09Unless required by applicable law or agreed to in writing, software10distributed under the License is distributed on an "AS IS" BASIS,11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12See the License for the specific language governing permissions and13limitations under the License.14*/15solrAdminApp.controller('IndexController', function($scope, System, Cores, Constants) {16 $scope.resetMenu("index", Constants.IS_ROOT_PAGE);17 $scope.reload = function() {18 System.get(function(data) {19 $scope.system = data;20 // load average21 var load_average = ( data.system.uptime || '' ).match( /load averages?: (\d+[.,]\d\d),? (\d+[.,]\d\d),? (\d+[.,]\d\d)/ );22 if (load_average) {23 for (var i=0;i<2;i++) {24 load_average[i]=load_average[i].replace(",","."); // for European users25 }26 $scope.load_average = load_average.slice(1);27 }28 // physical memory29 var memoryMax = parse_memory_value(data.system.totalPhysicalMemorySize);30 $scope.memoryTotal = parse_memory_value(data.system.totalPhysicalMemorySize - data.system.freePhysicalMemorySize);31 $scope.memoryPercentage = ($scope.memoryTotal / memoryMax * 100).toFixed(1)+ "%";32 $scope.memoryMax = pretty_print_bytes(memoryMax);33 $scope.memoryTotalDisplay = pretty_print_bytes($scope.memoryTotal);34 // swap space35 var swapMax = parse_memory_value(data.system.totalSwapSpaceSize);36 $scope.swapTotal = parse_memory_value(data.system.totalSwapSpaceSize - data.system.freeSwapSpaceSize);37 $scope.swapPercentage = ($scope.swapTotal / swapMax * 100).toFixed(1)+ "%";38 $scope.swapMax = pretty_print_bytes(swapMax);39 $scope.swapTotalDisplay = pretty_print_bytes($scope.swapTotal);40 // file handles41 $scope.fileDescriptorPercentage = (data.system.openFileDescriptorCount / data.system.maxFileDescriptorCount *100).toFixed(1) + "%";42 // java memory43 var javaMemoryMax = parse_memory_value(data.jvm.memory.raw.max || data.jvm.memory.max);44 $scope.javaMemoryTotal = parse_memory_value(data.jvm.memory.raw.total || data.jvm.memory.total);45 $scope.javaMemoryUsed = parse_memory_value(data.jvm.memory.raw.used || data.jvm.memory.used);46 $scope.javaMemoryTotalPercentage = ($scope.javaMemoryTotal / javaMemoryMax *100).toFixed(1) + "%";47 $scope.javaMemoryUsedPercentage = ($scope.javaMemoryUsed / $scope.javaMemoryTotal *100).toFixed(1) + "%";48 $scope.javaMemoryPercentage = ($scope.javaMemoryUsed / javaMemoryMax * 100).toFixed(1) + "%";49 $scope.javaMemoryTotalDisplay = pretty_print_bytes($scope.javaMemoryTotal);50 $scope.javaMemoryUsedDisplay = pretty_print_bytes($scope.javaMemoryUsed); // @todo These should really be an AngularJS Filter: {{ javaMemoryUsed | bytes }}51 $scope.javaMemoryMax = pretty_print_bytes(javaMemoryMax);52 // no info bar:53 $scope.noInfo = !(54 data.system.totalPhysicalMemorySize && data.system.freePhysicalMemorySize &&55 data.system.totalSwapSpaceSize && data.system.freeSwapSpaceSize &&56 data.system.openFileDescriptorCount && data.system.maxFileDescriptorCount);57 // command line args:58 $scope.commandLineArgs = data.jvm.jmx.commandLineArgs.sort();59 });60 };61 $scope.reload();62});63var parse_memory_value = function( value ) {64 if( value !== Number( value ) )65 {66 var units = 'BKMGTPEZY';67 var match = value.match( /^(\d+([,\.]\d+)?) (\w).*$/ );68 var value = parseFloat( match[1] ) * Math.pow( 1024, units.indexOf( match[3].toUpperCase() ) );69 }70 return value;71};72var pretty_print_bytes = function(byte_value) {73 var unit = null;74 byte_value /= 1024;75 byte_value /= 1024;76 unit = 'MB';77 if( 1024 <= byte_value ) {78 byte_value /= 1024;79 unit = 'GB';80 }81 return byte_value.toFixed( 2 ) + ' ' + unit;...
Using AI Code Generation
1var wpt = require('webpagetest');2var fs = require('fs');3var util = require('util');4var wpt = new WebPageTest('www.webpagetest.org');5var options = {6};7 if (err) return console.error(err);8 console.log('Test Status: ' + data.statusText);9 console.log('Test ID: ' + data.data.testId);10 console.log('Test URL: ' + data.data.summary);11 var testID = data.data.testId;12 wpt.getTestResults(testID, function(err, data) {13 if (err) return console.error(err);14 console.log('Test Status: ' + data.statusText);15 console.log('Test ID: ' + data.data.testId);16 console.log('Test URL: ' + data.data.summary);17 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));18 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));19 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));20 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));21 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));22 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));23 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));24 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));25 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));26 console.log('Test Results: ' + util.inspect(data.data.runs[1].firstView));27 });
Using AI Code Generation
1var wpty = require('wpty').file();2var pty = require('pty.js');3var fs = require('fs');4var express = require('express');5var app = express();6var server = require('http').createServer(app);7var io = require('socket.io')(server);8var term;9var shell = process.env[process.platform == 'win32' ? 'COMSPEC' : 'SHELL'];10var shellFlag = process.platform == 'win32' ? '/d /s /c' : '-i';11var cols = parseInt(process.argv[2] || process.env.COLUMNS || 80);12var rows = parseInt(process.argv[3] || process.env.ROWS || 24);13var sessid = process.argv[4] || process.env.SESSID;14var log = fs.createWriteStream('log.txt', {flags: 'a'});15var term = pty.spawn(shell, [shellFlag], {16});17wpty.attach(term, sessid);18term.on('data', function(data) {19 log.write(data);20});21io.on('connection', function(socket) {22 term.on('data', function(data) {23 socket.emit('data', data);24 });25 socket.on('data', function(data) {26 term.write(data);27 });28});29server.listen(3000);
Using AI Code Generation
1const fs = require('fs');2const wpt = require('webpagetest');3const wptConfig = require('./wpt-config');4const wptTest = new wpt(wptConfig);5const script = fs.readFileSync('./wpt-script.js', 'utf8');6const options = {7};8wptTest.runTest(url, options, (err, data) => {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});
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!!