Best JavaScript code snippet using wpt
grow-memory.js
Source:grow-memory.js
1// Copyright 2016 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --expose-wasm --stress-compaction5load("test/mjsunit/wasm/wasm-constants.js");6load("test/mjsunit/wasm/wasm-module-builder.js");7var kPageSize = 0x10000;8var kV8MaxPages = 16384;9function genGrowMemoryBuilder() {10 var builder = new WasmModuleBuilder();11 builder.addFunction("grow_memory", kSig_i_i)12 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])13 .exportFunc();14 builder.addFunction("load", kSig_i_i)15 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])16 .exportFunc();17 builder.addFunction("store", kSig_i_ii)18 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0,19 kExprGetLocal, 1])20 .exportFunc();21 builder.addFunction("load16", kSig_i_i)22 .addBody([kExprGetLocal, 0, kExprI32LoadMem16U, 0, 0])23 .exportFunc();24 builder.addFunction("store16", kSig_i_ii)25 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem16, 0, 0,26 kExprGetLocal, 1])27 .exportFunc();28 builder.addFunction("load8", kSig_i_i)29 .addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0])30 .exportFunc();31 builder.addFunction("store8", kSig_i_ii)32 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0,33 kExprGetLocal, 1])34 .exportFunc();35 return builder;36}37// TODO(gdeepti): Generate tests programatically for all the sizes instead of38// current implementation.39function testGrowMemoryReadWrite32() {40 var builder = genGrowMemoryBuilder();41 builder.addMemory(1, kV8MaxPages, false);42 var module = builder.instantiate();43 var offset;44 function peek() { return module.exports.load(offset); }45 function poke(value) { return module.exports.store(offset, value); }46 function growMem(pages) { return module.exports.grow_memory(pages); }47 for(offset = 0; offset <= (kPageSize - 4); offset+=4) {48 poke(20);49 assertEquals(20, peek());50 }51 for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) {52 assertTraps(kTrapMemOutOfBounds, poke);53 assertTraps(kTrapMemOutOfBounds, peek);54 }55 assertEquals(1, growMem(3));56 for (offset = kPageSize; offset <= 4*kPageSize -4; offset+=4) {57 poke(20);58 assertEquals(20, peek());59 }60 for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) {61 assertTraps(kTrapMemOutOfBounds, poke);62 assertTraps(kTrapMemOutOfBounds, peek);63 }64 assertEquals(4, growMem(15));65 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset+=4) {66 poke(20);67 assertEquals(20, peek());68 }69 for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset+=4) {70 poke(20);71 assertEquals(20, peek());72 }73 for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) {74 assertTraps(kTrapMemOutOfBounds, poke);75 assertTraps(kTrapMemOutOfBounds, peek);76 }77}78testGrowMemoryReadWrite32();79function testGrowMemoryReadWrite16() {80 var builder = genGrowMemoryBuilder();81 builder.addMemory(1, kV8MaxPages, false);82 var module = builder.instantiate();83 var offset;84 function peek() { return module.exports.load16(offset); }85 function poke(value) { return module.exports.store16(offset, value); }86 function growMem(pages) { return module.exports.grow_memory(pages); }87 for(offset = 0; offset <= (kPageSize - 2); offset+=2) {88 poke(20);89 assertEquals(20, peek());90 }91 for (offset = kPageSize - 1; offset < kPageSize + 4; offset++) {92 assertTraps(kTrapMemOutOfBounds, poke);93 assertTraps(kTrapMemOutOfBounds, peek);94 }95 assertEquals(1, growMem(3));96 for (offset = kPageSize; offset <= 4*kPageSize -2; offset+=2) {97 poke(20);98 assertEquals(20, peek());99 }100 for (offset = 4*kPageSize - 1; offset < 4*kPageSize + 4; offset++) {101 assertTraps(kTrapMemOutOfBounds, poke);102 assertTraps(kTrapMemOutOfBounds, peek);103 }104 assertEquals(4, growMem(15));105 for (offset = 4*kPageSize - 2; offset <= 4*kPageSize + 4; offset+=2) {106 poke(20);107 assertEquals(20, peek());108 }109 for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 2; offset+=2) {110 poke(20);111 assertEquals(20, peek());112 }113 for (offset = 19*kPageSize - 1; offset < 19*kPageSize + 5; offset++) {114 assertTraps(kTrapMemOutOfBounds, poke);115 assertTraps(kTrapMemOutOfBounds, peek);116 }117}118testGrowMemoryReadWrite16();119function testGrowMemoryReadWrite8() {120 var builder = genGrowMemoryBuilder();121 builder.addMemory(1, kV8MaxPages, false);122 var module = builder.instantiate();123 var offset;124 function peek() { return module.exports.load8(offset); }125 function poke(value) { return module.exports.store8(offset, value); }126 function growMem(pages) { return module.exports.grow_memory(pages); }127 for(offset = 0; offset <= kPageSize - 1; offset++) {128 poke(20);129 assertEquals(20, peek());130 }131 for (offset = kPageSize; offset < kPageSize + 4; offset++) {132 assertTraps(kTrapMemOutOfBounds, poke);133 assertTraps(kTrapMemOutOfBounds, peek);134 }135 assertEquals(1, growMem(3));136 for (offset = kPageSize; offset <= 4*kPageSize -1; offset++) {137 poke(20);138 assertEquals(20, peek());139 }140 for (offset = 4*kPageSize; offset < 4*kPageSize + 4; offset++) {141 assertTraps(kTrapMemOutOfBounds, poke);142 assertTraps(kTrapMemOutOfBounds, peek);143 }144 assertEquals(4, growMem(15));145 for (offset = 4*kPageSize; offset <= 4*kPageSize + 4; offset++) {146 poke(20);147 assertEquals(20, peek());148 }149 for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 1; offset++) {150 poke(20);151 assertEquals(20, peek());152 }153 for (offset = 19*kPageSize; offset < 19*kPageSize + 5; offset++) {154 assertTraps(kTrapMemOutOfBounds, poke);155 assertTraps(kTrapMemOutOfBounds, peek);156 }157}158testGrowMemoryReadWrite8();159function testGrowMemoryZeroInitialSize() {160 var builder = genGrowMemoryBuilder();161 builder.addMemory(0, kV8MaxPages, false);162 var module = builder.instantiate();163 var offset;164 function peek() { return module.exports.load(offset); }165 function poke(value) { return module.exports.store(offset, value); }166 function growMem(pages) { return module.exports.grow_memory(pages); }167 assertTraps(kTrapMemOutOfBounds, peek);168 assertTraps(kTrapMemOutOfBounds, poke);169 assertEquals(0, growMem(1));170 for(offset = 0; offset <= kPageSize - 4; offset++) {171 poke(20);172 assertEquals(20, peek());173 }174 for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {175 assertTraps(kTrapMemOutOfBounds, peek);176 }177 offset = 3*kPageSize;178 for (var i = 1; i < 4; i++) {179 assertTraps(kTrapMemOutOfBounds, poke);180 assertEquals(i, growMem(1));181 }182 poke(20);183 assertEquals(20, peek());184}185testGrowMemoryZeroInitialSize();186function testGrowMemoryZeroInitialSize32() {187 var builder = genGrowMemoryBuilder();188 builder.addMemory(0, kV8MaxPages, false);189 var module = builder.instantiate();190 var offset;191 function peek() { return module.exports.load(offset); }192 function poke(value) { return module.exports.store(offset, value); }193 function growMem(pages) { return module.exports.grow_memory(pages); }194 assertTraps(kTrapMemOutOfBounds, peek);195 assertTraps(kTrapMemOutOfBounds, poke);196 assertEquals(0, growMem(1));197 for(offset = 0; offset <= kPageSize - 4; offset++) {198 poke(20);199 assertEquals(20, peek());200 }201 for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {202 assertTraps(kTrapMemOutOfBounds, peek);203 }204}205testGrowMemoryZeroInitialSize32();206function testGrowMemoryZeroInitialSize16() {207 var builder = genGrowMemoryBuilder();208 builder.addMemory(0, kV8MaxPages, false);209 var module = builder.instantiate();210 var offset;211 function peek() { return module.exports.load16(offset); }212 function poke(value) { return module.exports.store16(offset, value); }213 function growMem(pages) { return module.exports.grow_memory(pages); }214 assertTraps(kTrapMemOutOfBounds, peek);215 assertTraps(kTrapMemOutOfBounds, poke);216 assertEquals(0, growMem(1));217 for(offset = 0; offset <= kPageSize - 2; offset++) {218 poke(20);219 assertEquals(20, peek());220 }221 for(offset = kPageSize - 1; offset <= kPageSize + 5; offset++) {222 assertTraps(kTrapMemOutOfBounds, peek);223 }224}225testGrowMemoryZeroInitialSize16();226function testGrowMemoryZeroInitialSize8() {227 var builder = genGrowMemoryBuilder();228 builder.addMemory(0, kV8MaxPages, false);229 var module = builder.instantiate();230 var offset;231 function peek() { return module.exports.load8(offset); }232 function poke(value) { return module.exports.store8(offset, value); }233 function growMem(pages) { return module.exports.grow_memory(pages); }234 assertTraps(kTrapMemOutOfBounds, peek);235 assertTraps(kTrapMemOutOfBounds, poke);236 assertEquals(0, growMem(1));237 for(offset = 0; offset <= kPageSize - 1; offset++) {238 poke(20);239 assertEquals(20, peek());240 }241 for(offset = kPageSize; offset <= kPageSize + 5; offset++) {242 assertTraps(kTrapMemOutOfBounds, peek);243 }244}245testGrowMemoryZeroInitialSize8();246function testGrowMemoryTrapMaxPagesZeroInitialMemory() {247 var builder = genGrowMemoryBuilder();248 builder.addMemory(0, kV8MaxPages, false);249 var module = builder.instantiate();250 var maxPages = 16385;251 function growMem(pages) { return module.exports.grow_memory(pages); }252 assertEquals(-1, growMem(maxPages));253}254testGrowMemoryTrapMaxPagesZeroInitialMemory();255function testGrowMemoryTrapMaxPages() {256 var builder = genGrowMemoryBuilder();257 builder.addMemory(1, 1, false);258 var module = builder.instantiate();259 var maxPages = 16384;260 function growMem(pages) { return module.exports.grow_memory(pages); }261 assertEquals(-1, growMem(maxPages));262}263testGrowMemoryTrapMaxPages();264function testGrowMemoryTrapsWithNonSmiInput() {265 var builder = genGrowMemoryBuilder();266 builder.addMemory(0, kV8MaxPages, false);267 var module = builder.instantiate();268 function growMem(pages) { return module.exports.grow_memory(pages); }269 // The parameter of grow_memory is unsigned. Therefore -1 stands for270 // UINT32_MIN, which cannot be represented as SMI.271 assertEquals(-1, growMem(-1));272};273testGrowMemoryTrapsWithNonSmiInput();274function testGrowMemoryCurrentMemory() {275 var builder = genGrowMemoryBuilder();276 builder.addMemory(1, kV8MaxPages, false);277 builder.addFunction("memory_size", kSig_i_v)278 .addBody([kExprMemorySize, kMemoryZero])279 .exportFunc();280 var module = builder.instantiate();281 function growMem(pages) { return module.exports.grow_memory(pages); }282 function MemSize() { return module.exports.memory_size(); }283 assertEquals(1, MemSize());284 assertEquals(1, growMem(1));285 assertEquals(2, MemSize());286}287testGrowMemoryCurrentMemory();288function testGrowMemoryPreservesDataMemOp32() {289 var builder = genGrowMemoryBuilder();290 builder.addMemory(1, kV8MaxPages, false);291 var module = builder.instantiate();292 var offset, val;293 function peek() { return module.exports.load(offset); }294 function poke(value) { return module.exports.store(offset, value); }295 function growMem(pages) { return module.exports.grow_memory(pages); }296 for(offset = 0; offset <= (kPageSize - 4); offset+=4) {297 poke(100000 - offset);298 assertEquals(100000 - offset, peek());299 }300 assertEquals(1, growMem(3));301 for(offset = 0; offset <= (kPageSize - 4); offset+=4) {302 assertEquals(100000 - offset, peek());303 }304}305testGrowMemoryPreservesDataMemOp32();306function testGrowMemoryPreservesDataMemOp16() {307 var builder = genGrowMemoryBuilder();308 builder.addMemory(1, kV8MaxPages, false);309 var module = builder.instantiate();310 var offset, val;311 function peek() { return module.exports.load16(offset); }312 function poke(value) { return module.exports.store16(offset, value); }313 function growMem(pages) { return module.exports.grow_memory(pages); }314 for(offset = 0; offset <= (kPageSize - 2); offset+=2) {315 poke(65535 - offset);316 assertEquals(65535 - offset, peek());317 }318 assertEquals(1, growMem(3));319 for(offset = 0; offset <= (kPageSize - 2); offset+=2) {320 assertEquals(65535 - offset, peek());321 }322}323testGrowMemoryPreservesDataMemOp16();324function testGrowMemoryPreservesDataMemOp8() {325 var builder = genGrowMemoryBuilder();326 builder.addMemory(1, kV8MaxPages, false);327 var module = builder.instantiate();328 var offset, val = 0;329 function peek() { return module.exports.load8(offset); }330 function poke(value) { return module.exports.store8(offset, value); }331 function growMem(pages) { return module.exports.grow_memory(pages); }332 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) {333 poke(val);334 assertEquals(val, peek());335 if (val == 255) val = 0;336 }337 assertEquals(1, growMem(3));338 val = 0;339 for(offset = 0; offset <= (kPageSize - 1); offset++, val++) {340 assertEquals(val, peek());341 if (val == 255) val = 0;342 }343}344testGrowMemoryPreservesDataMemOp8();345function testGrowMemoryOutOfBoundsOffset() {346 var builder = genGrowMemoryBuilder();347 builder.addMemory(1, kV8MaxPages, false);348 var module = builder.instantiate();349 var offset, val;350 function peek() { return module.exports.load(offset); }351 function poke(value) { return module.exports.store(offset, value); }352 function growMem(pages) { return module.exports.grow_memory(pages); }353 offset = 3*kPageSize + 4;354 assertTraps(kTrapMemOutOfBounds, poke);355 assertEquals(1, growMem(1));356 assertTraps(kTrapMemOutOfBounds, poke);357 assertEquals(2, growMem(1));358 assertTraps(kTrapMemOutOfBounds, poke);359 assertEquals(3, growMem(1));360 for (offset = 3*kPageSize; offset <= 4*kPageSize - 4; offset++) {361 poke(0xaced);362 assertEquals(0xaced, peek());363 }364 for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) {365 assertTraps(kTrapMemOutOfBounds, poke);366 }367}368testGrowMemoryOutOfBoundsOffset();369function testGrowMemoryOutOfBoundsOffset2() {370 var builder = new WasmModuleBuilder();371 builder.addMemory(16, 128, false);372 builder.addFunction("main", kSig_v_v)373 .addBody([374 kExprI32Const, 20,375 kExprI32Const, 29,376 kExprGrowMemory, kMemoryZero,377 kExprI32StoreMem, 0, 0xFF, 0xFF, 0xFF, 0x3a378 ])379 .exportAs("main");380 var module = builder.instantiate();381 assertTraps(kTrapMemOutOfBounds, module.exports.main);382}383testGrowMemoryOutOfBoundsOffset2();384function testGrowMemoryDeclaredMaxTraps() {385 var builder = genGrowMemoryBuilder();386 builder.addMemory(1, 16, false);387 var module = builder.instantiate();388 function growMem(pages) { return module.exports.grow_memory(pages); }389 assertEquals(1, growMem(5));390 assertEquals(6, growMem(5));391 assertEquals(-1, growMem(6));392}393testGrowMemoryDeclaredMaxTraps();394function testGrowMemoryDeclaredSpecMaxTraps() {395 // The spec maximum is higher than the internal V8 maximum. This test only396 // checks that grow_memory does not grow past the internally defined maximum397 // to reflect the currentl implementation.398 var builder = genGrowMemoryBuilder();399 var kSpecMaxPages = 65535;400 builder.addMemory(1, kSpecMaxPages, false);401 var module = builder.instantiate();402 function poke(value) { return module.exports.store(offset, value); }403 function growMem(pages) { return module.exports.grow_memory(pages); }404 assertEquals(1, growMem(20));405 assertEquals(-1, growMem(kV8MaxPages - 20));406}...
member.js
Source:member.js
1const { sequelize, Sequelize : { QueryTypes } } = require("./index");2const bcrypt = require('bcrypt');3const crypto = require('crypto');4/**5* íì models6*7*/8const member = {9 /**10 * íìê°ì
11 *12 */13 async join(data) {14 await this.checkJoinData(data);15 try {16 const sql = `INSERT INTO member (memId, memPw, memNm, cellPhone)17 VALUES (:memId, :memPw, :memNm, :cellPhone)`;18 const hash = data.memPw?await bcrypt.hash(data.memPw, 10):"";19 let cellPhone = "";20 if (data.cellPhone) {21 cellPhone = data.cellPhone.replace(/[^0-9]/g, "");22 }23 const replacements = {24 memId : data.memId,25 memPw : hash,26 memNm : data.memNm,27 cellPhone,28 };29 const result = await sequelize.query(sql, {30 replacements : replacements,31 type : QueryTypes.INSERT,32 });33 const memNo = result[0];34 const memberInfo = await this.get(memNo);35 return memberInfo;36 } catch (err) {37 console.error(err);38 return false;39 }40 },41 /**42 * íìì ë³´ ìì 43 *44 */45 async update(data) {46 /** íì í목 ì²´í¬ S */47 const required = {48 token : "í í°ì´ ëë½ëììµëë¤.",49 memNm : "íìëª
ì ì
ë ¥íì¸ì.",50 };51 for (let key in required) {52 if (!data[key]) {53 throw new Error(required[key]);54 }55 }56 /** íì í목 ì²´í¬ */57 /** ë¹ë°ë²í¸ ë³ê²½ ìëì ë¹ë°ë²í¸ ì²´í¬ */58 this.checkPassword(data.memPw, data.memPwRe);59 /** í´ëì íë²í¸ íì ì²´í¬ */60 this.checkCellPhone(data.cellPhone);61 let cellPhone = "";62 if (data.cellPhone) {63 cellPhone = data.cellPhone.replace(/[^0-9]/g, "");64 }65 const replacements = {66 memNm : data.memNm,67 cellPhone,68 };69 let addSet = "";70 if (data.memPw) {71 const hash = await bcrypt.hash(data.memPw, 10);72 addSet = ",memPw = :hash";73 replacements.hash = hash;74 }75 replacements.token = data.token;76 try {77 const sql = `UPDATE member78 SET79 memNm = :memNm,80 cellPhone = :cellPhone81 ${addSet}82 WHERE83 token = :token`;84 await sequelize.query(sql, {85 replacements,86 type : QueryTypes.UPDATE87 });88 return true;89 } catch (err) {90 console.error(err);91 return false;92 }93 },94 /**95 * ë¡ê·¸ì¸ ì²ë¦¬96 *97 */98 async login(data) {99 /**100 * 1. íì í목(ìì´ë, ë¹ë²) ì²´í¬(O)101 * 2. ìì´ë -> íìì ë³´ ì¡°í(O)102 * 3. íìì´ ìì¼ë©´ ë¹ë°ë²í¸ ì²´í¬ (O)103 * 4. ë¹ë°ë²í¸ ì¼ì¹íë ê²½ì° (O)104 ì ì ì í¨ ìê°ì´ ìë í í° ë°ê¸ ->105 í í°ì íë¡ í¸ ë¸ë¼ì°ì ì ì ì¥(ì¸ì
ì¤í 리ì§)106 í í°ì íë¡ í¸ -> ìë²ë¡ -> í í° ê²ì¦(ì í¨ìê°ì´ ë¨ì ìê³ íì ID ìì¼ë©´)107 -> íì ì 보를 íë¡ í¸ë¡ ì ì¡108 */109 if (!data.memId) {110 throw new Error('ìì´ë를 ì
ë ¥íì¸ì.');111 }112 if (!data.memPw) {113 throw new Error('ë¹ë°ë²í¸ë¥¼ ì
ë ¥íì¸ì.');114 }115 // íìì ë³´ ì¡°í116 const info = await this.get(data.memId, true);117 if (!info) {118 throw new Error("ì¡´ì¬íì§ ìë íìì
ëë¤.");119 }120 // ë¹ë°ë²í¸ ì²´í¬121 const match = await bcrypt.compare(data.memPw, info.memPw);122 if (!match) {123 throw new Error('ë¹ë°ë²í¸ê° ì¼ì¹íì§ ììµëë¤.');124 }125 // í í° -> ë¡ê·¸ì¸í íì ì 보를 ì¡°í, ì í¨ìê°126 const token = await this.generateToken(data.memId);127 return token;128 },129 /**130 * íìê°ì
ì í¨ì± ê²ì¬131 * 1. íì í목 ì²´í¬(memId, memPw, memPwRe, memNm) - O132 * 2. ìì´ë ì²´í¬(ì리ì 6ì리 ì´ì, ìíë²³ + ì«ì) - O133 * 3. ì¤ë³µ ìì´ë ì²´í¬ - O134 * 4. ë¹ë°ë²í¸ ì²´í¬(ì리ì 8ì리 ì´ì, ìíë²³ + ì«ì + í¹ì 문ì) - O135 * 5. ë¹ë°ë²í¸ íì¸ - O136 * 6. í´ëì íë²í¸ë íì X -> ì
ë ¥ë ê²½ì°ë í´ëì íë²í¸ íì ì²´í¬137 */138 async checkJoinData(data) {139 // íì í목 ì²´í¬140 const required = {141 memId : "ìì´ë를 ì
ë ¥íì¸ì.",142 memPw : "ë¹ë°ë²í¸ë¥¼ ì
ë ¥íì¸ì.",143 memPwRe : "ë¹ë°ë²í¸ë¥¼ íì¸íì¸ì.",144 memNm : "íìëª
ì ì
ë ¥íì¸ì.",145 };146 for (let key in required) {147 if (!data[key] || (data[key] && data[key].trim() == "")) {148 throw new Error(required[key]);149 }150 }151 // ìì´ë ì²´í¬ S152 const memId = data.memId;153 if (memId.length < 6) {154 throw new Error("ìì´ëë 6ì리 ì´ì ì
ë ¥íì¸ì.");155 }156 // test (매ì¹ì´ëë©´ true), exec - 매ì¹ì´ ëë©´ 매ì¹ë ìì를 ë°í157 // /[^a-z0-9]/ - ìíë²³, ì«ìê° ìë 문ì - case-insensitive158 if (/[^a-z0-9]/i.test(memId)) {159 throw new Error("ìì´ëë ìí벳과 ì«ìë¡ë§ ì
ë ¥íì¸ì.");160 }161 // ìì´ë ì²´í¬ E162 // ì¤ë³µ ìì´ë ì²´í¬ S163 const sql = "SELECT COUNT(*) cnt FROM member WHERE memId = ?";164 const rows = await sequelize.query(sql, {165 replacements : [memId],166 type : QueryTypes.SELECT,167 });168 if (rows[0].cnt > 0) { // ì´ë¯¸ ê°ì
ë ê²½ì°169 throw new Error('ì´ë¯¸ ê°ì
ë ìì´ë ì
ëë¤. - ' + memId);170 }171 // ì¤ë³µ ìì´ë ì²´í¬ E172 // ë¹ë°ë²í¸ ì²´í¬ S173 this.checkPassword(data.memPw, data.memPwRe);174 // ë¹ë°ë²í¸ ì²´í¬ E175 // í´ëì íë²í¸ íì ì²´í¬ S176 this.checkCellPhone(data.cellPhone);177 // í´ëì íë²í¸ íì ì²´í¬ E178 },179 /** ë¹ë°ë²í¸ ì²´í¬ */180 checkPassword(memPw, memPwRe) {181 if (!memPw)182 return;183 if (memPw.length < 8) {184 throw new Error("ë¹ë°ë²í¸ë 8ì리 ì´ì ì
ë ¥íì¸ì.");185 }186 if (!/[a-z]/i.test(memPw) || !/[0-9]/.test(memPw) || !/[~!@#$%^&*()]/.test(memPw)) {187 throw new Error("ë¹ë°ë²í¸ë 1ê°ì´ìì ìíë²³, ì«ì, í¹ì문ìë¡ ì
ë ¥íì¸ì.");188 }189 // ë¹ë°ë²í¸ íì¸ S190 if (memPw != memPwRe) {191 throw new Error("ë¹ë°ë²í¸ë¥¼ íì¸íì¸ì.");192 }193 // ë¹ë°ë²í¸ íì¸ E194 },195 /** í´ëì íë²í¸ íì ì²´í¬ */196 checkCellPhone(cellPhone) {197 if (!cellPhone) {198 return;199 }200 cellPhone = cellPhone.replace(/[^0-9]/g, "");201 const pattern = /^01[016789][0-9]{3,4}[0-9]{4}$/;202 if (!pattern.test(cellPhone)) {203 throw new Error('í´ëì íë²í¸ íìì´ ìëëë¤.');204 }205 },206 /**207 * íì ì ë³´ ì¡°í208 *209 * @param memNo - ì ì - íìë²í¸, 문ì -> ìì´ë210 */211 async get(memNo, isLogin) {212 try {213 let fields = "memNo";214 if (typeof memNo == 'string') {215 fields = "memId";216 }217 const sql = `SELECT * FROM member WHERE ${fields} = ?`;218 const rows = await sequelize.query(sql, {219 replacements : [memNo],220 type : QueryTypes.SELECT,221 });222 if (rows.length == 0) { // íìì´ ìë ê²½ì°223 return false;224 }225 const data = rows[0];226 if (!isLogin) {227 delete data.memPw;228 }229 return data;230 } catch (err) {231 console.error(err);232 return false;233 }234 },235 /**236 * í í° ë°ê¸237 * - ë¡ê·¸ì¸ ì ì§238 * - ì í¨ ìê°(2ìê°)239 */240 async generateToken(memId) {241 const now = Date.now();242 const hash = crypto.createHash('md5').update("" + now).digest('hex');243 const expireTime = now + 60 * 60 * 2 * 1000;244 const sql = `UPDATE member245 SET246 token = :token,247 tokenExpires = :tokenExpires248 WHERE249 memId = :memId`;250 const replacements = {251 token : hash,252 tokenExpires : new Date(expireTime),253 memId,254 };255 try {256 await sequelize.query(sql, {257 replacements,258 type : QueryTypes.UPDATE,259 });260 return hash;261 } catch (err) {262 console.error(err);263 return false;264 }265 },266 /** í í°ì¼ë¡ íì ì ë³´ ì¡°í */267 async getByToken(token) {268 if (!token) {269 throw new Error('í í°ì´ ëë½ëììµëë¤');270 }271 let rows = [];272 try {273 const sql = 'SELECT * FROM member WHERE token = ?';274 rows = await sequelize.query(sql, {275 replacements : [token],276 type : QueryTypes.SELECT,277 });278 } catch (err) {279 console.log(err);280 return false;281 }282 if (rows.length == 0) {283 throw new Error('ì¡´ì¬íì§ ìë íìì
ëë¤');284 }285 const data = rows[0];286 delete data.memPw;287 const expireTime = new Date(data.tokenExpires).getTime();288 if (expireTime < Date.now()) {289 throw new Error('í í°ì´ ë§ë£ ëììµëë¤.');290 }291 return data;292 }293};...
instance-memory-gc-stress.js
Source:instance-memory-gc-stress.js
1// Copyright 2016 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --expose-wasm --expose-gc5load("test/mjsunit/wasm/wasm-constants.js");6load("test/mjsunit/wasm/wasm-module-builder.js");7// This test verifies that when instances are exported, Gc'ed, the other8// instances in the chain still maintain a consistent view of the memory.9(function InstanceMemoryGcStress() {10 print("InstanceMemoryGcStress");11 let memory = new WebAssembly.Memory({initial: 100, maximum: 1500});12 var builder = new WasmModuleBuilder();13 builder.addImportedMemory("mod", "imported_mem");14 builder.addFunction("mem_size", kSig_i_v)15 .addBody([kExprMemorySize, kMemoryZero])16 .exportFunc();17 builder.addFunction("grow", kSig_i_i)18 .addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])19 .exportFunc();20 var instances = [];21 for (var i = 0; i < 5; i++) {22 gc();23 instances.push(builder.instantiate({mod: {imported_mem: memory}}));24 }25 function grow_instance_0(pages) { return instances[0].exports.grow(pages); }26 function grow_instance_1(pages) { return instances[1].exports.grow(pages); }27 function grow_instance_2(pages) { return instances[2].exports.grow(pages); }28 function grow_instance_3(pages) { return instances[3].exports.grow(pages); }29 function grow_instance_4(pages) { return instances[4].exports.grow(pages); }30 var start_index = 0;31 var end_index = 5;32 function verify_mem_size(expected_pages) {33 assertEquals(expected_pages*kPageSize, memory.buffer.byteLength);34 for (var i = start_index; i < end_index; i++) {35 assertEquals(expected_pages, instances[i].exports.mem_size());36 }37 }38 // Verify initial memory size of all instances, grow and verify that all39 // instances are updated correctly.40 verify_mem_size(100);41 assertEquals(100, memory.grow(500));42 verify_mem_size(600);43 instances[1] = null;44 gc();45 gc();46 // i[0] - i[2] - i[3] - i[4]47 start_index = 2;48 verify_mem_size(600);49 assertEquals(600, instances[0].exports.mem_size());50 assertEquals(600, grow_instance_2(200));51 assertEquals(800*kPageSize, memory.buffer.byteLength);52 verify_mem_size(800);53 assertEquals(800, instances[0].exports.mem_size());54 // Instantiate a new instance and verify that it can be grown correctly.55 instances.push(builder.instantiate({mod: {imported_mem: memory}}));56 function grow_instance_5(pages) { return instances[5].exports.grow(pages); }57 gc();58 gc();59 // i[0] - i[2] - i[3] - i[4] - i[5]60 start_index = 2;61 end_index = 6;62 verify_mem_size(800);63 assertEquals(800, instances[0].exports.mem_size());64 assertEquals(800, grow_instance_2(100));65 assertEquals(900*kPageSize, memory.buffer.byteLength);66 verify_mem_size(900);67 assertEquals(900, instances[0].exports.mem_size());68 instances[4] = null;69 gc();70 gc();71 // i[0] - i[2] - i[3] - i[5]72 assertEquals(900, instances[0].exports.mem_size());73 assertEquals(900, instances[2].exports.mem_size());74 assertEquals(900, instances[3].exports.mem_size());75 assertEquals(900, instances[5].exports.mem_size());76 assertEquals(900, memory.grow(100));77 assertEquals(1000*kPageSize, memory.buffer.byteLength);78 assertEquals(1000, instances[0].exports.mem_size());79 assertEquals(1000, instances[2].exports.mem_size());80 assertEquals(1000, instances[3].exports.mem_size());81 assertEquals(1000, instances[5].exports.mem_size());82 gc();83 gc();84 instances[3] = null;85 // i[0] - i[2] - i[5]86 assertEquals(1000, instances[0].exports.mem_size());87 assertEquals(1000, instances[2].exports.mem_size());88 assertEquals(1000, instances[5].exports.mem_size());89 assertEquals(1000, memory.grow(100));90 assertEquals(1100*kPageSize, memory.buffer.byteLength);91 assertEquals(1100, instances[0].exports.mem_size());92 assertEquals(1100, instances[2].exports.mem_size());93 assertEquals(1100, instances[5].exports.mem_size());94 instances[0] = null;95 gc();96 gc();97 // i[2] - i[5]98 assertEquals(1100, instances[2].exports.mem_size());99 assertEquals(1100, instances[5].exports.mem_size());100 assertEquals(1100, grow_instance_5(1));101 gc();102 gc();103 assertEquals(1101*kPageSize, memory.buffer.byteLength);104 assertEquals(1101, instances[2].exports.mem_size());105 assertEquals(1101, instances[5].exports.mem_size());...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('wpt');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.getLocations(function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('wpt');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getLocations(function(err, data) {34 if (err) return console.error(err);35 console.log(data);36});37var wpt = require('wpt');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getLocations(function(err, data) {40 if (err) return console.error(err);41 console.log(data);42});43var wpt = require('wpt');44var wpt = new WebPageTest('www.webpagetest.org');45wpt.getLocations(function(err, data) {46 if (err) return console.error(err);47 console.log(data);48});49var wpt = require('wpt');
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org', 'A.6f1a8b8e6b1e2c9a3e3c8d7d6f5a6b7', {pretty: true});2 if (err) return console.error(err);3 console.log(data.data.median.firstView.SpeedIndex);4 console.log(data.data.median.firstView.TTFB);5 console.log(data.data.median.firstView.render);6 console.log(data.data.median.firstView.fullyLoaded);7 console.log(data.data.median.firstView.loadTime);8 console.log(data.data.median.firstView.docTime);9 console.log(data.data.median.firstView.bytesIn);10 console.log(data.data.median.firstView.bytesOut);11 console.log(data.data.median.firstView.bytesInDoc);12 console.log(data.data.median.firstView.requests);13 console.log(data.data.median.firstView.requestsDoc);14 console.log(data.data.median.firstView.responses_200);15 console.log(data.data.median.firstView.responses_404);16 console.log(data.data.median.firstView.responses_other);17 console.log(data.data.median.firstView.result);18 console.log(data.data.median.firstView.render);19 console.log(data.data.median.firstView.fullyLoaded);20 console.log(data.data.median.firstView.loadTime);21 console.log(data.data.median.firstView.docTime);22 console.log(data.data.median.firstView.bytesIn);23 console.log(data.data.median.firstView.bytesOut);24 console.log(data.data.median.firstView.bytesInDoc);25 console.log(data.data.median.firstView.requests);26 console.log(data.data.median.firstView.requestsDoc);27 console.log(data.data.median.firstView.responses_200);28 console.log(data.data.median.firstView.responses_404);29 console.log(data.data.median.firstView.responses_other);30 console.log(data.data.median.firstView.result);31 console.log(data.data.median.firstView.render);32 console.log(data.data.median.firstView.fullyLoaded
Using AI Code Generation
1var wptools = require('wptools')2var fs = require('fs')3var output = fs.createWriteStream('output.txt');4var errput = fs.createWriteStream('error.txt');5var mem = wptools.mem;6mem.set('output', output);7mem.set('error', errput);8var page = wptools.page('Barack Obama');9page.get(function(err,resp){10 console.log(resp);11});12var wptools = require('wptools')13var fs = require('fs')14var output = fs.createWriteStream('output.txt');15var errput = fs.createWriteStream('error.txt');16var mem = wptools.mem;17mem.set('output', output);18mem.set('error', errput);19var page = wptools.page('Barack Obama');20page.get(function(err,resp){21 console.log(resp);22});23var wptools = require('wptools')24var fs = require('fs')25var output = fs.createWriteStream('output.txt');26var errput = fs.createWriteStream('error.txt');27var mem = wptools.mem;28mem.set('output', output);29mem.set('error', errput);30var page = wptools.page('Barack Obama');31page.get(function(err,resp){32 console.log(resp);33});34var wptools = require('wptools')35var fs = require('fs')36var output = fs.createWriteStream('output.txt');37var errput = fs.createWriteStream('error.txt');38var mem = wptools.mem;39mem.set('output', output);40mem.set('error', errput);41var page = wptools.page('Barack Obama');42page.get(function(err,resp){43 console.log(resp);44});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('wikipedia', 'en.wikipedia.org', 'Albert Einstein');3wiki.get(function(err, data) {4 console.log(data);5});6{7 "dependencies": {8 }9}
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.2d6b8f6f1f6c2e6f3d6d1e6b1e6b8f6f');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status:', data.statusText);6 if (data.statusCode > 200) return;7 test.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 console.log('Test completed in %d seconds', data.data.average.firstView.loadTime);10 console.log('View the test at %s', data.data.summary);11 });12});13var wpt = require('webpagetest');14var test = new wpt('www.webpagetest.org', 'A.2d6b8f6f1f6c2e6f3d6d1e6b1e6b8f6f');15}, function(err, data) {16 if (err) return console.error(err);17 console.log('Test status:', data.statusText);18 if (data.statusCode > 200) return;19 test.getTestResults(data.data.testId, function(err, data) {20 if (err) return console.error(err);21 console.log('Test completed in %d seconds', data.data.average.firstView.loadTime);22 console.log('View the test at %s', data.data.summary);23 });24});25var wpt = require('webpagetest');26var test = new wpt('www.webpagetest.org', 'A.2d6b8f6f1f6c2e6f3d6d1e
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.8d8b0f9e033e5b9c9d8f1e3c3f3d3b0c');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6 test.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});
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!!