diff --git a/benchmarks/binarytree.ce b/benchmarks/binarytree.ce index af76d9da..7a01d948 100644 --- a/benchmarks/binarytree.ce +++ b/benchmarks/binarytree.ce @@ -27,7 +27,7 @@ function TreeNode(left, right) { } function itemCheck(node) { - if (node.left === null) + if (node.left == null) return 1; return 1 + itemCheck(node.left) + itemCheck(node.right); } diff --git a/benchmarks/js_perf.ce b/benchmarks/js_perf.ce index 49589773..2e0d7326 100644 --- a/benchmarks/js_perf.ce +++ b/benchmarks/js_perf.ce @@ -296,7 +296,7 @@ function benchClosures() { //////////////////////////////////////////////////////////////////////////////// log.console("JavaScript Performance Benchmark"); -log.console("================================\n"); +log.console("======================\n"); // Property Access log.console("BENCHMARK: Property Access"); diff --git a/benchmarks/montecarlo.ce b/benchmarks/montecarlo.ce index f847c5da..15bfa186 100644 --- a/benchmarks/montecarlo.ce +++ b/benchmarks/montecarlo.ce @@ -1,4 +1,4 @@ -var N = 1000000; +var N = 10000000; var num = 0; for (var i = 0; i < N; i ++) { var x = 2 * $_.random(); @@ -8,4 +8,11 @@ for (var i = 0; i < N; i ++) { } log.console(2 * num / N); +var a = 100 +var b = 100 + +if ("test") log.console("OK!") + +log.console(a != b) + $_.stop() \ No newline at end of file diff --git a/benchmarks/nota.ce b/benchmarks/nota.ce index 63570441..e4a803eb 100644 --- a/benchmarks/nota.ce +++ b/benchmarks/nota.ce @@ -49,7 +49,7 @@ function getStats(arr) { } // Pretty print results -log.console("\n=== Performance Test Results (100 iterations) ==="); +log.console("\n== Performance Test Results (100 iterations) =="); log.console("\nJSON Decoding (ms):"); const jsonDecStats = getStats(jsonDecodeTimes); log.console(`Average: ${jsonDecStats.avg.toFixed(2)} ms`); diff --git a/benchmarks/wota.ce b/benchmarks/wota.ce index 823d0c4f..7ba23456 100644 --- a/benchmarks/wota.ce +++ b/benchmarks/wota.ce @@ -76,7 +76,7 @@ const benchmarks = [ // Print a header log.console("Wota Encode/Decode Benchmark"); -log.console("============================\n"); +log.console("===================\n"); // We'll run each benchmark scenario in turn. for (let bench of benchmarks) { diff --git a/benchmarks/wota_nota_json.ce b/benchmarks/wota_nota_json.ce index 24bbc6e3..7665c96e 100644 --- a/benchmarks/wota_nota_json.ce +++ b/benchmarks/wota_nota_json.ce @@ -13,7 +13,7 @@ // // Parse command line arguments -if (arg.length !== 2) { +if (arg.length != 2) { log.console('Usage: cell benchmark_wota_nota_json.ce '); $_.stop() } @@ -139,7 +139,7 @@ function runBenchmarkForLibrary(lib, bench) { let e = lib.encode(bench.data[j]); // store only in the very first iteration, so we can decode them later // but do not store them every iteration or we blow up memory. - if (i === 0) { + if (i == 0) { encodedList.push(e); totalSize += lib.getSize(e); } @@ -166,8 +166,8 @@ function runBenchmarkForLibrary(lib, bench) { //////////////////////////////////////////////////////////////////////////////// // Find the requested library and scenario -var lib = libraries.find(l => l.name === lib_name); -var bench = benchmarks.find(b => b.name === scenario_name); +var lib = libraries.find(l => l.name == lib_name); +var bench = benchmarks.find(b => b.name == scenario_name); if (!lib) { log.console('Unknown library:', lib_name); diff --git a/examples/http_download_actor.ce b/examples/http_download_actor.ce index f85370d0..9bbce384 100644 --- a/examples/http_download_actor.ce +++ b/examples/http_download_actor.ce @@ -18,7 +18,7 @@ var state = { // Helper to calculate progress percentage function get_progress() { - if (state.total_bytes === 0) { + if (state.total_bytes == 0) { return 0; } return Math.round((state.downloaded_bytes / state.total_bytes) * 100); @@ -150,7 +150,7 @@ function read_next_chunk() { try { var chunk = http.fetch_read_chunk(state.connection); - if (chunk === null) { + if (chunk == null) { // Download complete finish_download(); return; diff --git a/prosperon/_sprite.cm b/prosperon/_sprite.cm index 1119a0ce..66c2f4e8 100644 --- a/prosperon/_sprite.cm +++ b/prosperon/_sprite.cm @@ -12,7 +12,7 @@ var sprite = { return; } - if (typeof str === 'string') { + if (typeof str == 'string') { if (!this.animset[str]) { fn?.(); return; @@ -38,10 +38,10 @@ var sprite = { var done = false; if (reverse) { f = (((f - 1) % playing.frames.length) + playing.frames.length) % playing.frames.length; - if (f === playing.frames.length - 1) done = true; + if (f == playing.frames.length - 1) done = true; } else { f = (f + 1) % playing.frames.length; - if (f === 0) done = true; + if (f == 0) done = true; } this.image = playing.frames[f]; diff --git a/prosperon/clay.cm b/prosperon/clay.cm index 1ecd4243..d7eb7343 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -125,8 +125,8 @@ function add_item(config) // Adjust for child_gap if (root_config._childIndex > 0) { var parentContain = root_config.contain || 0; - var isVStack = (parentContain & layout.contain.column) !== 0; - var isHStack = (parentContain & layout.contain.row) !== 0; + var isVStack = (parentContain & layout.contain.column) != 0; + var isHStack = (parentContain & layout.contain.row) != 0; if (isVStack) { margin.t += childGap; @@ -162,7 +162,7 @@ function add_item(config) function rectify_configs(config_array) { - if (config_array.length === 0) + if (config_array.length == 0) config_array = [{}]; for (var i = config_array.length-1; i > 0; i--) diff --git a/prosperon/color.cm b/prosperon/color.cm index 027309b2..710e6fd0 100644 --- a/prosperon/color.cm +++ b/prosperon/color.cm @@ -1,6 +1,6 @@ function tohex(n) { var s = Math.floor(n).toString(16); - if (s.length === 1) s = "0" + s; + if (s.length == 1) s = "0" + s; return s.toUpperCase(); }; @@ -98,14 +98,14 @@ Color.normalize = function (c) { }; for (var p of Object.keys(c)) { - if (typeof c[p] !== "object") continue; + if (typeof c[p] != "object") continue; if (!Array.isArray(c[p])) { Color.normalize(c[p]); continue; } // Add alpha channel if not present - if (c[p].length === 3) { + if (c[p].length == 3) { c[p][3] = 1; } diff --git a/prosperon/controller.cm b/prosperon/controller.cm index 7bcec6ab..d21f65b4 100644 --- a/prosperon/controller.cm +++ b/prosperon/controller.cm @@ -107,8 +107,8 @@ input.mouse.normal.doc = "Set the mouse to show again after hiding."; input.keyboard = {}; input.keyboard.down = function (code) { - if (typeof code === "number") return downkeys[code]; - if (typeof code === "string") return downkeys[code.toUpperCase().charCodeAt()] || downkeys[code.toLowerCase().charCodeAt()]; + if (typeof code == "number") return downkeys[code]; + if (typeof code == "string") return downkeys[code.toUpperCase().charCodeAt()] || downkeys[code.toLowerCase().charCodeAt()]; return undefined; }; @@ -157,7 +157,7 @@ input.print_md_kbm = function print_md_kbm(pawn) { }; input.has_bind = function (pawn, bind) { - return typeof pawn.inputs?.[bind] === "function"; + return typeof pawn.inputs?.[bind] == "function"; }; input.action = { @@ -176,17 +176,17 @@ input.tabcomplete = function tabcomplete(val, list) { if (!val) return val; list = filter(x => x.startsWith(val)) - if (list.length === 1) { + if (list.length == 1) { return list[0]; } var ret = undefined; var i = val.length; - while (!ret && list.length !== 0) { + while (!ret && list.length != 0) { var char = list[0][i]; if ( !list.every(function (x) { - return x[i] === char; + return x[i] == char; }) ) ret = list[0].slice(0, i); @@ -213,7 +213,7 @@ var Player = { mouse_input(type, ...args) { for (var pawn of [...this.pawns].reverse()) { - if (typeof pawn.inputs?.mouse?.[type] === "function") { + if (typeof pawn.inputs?.mouse?.[type] == "function") { pawn.inputs.mouse[type].call(pawn, ...args); pawn.inputs.post?.call(pawn); if (!pawn.inputs.fallthru) return; @@ -223,7 +223,7 @@ var Player = { char_input(c) { for (var pawn of [...this.pawns].reverse()) { - if (typeof pawn.inputs?.char === "function") { + if (typeof pawn.inputs?.char == "function") { pawn.inputs.char.call(pawn, c); pawn.inputs.post?.call(pawn); if (!pawn.inputs.fallthru) return; @@ -270,16 +270,16 @@ var Player = { fn = inputs[cmd].released; break; case "down": - if (typeof inputs[cmd].down === "function") fn = inputs[cmd].down; + if (typeof inputs[cmd].down == "function") fn = inputs[cmd].down; else if (inputs[cmd].down) fn = inputs[cmd]; } var consumed = false; - if (typeof fn === "function") { + if (typeof fn == "function") { fn.call(pawn, ...args); consumed = true; } - if (state === "released") inputs.release_post?.call(pawn); + if (state == "released") inputs.release_post?.call(pawn); if (inputs.block) return; if (consumed) return; } diff --git a/prosperon/emitter.cm b/prosperon/emitter.cm index e08a9267..b0ea384e 100644 --- a/prosperon/emitter.cm +++ b/prosperon/emitter.cm @@ -111,7 +111,7 @@ ex.draw = function() if (!diff) throw new Error("emitter does not have a proper diffuse texture") var mesh = graphics.make_sprite_mesh(this.particles) - if (mesh.num_indices === 0) return + if (mesh.num_indices == 0) return render.queue({ type:'geometry', mesh, diff --git a/prosperon/examples/chess/chess.ce b/prosperon/examples/chess/chess.ce index 6731d772..0915eb0c 100644 --- a/prosperon/examples/chess/chess.ce +++ b/prosperon/examples/chess/chess.ce @@ -41,7 +41,7 @@ function updateTitle() { break; case 'connected': if (myColor) { - title += (mover.turn === myColor ? "Your turn (" + myColor + ")" : "Opponent's turn (" + mover.turn + ")"); + title += (mover.turn == myColor ? "Your turn (" + myColor + ")" : "Opponent's turn (" + mover.turn + ")"); } else { title += mover.turn + " turn"; } @@ -64,10 +64,10 @@ var opponentHoldingPiece = false; var opponentSelectPos = null; function handleMouseButtonDown(e) { - if (e.which !== 0) return; + if (e.which != 0) return; // Don't allow piece selection unless we have an opponent - if (gameState !== 'connected' || !opponent) return; + if (gameState != 'connected' || !opponent) return; var mx = e.mouse.x; var my = e.mouse.y; @@ -76,7 +76,7 @@ function handleMouseButtonDown(e) { if (!grid.inBounds(c)) return; var cell = grid.at(c); - if (cell.length && cell[0].colour === mover.turn) { + if (cell.length && cell[0].colour == mover.turn) { selectPos = c; holdingPiece = true; // Send pickup notification to opponent @@ -92,10 +92,10 @@ function handleMouseButtonDown(e) { } function handleMouseButtonUp(e) { - if (e.which !== 0 || !holdingPiece || !selectPos) return; + if (e.which != 0 || !holdingPiece || !selectPos) return; // Don't allow moves unless we have an opponent and it's our turn - if (gameState !== 'connected' || !opponent || !isMyTurn) { + if (gameState != 'connected' || !opponent || !isMyTurn) { holdingPiece = false; return; } @@ -147,7 +147,7 @@ function handleMouseMotion(e) { hoverPos = c; // Send mouse position to opponent in real-time - if (opponent && gameState === 'connected') { + if (opponent && gameState == 'connected') { send(opponent, { type: 'mouse_move', pos: c, @@ -159,11 +159,11 @@ function handleMouseMotion(e) { function handleKeyDown(e) { // S key - start server - if (e.scancode === 22 && gameState === 'waiting') { // S key + if (e.scancode == 22 && gameState == 'waiting') { // S key startServer(); } // J key - join server - else if (e.scancode === 13 && gameState === 'waiting') { // J key + else if (e.scancode == 13 && gameState == 'waiting') { // J key joinServer(); } } @@ -181,8 +181,8 @@ var opponentMouseColor = [1.0, 0.0, 0.0, 1.0]; // Red for opponent mouse function drawBoard() { for (var y = 0; y < 8; ++y) for (var x = 0; x < 8; ++x) { - var isMyHover = hoverPos && hoverPos[0] === x && hoverPos[1] === y; - var isOpponentHover = opponentMousePos && opponentMousePos[0] === x && opponentMousePos[1] === y; + var isMyHover = hoverPos && hoverPos[0] == x && hoverPos[1] == y; + var isOpponentHover = opponentMousePos && opponentMousePos[0] == x && opponentMousePos[1] == y; var isValidMove = selectPos && holdingPiece && isValidMoveForTurn(selectPos, [x, y]); var color = ((x+y)&1) ? dark : light; @@ -211,7 +211,7 @@ function isValidMoveForTurn(from, to) { // Check if the destination has a piece of the same color var destCell = grid.at(to); - if (destCell.length && destCell[0].colour === piece.colour) { + if (destCell.length && destCell[0].colour == piece.colour) { return false; } @@ -225,15 +225,15 @@ function drawPieces() { // Skip drawing the piece being held (by me or opponent) if (holdingPiece && selectPos && - piece.coord[0] === selectPos[0] && - piece.coord[1] === selectPos[1]) { + piece.coord[0] == selectPos[0] && + piece.coord[1] == selectPos[1]) { return; } // Skip drawing the piece being held by opponent if (opponentHoldingPiece && opponentSelectPos && - piece.coord[0] === opponentSelectPos[0] && - piece.coord[1] === opponentSelectPos[1]) { + piece.coord[0] == opponentSelectPos[0] && + piece.coord[1] == opponentSelectPos[1]) { return; } @@ -329,10 +329,10 @@ $_.receiver(e => { send(e, update(e.dt)) else if (e.kind == 'draw') send(e, draw()) - else if (e.type === 'game_start' || e.type === 'move' || e.type === 'greet') + else if (e.type == 'game_start' || e.type == 'move' || e.type == 'greet') log.console("Receiver got message:", e.type, e); - if (e.type === 'greet') { + if (e.type == 'greet') { log.console("Server received greet from client"); // Store the client's actor object for ongoing communication opponent = e.client_actor; @@ -348,13 +348,13 @@ $_.receiver(e => { }); log.console("game_start message sent to client"); } - else if (e.type === 'game_start') { + else if (e.type == 'game_start') { log.console("Game starting, I am:", e.your_color); myColor = e.your_color; - isMyTurn = (myColor === 'white'); + isMyTurn = (myColor == 'white'); gameState = 'connected'; updateTitle(); - } else if (e.type === 'move') { + } else if (e.type == 'move') { log.console("Received move from opponent:", e.from, "to", e.to); // Apply opponent's move var fromCell = grid.at(e.from); @@ -370,26 +370,26 @@ $_.receiver(e => { } else { log.console("No piece found at from position"); } - } else if (e.type === 'mouse_move') { + } else if (e.type == 'mouse_move') { // Update opponent's mouse position opponentMousePos = e.pos; opponentHoldingPiece = e.holding; opponentSelectPos = e.selectPos; - } else if (e.type === 'piece_pickup') { + } else if (e.type == 'piece_pickup') { // Opponent picked up a piece opponentSelectPos = e.pos; opponentHoldingPiece = true; - } else if (e.type === 'piece_drop') { + } else if (e.type == 'piece_drop') { // Opponent dropped their piece opponentHoldingPiece = false; opponentSelectPos = null; - } else if (e.type === 'mouse_button_down') { + } else if (e.type == 'mouse_button_down') { handleMouseButtonDown(e) - } else if (e.type === 'mouse_button_up') { + } else if (e.type == 'mouse_button_up') { handleMouseButtonUp(e) - } else if (e.type === 'mouse_motion') { + } else if (e.type == 'mouse_motion') { handleMouseMotion(e) - } else if (e.type === 'key_down') { + } else if (e.type == 'key_down') { handleKeyDown(e) } }) diff --git a/prosperon/examples/chess/grid.cm b/prosperon/examples/chess/grid.cm index 6e684596..868f90a7 100644 --- a/prosperon/examples/chess/grid.cm +++ b/prosperon/examples/chess/grid.cm @@ -47,7 +47,7 @@ grid.prototype = { var cell = this.at([x,y]); out += cell.length } - if (y !== this.height - 1) out += "\n" + if (y != this.height - 1) out += "\n" } return out diff --git a/prosperon/examples/chess/movement.cm b/prosperon/examples/chess/movement.cm index b4256fe2..19d42603 100644 --- a/prosperon/examples/chess/movement.cm +++ b/prosperon/examples/chess/movement.cm @@ -5,17 +5,17 @@ var MovementSystem = function(grid, rules) { } MovementSystem.prototype.tryMove = function (piece, to) { - if (piece.colour !== this.turn) return false; + if (piece.colour != this.turn) return false; // normalise ‘to’ into our hybrid coord - var dest = [to.x !== undefined ? to.x : to[0], - to.y !== undefined ? to.y : to[1]]; + var dest = [to.x != undefined ? to.x : to[0], + to.y != undefined ? to.y : to[1]]; if (!this.grid.inBounds(dest)) return false; if (!this.rules.canMove(piece, piece.coord, dest, this.grid)) return false; var victims = this.grid.at(dest); - if (victims.length && victims[0].colour === piece.colour) return false; + if (victims.length && victims[0].colour == piece.colour) return false; if (victims.length) victims[0].captured = true; this.grid.remove(piece, piece.coord); @@ -25,7 +25,7 @@ MovementSystem.prototype.tryMove = function (piece, to) { piece.coord.x = dest.x; piece.coord.y = dest.y; - this.turn = (this.turn === 'white') ? 'black' : 'white'; + this.turn = (this.turn == 'white') ? 'black' : 'white'; return true; }; diff --git a/prosperon/examples/chess/rules.cm b/prosperon/examples/chess/rules.cm index 7c0b670c..323cb0af 100644 --- a/prosperon/examples/chess/rules.cm +++ b/prosperon/examples/chess/rules.cm @@ -1,32 +1,32 @@ /* helper – robust coord access */ -function cx(c) { return (c.x !== undefined) ? c.x : c[0]; } -function cy(c) { return (c.y !== undefined) ? c.y : c[1]; } +function cx(c) { return (c.x != undefined) ? c.x : c[0]; } +function cy(c) { return (c.y != undefined) ? c.y : c[1]; } /* simple move-shape checks */ var deltas = { pawn: function (pc, dx, dy, grid, to) { - var dir = (pc.colour === 'white') ? -1 : 1; - var base = (pc.colour === 'white') ? 6 : 1; - var one = (dy === dir && dx === 0 && grid.at(to).length === 0); - var two = (dy === 2 * dir && dx === 0 && cy(pc.coord) === base && - grid.at({ x: cx(pc.coord), y: cy(pc.coord)+dir }).length === 0 && - grid.at(to).length === 0); - var cap = (dy === dir && Math.abs(dx) === 1 && grid.at(to).length); + var dir = (pc.colour == 'white') ? -1 : 1; + var base = (pc.colour == 'white') ? 6 : 1; + var one = (dy == dir && dx == 0 && grid.at(to).length == 0); + var two = (dy == 2 * dir && dx == 0 && cy(pc.coord) == base && + grid.at({ x: cx(pc.coord), y: cy(pc.coord)+dir }).length == 0 && + grid.at(to).length == 0); + var cap = (dy == dir && Math.abs(dx) == 1 && grid.at(to).length); return one || two || cap; }, - rook : function (pc, dx, dy) { return (dx === 0 || dy === 0); }, - bishop: function (pc, dx, dy) { return Math.abs(dx) === Math.abs(dy); }, - queen : function (pc, dx, dy) { return (dx === 0 || dy === 0 || Math.abs(dx) === Math.abs(dy)); }, - knight: function (pc, dx, dy) { return (Math.abs(dx) === 1 && Math.abs(dy) === 2) || - (Math.abs(dx) === 2 && Math.abs(dy) === 1); }, - king : function (pc, dx, dy) { return Math.max(Math.abs(dx), Math.abs(dy)) === 1; } + rook : function (pc, dx, dy) { return (dx == 0 || dy == 0); }, + bishop: function (pc, dx, dy) { return Math.abs(dx) == Math.abs(dy); }, + queen : function (pc, dx, dy) { return (dx == 0 || dy == 0 || Math.abs(dx) == Math.abs(dy)); }, + knight: function (pc, dx, dy) { return (Math.abs(dx) == 1 && Math.abs(dy) == 2) || + (Math.abs(dx) == 2 && Math.abs(dy) == 1); }, + king : function (pc, dx, dy) { return Math.max(Math.abs(dx), Math.abs(dy)) == 1; } }; function clearLine(from, to, grid) { var dx = Math.sign(cx(to) - cx(from)); var dy = Math.sign(cy(to) - cy(from)); var x = cx(from) + dx, y = cy(from) + dy; - while (x !== cx(to) || y !== cy(to)) { + while (x != cx(to) || y != cy(to)) { if (grid.at({ x: x, y: y }).length) return false; x += dx; y += dy; } @@ -38,7 +38,7 @@ function canMove(piece, from, to, grid) { var dy = cy(to) - cy(from); var f = deltas[piece.kind]; if (!f || !f(piece, dx, dy, grid, to)) return false; - if (piece.kind === 'knight') return true; + if (piece.kind == 'knight') return true; return clearLine(from, to, grid); } diff --git a/prosperon/examples/snake/main.ce b/prosperon/examples/snake/main.ce index f40c965c..d7830f56 100644 --- a/prosperon/examples/snake/main.ce +++ b/prosperon/examples/snake/main.ce @@ -36,7 +36,7 @@ function spawnApple() { apple = {x:Math.floor(Math.random()*gridW), y:Math.floor(Math.random()*gridH)} // Re-spawn if apple lands on snake for (var i=0; i x.type === 'sprite') - if (sprites.length === 0) return [] + var sprites = queue.filter(x => x.type == 'sprite') + if (sprites.length == 0) return [] var mesh = graphics.make_sprite_mesh(sprites) for (var i = 0; i < sprites.length; i++) { sprites[i].mesh = mesh diff --git a/prosperon/imgui.cm b/prosperon/imgui.cm index 34e5a192..4f228fc4 100644 --- a/prosperon/imgui.cm +++ b/prosperon/imgui.cm @@ -17,7 +17,7 @@ function imtoggle(name, obj, field) { var changed = false; var old = obj[field]; obj[field] = imgui.checkbox(name, obj[field]); - if (old !== obj[field]) return true; + if (old != obj[field]) return true; return false; }; diff --git a/prosperon/prosperon.ce b/prosperon/prosperon.ce index a991608a..58e77356 100644 --- a/prosperon/prosperon.ce +++ b/prosperon/prosperon.ce @@ -19,7 +19,7 @@ var video var cnf = use('accio/config') $_.start(e => { - if (e.type !== 'greet') return + if (e.type != 'greet') return video = e.actor graphics = use('graphics', video) send(video, {kind:"window", op:"makeRenderer"}, e => { @@ -145,15 +145,15 @@ function translate_draw_commands(commands) { // Handle rectangles with optional rounding and thickness if (cmd.opt && cmd.opt.radius && cmd.opt.radius > 0) { // Rounded rectangle - var thickness = (cmd.opt.thickness === 0) ? 0 : (cmd.opt.thickness || 1) + var thickness = (cmd.opt.thickness == 0) ? 0 : (cmd.opt.thickness || 1) var raster_result = rasterize.round_rect(cmd.rect, cmd.opt.radius, thickness) - if (raster_result.type === 'rect') { + if (raster_result.type == 'rect') { renderer_commands.push({ op: "fillRect", data: {rect: raster_result.data} }) - } else if (raster_result.type === 'rects') { + } else if (raster_result.type == 'rects') { raster_result.data.forEach(function(rect) { renderer_commands.push({ op: "fillRect", @@ -165,12 +165,12 @@ function translate_draw_commands(commands) { // Outlined rectangle var raster_result = rasterize.outline_rect(cmd.rect, cmd.opt.thickness) - if (raster_result.type === 'rect') { + if (raster_result.type == 'rect') { renderer_commands.push({ op: "fillRect", data: {rect: raster_result.data} }) - } else if (raster_result.type === 'rects') { + } else if (raster_result.type == 'rects') { renderer_commands.push({ op: "rects", data: {rects: raster_result.data} @@ -191,12 +191,12 @@ function translate_draw_commands(commands) { var radii = cmd.radii || [cmd.radius, cmd.radius] var raster_result = rasterize.ellipse(cmd.pos, radii, cmd.opt || {}) - if (raster_result.type === 'points') { + if (raster_result.type == 'points') { renderer_commands.push({ op: "point", data: {points: raster_result.data} }) - } else if (raster_result.type === 'rects') { + } else if (raster_result.type == 'rects') { // Use 'rects' operation for multiple rectangles renderer_commands.push({ op: "rects", @@ -311,7 +311,7 @@ var input_state = { function poll_input() { send(video, {kind:'input', op:'get'}, evs => { for (var ev of evs) { - if (ev.type === 'quit') + if (ev.type == 'quit') $_.stop() if (ev.type.includes('mouse')) { diff --git a/prosperon/rasterize.cm b/prosperon/rasterize.cm index 3ced0429..ceaf0281 100644 --- a/prosperon/rasterize.cm +++ b/prosperon/rasterize.cm @@ -35,7 +35,7 @@ rasterize.ellipse = function ellipse(pos, radii, opt) { ry_i = ry - thickness var hole = (rx_i > 0 && ry_i > 0) - if (!hole && thickness === 1) { + if (!hole && thickness == 1) { var points = [] var rx_sq = rx * rx, ry_sq = ry * ry var two_rx_sq = rx_sq << 1, two_ry_sq = ry_sq << 1 @@ -82,9 +82,9 @@ rasterize.ellipse = function ellipse(pos, radii, opt) { if (hole && Math.abs(dx) <= x_in) { run_start = null; continue } if (!within_wedge(dx, dy, start, end, full_circle)) { run_start = null; continue } - if (run_start === null) run_start = cx + dx + if (run_start == null) run_start = cx + dx - var last = (dx === x_out) + var last = (dx == x_out) var next_in_ring = !last && !(hole && Math.abs(dx+1) <= x_in) && diff --git a/prosperon/resources.cm b/prosperon/resources.cm index ef8795c9..840cb1b9 100644 --- a/prosperon/resources.cm +++ b/prosperon/resources.cm @@ -41,7 +41,7 @@ function isRecognizedExtension(ext) { } function find_in_path(filename, exts = []) { - if (typeof filename !== 'string') return undefined + if (typeof filename != 'string') return undefined if (filename.includes('.')) { var candidate = filename // possibly need "/" ? diff --git a/prosperon/scenetree.cm b/prosperon/scenetree.cm index 11db13df..463e246a 100644 --- a/prosperon/scenetree.cm +++ b/prosperon/scenetree.cm @@ -45,7 +45,7 @@ globalThis.Register = { var fns = [] n.register = function (fn, oname) { - if (typeof fn !== 'function') return + if (typeof fn != 'function') return var dofn = function (...args) { fn(...args) @@ -59,7 +59,7 @@ globalThis.Register = { while (left <= right) { var mid = Math.floor((left + right) / 2) - if (fns[mid] === dofn.layer) { + if (fns[mid] == dofn.layer) { left = mid break } else if (fns[mid].layer < dofn.layer) left = mid + 1 @@ -93,7 +93,7 @@ globalThis.Register = { Register.pull_registers = function pull_registers(obj) { var reggies = [] for (var reg in Register.registries) { - if (typeof obj[reg] === "function") + if (typeof obj[reg] == "function") reggies.push(reg) } return reggies @@ -115,7 +115,7 @@ Register.check_registers = function check_registers(obj) { return } for (var reg in Register.registries) { - if (typeof obj[reg] === "function") + if (typeof obj[reg] == "function") Register.register_obj(obj,reg) } } @@ -205,7 +205,7 @@ actor.spawn = function spawn(script, config, actor_context) { if (underling[DEAD]) return undefined; - if (typeof config === 'object') Object.assign(underling, config) + if (typeof config == 'object') Object.assign(underling, config) if (!underling[REGGIES]) underling.__proto__[REGGIES] = Register.pull_registers(underling) @@ -238,8 +238,8 @@ actor.kill = function kill() { this[OVERLING][UNDERLINGS].delete(this) delete this[UNDERLINGS] - if (typeof this.garbage === "function") this.garbage() - if (typeof this.then === "function") this.then() + if (typeof this.garbage == "function") this.garbage() + if (typeof this.then == "function") this.then() act.tag_clear_guid(this) } @@ -264,7 +264,7 @@ function eachobj(obj, fn) { var val = fn(obj) if (val) return val for (var o in obj.objects) { - if (obj.objects[o] === obj) log.error(`Object ${obj.toString()} is referenced by itself.`) + if (obj.objects[o] == obj) log.error(`Object ${obj.toString()} is referenced by itself.`) val = eachobj(obj.objects[o], fn) if (val) return val } @@ -382,7 +382,7 @@ var script_fn = function script_fn(path, args) { var mod_script = `(function setup_${module_name}_module(){ var self = this; var $ = this; var exports = {}; var module = {exports: exports}; var define = undefined; var arg = this.__args__; ${parsed.module}})` var module_fn = js.eval(file, mod_script) parsed.module_ret = module_fn.call(context) - if (parsed.module_ret === undefined || parsed.module_ret === null) + if (parsed.module_ret == undefined || parsed.module_ret == null) throw new Error(`Module ${module_name} must return a value`) parsed.module_fn = module_fn } diff --git a/prosperon/sdl_gpu.cm b/prosperon/sdl_gpu.cm index cc6042b1..6c21472d 100644 --- a/prosperon/sdl_gpu.cm +++ b/prosperon/sdl_gpu.cm @@ -181,7 +181,7 @@ function ubo_obj_to_array(pipeline, name, obj) { var val = obj[mem.name]; if (!val) throw new Error (`Could not find ${mem.name} on supplied object`); - if (mem.name === 'model') + if (mem.name == 'model') val = transpose4x4(val.array()); for (var i = 0; i < val.length; i++) @@ -226,9 +226,9 @@ var shader_times = {}; function make_pipeline(pipeline) { if (pipeline.hasOwnProperty("gpu")) return; // this pipeline has already been made - if (typeof pipeline.vertex === 'string') + if (typeof pipeline.vertex == 'string') pipeline.vertex = make_shader(pipeline.vertex); - if (typeof pipeline.fragment === 'string') + if (typeof pipeline.fragment == 'string') pipeline.fragment = make_shader(pipeline.fragment) // 1) Reflection data for vertex shader @@ -309,7 +309,7 @@ function make_shader(sh_file) { num_textures: 0, num_storage_buffers: refl.separate_storage_buffers ? refl.separate_storage_buffers.length : 0, num_uniform_buffers: refl.ubos ? refl.ubos.length : 0, - entrypoint: shader_type === "msl" ? "main0" : "main" + entrypoint: shader_type == "msl" ? "main0" : "main" } shader.gpu = context.make_shader(shader) @@ -349,7 +349,7 @@ var std_sampler = { function upload_model(model) { var bufs = []; for (var i in model) { - if (typeof model[i] !== 'object') continue; + if (typeof model[i] != 'object') continue; bufs.push(model[i]); } context.upload(this, bufs); @@ -405,7 +405,7 @@ bind_mat[cell.DOC] = `Bind the material images and samplers needed by the pipeli ` function group_sprites_by_texture(sprites, mesh) { - if (sprites.length === 0) return; + if (sprites.length == 0) return; for (var i = 0; i < sprites.length; i++) { sprites[i].mesh = mesh; sprites[i].first_index = i*6; @@ -418,7 +418,7 @@ function group_sprites_by_texture(sprites, mesh) { var group = {image:sprites[0].image, first_index:0}; var count = 1; for (var i = 1; i < sprites.length; i++) { - if (sprites[i].image === group.image) { + if (sprites[i].image == group.image) { count++; continue; } @@ -495,7 +495,7 @@ function render_camera(cmds, camera) { buffers = buffers.concat(graphics.queue_sprite_mesh(hud_queue)); for (var q of hud_queue) - if (q.type === 'geometry') buffers = buffers.concat([q.mesh.pos, q.mesh.color, q.mesh.uv, q.mesh.indices]); + if (q.type == 'geometry') buffers = buffers.concat([q.mesh.pos, q.mesh.color, q.mesh.uv, q.mesh.indices]); full_upload(buffers) @@ -505,11 +505,11 @@ function render_camera(cmds, camera) { bind_pipeline(pass,pipeline); var camslot = get_pipeline_ubo_slot(pipeline, 'TransformBuffer'); - if (typeof camslot !== 'undefined') + if (typeof camslot != 'undefined') cmds.camera(camera, camslot); modelslot = get_pipeline_ubo_slot(pipeline, "model"); - if (typeof modelslot !== 'undefined') { + if (typeof modelslot != 'undefined') { var ubo = ubo_obj_to_array(pipeline, 'model', sprite_model_ubo); cmds.push_vertex_uniform_data(modelslot, ubo); } @@ -537,7 +537,7 @@ function render_camera(cmds, camera) { cmds.push_debug_group("hud") var camslot = get_pipeline_ubo_slot(pipeline, 'TransformBuffer'); - if (typeof camslot !== 'undefined') + if (typeof camslot != 'undefined') cmds.hud(camera.size, camslot); for (var group of hud_queue) { @@ -651,7 +651,7 @@ var stencil_invert = { }; function mask(image, pos, scale, rotation = 0, ref = 1) { - if (typeof image === 'string') + if (typeof image == 'string') image = graphics.texture(image); var tex = image.texture; diff --git a/prosperon/sdl_video.ce b/prosperon/sdl_video.ce index e0f93885..50349966 100644 --- a/prosperon/sdl_video.ce +++ b/prosperon/sdl_video.ce @@ -145,7 +145,7 @@ function handle_window(msg) { if (!prop) return {error: "Missing property name"}; // Handle special cases - if (prop === 'surface') { + if (prop == 'surface') { var surf = win.surface; if (!surf) return {data: null}; var surf_id = allocate_id(); @@ -162,7 +162,7 @@ function handle_window(msg) { // Validate property is settable var readonly = ['id', 'pixelDensity', 'displayScale', 'sizeInPixels', 'flags', 'surface']; - if (readonly.indexOf(prop) !== -1) { + if (readonly.indexOf(prop) != -1) { return {error: "Property '" + prop + "' is read-only"}; } @@ -244,9 +244,9 @@ var renderfuncs = { if (!prop) return {error: "Missing property name"}; // Handle special getters that might return objects - if (prop === 'drawColor') { + if (prop == 'drawColor') { var color = ren[prop]; - if (color && typeof color === 'object') { + if (color && typeof color == 'object') { // Convert color object to array format [r,g,b,a] return {data: [color.r || 0, color.g || 0, color.b || 0, color.a || 255]}; } @@ -264,12 +264,12 @@ var renderfuncs = { // Validate property is settable var readonly = ['window', 'name', 'outputSize', 'currentOutputSize', 'logicalPresentationRect', 'safeArea']; - if (readonly.indexOf(prop) !== -1) { + if (readonly.indexOf(prop) != -1) { return {error: "Property '" + prop + "' is read-only"}; } // Special handling for render target - if (prop === 'target' && value !== null && value !== undefined) { + if (prop == 'target' && value != null && value != undefined) { var tex = resources.texture[value]; if (!tex) return {error: "Invalid texture id"}; value = tex; @@ -468,7 +468,7 @@ function handle_renderer(msg) { // Texture operations function handle_texture(msg) { // Special case: create needs a renderer - if (msg.op === 'create') { + if (msg.op == 'create') { if (!msg.data) return {error: "Missing texture data"}; var ren_id = msg.data.renderer_id; if (!ren_id || !resources.renderer[ren_id]) return {error: "Invalid renderer id"}; @@ -527,7 +527,7 @@ function handle_texture(msg) { // Validate property is settable var readonly = ['size', 'width', 'height']; - if (readonly.indexOf(prop) !== -1) { + if (readonly.indexOf(prop) != -1) { return {error: "Property '" + prop + "' is read-only"}; } @@ -616,12 +616,12 @@ function handle_mouse(msg) { switch (msg.op) { case 'show': - if (msg.data === undefined) return {error: "Missing show parameter"}; + if (msg.data == undefined) return {error: "Missing show parameter"}; mouse.show(msg.data); return {success: true}; case 'capture': - if (msg.data === undefined) return {error: "Missing capture parameter"}; + if (msg.data == undefined) return {error: "Missing capture parameter"}; mouse.capture(msg.data); return {success: true}; @@ -655,7 +655,7 @@ function handle_mouse(msg) { if (!cursor) return {data: null}; // Find or create cursor ID for (var id in resources.cursor) { - if (resources.cursor[id] === cursor) { + if (resources.cursor[id] == cursor) { return {data: id}; } } @@ -669,7 +669,7 @@ function handle_mouse(msg) { if (!cursor) return {data: null}; // Find or create cursor ID for (var id in resources.cursor) { - if (resources.cursor[id] === cursor) { + if (resources.cursor[id] == cursor) { return {data: id}; } } @@ -679,7 +679,7 @@ function handle_mouse(msg) { return {data: cursor_id}; case 'create_system_cursor': - if (msg.data === undefined) return {error: "Missing cursor type"}; + if (msg.data == undefined) return {error: "Missing cursor type"}; var cursor = mouse.create_system_cursor(msg.data); var cursor_id = allocate_id(); resources.cursor[cursor_id] = cursor; @@ -690,7 +690,7 @@ function handle_mouse(msg) { if (!window) return {data: null}; // Find window ID for (var id in resources.window) { - if (resources.window[id] === window) { + if (resources.window[id] == window) { return {data: id}; } } @@ -717,7 +717,7 @@ function handle_keyboard(msg) { if (!window) return {data: null}; // Find window ID for (var id in resources.window) { - if (resources.window[id] === window) { + if (resources.window[id] == window) { return {data: id}; } } diff --git a/prosperon/tests/camera_colorspace.ce b/prosperon/tests/camera_colorspace.ce index 6cb155d8..15eaa40b 100644 --- a/prosperon/tests/camera_colorspace.ce +++ b/prosperon/tests/camera_colorspace.ce @@ -4,7 +4,7 @@ var json = use('json'); // Get list of cameras var cameras = camera.list(); -if (cameras.length === 0) { +if (cameras.length == 0) { log.console("No cameras found!"); $_. stop(); } diff --git a/prosperon/tests/camera_colorspace_convert.ce b/prosperon/tests/camera_colorspace_convert.ce index c05dc958..5289a943 100644 --- a/prosperon/tests/camera_colorspace_convert.ce +++ b/prosperon/tests/camera_colorspace_convert.ce @@ -5,7 +5,7 @@ var json = use('json'); // Get first camera var cameras = camera.list(); -if (cameras.length === 0) { +if (cameras.length == 0) { log.console("No cameras found!"); $_.stop(); } @@ -30,10 +30,10 @@ log.console(" Colorspace:", format.colorspace); // Handle camera approval var approved = false; $_.receiver(e => { - if (e.type === 'camera_device_approved') { + if (e.type == 'camera_device_approved') { log.console("\nCamera approved!"); approved = true; - } else if (e.type === 'camera_device_denied') { + } else if (e.type == 'camera_device_denied') { log.error("Camera access denied!"); $_.stop(); } @@ -63,7 +63,7 @@ function capture_test() { log.console("\nTesting colorspace conversions:"); // Convert to sRGB if not already - if (format.colorspace !== "srgb") { + if (format.colorspace != "srgb") { try { var srgb_surf = surf.convert(surf.format, "srgb"); log.console(" Converted to sRGB colorspace"); @@ -89,7 +89,7 @@ function capture_test() { } // If YUV format, try BT.709 (HD video standard) - if (surf.format.indexOf("yuv") !== -1 || surf.format.indexOf("yuy") !== -1) { + if (surf.format.indexOf("yuv") != -1 || surf.format.indexOf("yuy") != -1) { try { var hd_surf = surf.convert(surf.format, "bt709_limited"); log.console(" Converted to BT.709 limited (HD video standard)"); diff --git a/prosperon/tests/camera_info.ce b/prosperon/tests/camera_info.ce index 99748a1b..f5d0a316 100644 --- a/prosperon/tests/camera_info.ce +++ b/prosperon/tests/camera_info.ce @@ -41,7 +41,7 @@ if (cameras.length > 0) { // Try to find a 640x480 format var preferred_format = null; for (var i = 0; i < formats.length; i++) { - if (formats[i].width === 640 && formats[i].height === 480) { + if (formats[i].width == 640 && formats[i].height == 480) { preferred_format = formats[i]; break; } diff --git a/prosperon/tests/webcam.ce b/prosperon/tests/webcam.ce index 40a28434..2628ad8d 100644 --- a/prosperon/tests/webcam.ce +++ b/prosperon/tests/webcam.ce @@ -20,10 +20,10 @@ var webcam_texture = null; // Handle camera events $_.receiver(e => { - if (e.type === 'camera_device_approved' && e.which === cam_id) { + if (e.type == 'camera_device_approved' && e.which == cam_id) { log.console("Camera approved!"); cam_approved = true; - } else if (e.type === 'camera_device_denied' && e.which === cam_id) { + } else if (e.type == 'camera_device_denied' && e.which == cam_id) { log.error("Camera access denied!"); $_.stop(); } @@ -67,7 +67,7 @@ send(video_actor, { // List available cameras var cameras = camera.list(); - if (cameras.length === 0) { + if (cameras.length == 0) { log.error("No cameras found!"); log.console(json.encode(cameras)) $_.stop(); @@ -89,10 +89,10 @@ send(video_actor, { // Look for a 640x480 format with preferred colorspace var preferred_format = null; for (var i = 0; i < formats.length; i++) { - if (formats[i].width === 640 && formats[i].height === 480) { + if (formats[i].width == 640 && formats[i].height == 480) { preferred_format = formats[i]; // Prefer JPEG or sRGB colorspace if available - if (formats[i].colorspace === "jpeg" || formats[i].colorspace === "srgb") { + if (formats[i].colorspace == "jpeg" || formats[i].colorspace == "srgb") { break; } } diff --git a/prosperon/tests/window.ce b/prosperon/tests/window.ce index d7db8efe..2d0749fd 100644 --- a/prosperon/tests/window.ce +++ b/prosperon/tests/window.ce @@ -49,7 +49,7 @@ send(ioguy, { }) $_.receiver(e => { - if (e.type === 'quit') + if (e.type == 'quit') os.exit() else log.console(json.encode(e)) diff --git a/prosperon/tilemap.cm b/prosperon/tilemap.cm index 4d3a3d17..cf5712e8 100644 --- a/prosperon/tilemap.cm +++ b/prosperon/tilemap.cm @@ -14,12 +14,12 @@ tilemap.for = function (map, fn) { for (var x = 0; x < map.tiles.length; x++) { if (!map.tiles[x]) continue; for (var y = 0; y < map.tiles[x].length; y++) { - if (map.tiles[x][y] !== undefined) { + if (map.tiles[x][y] != undefined) { var result = fn(map.tiles[x][y], { x: x + map.offset_x, y: y + map.offset_y }); - if (result !== undefined) { + if (result != undefined) { map.tiles[x][y] = result; } } diff --git a/prosperon/tween.cm b/prosperon/tween.cm index 2a2d08f6..3287185e 100644 --- a/prosperon/tween.cm +++ b/prosperon/tween.cm @@ -43,15 +43,15 @@ Ease.quint = make_easing_fns(5) Ease.expo = { in(t) { - return t === 0 ? 0 : Math.pow(2, 10 * t - 10) + return t == 0 ? 0 : Math.pow(2, 10 * t - 10) }, out(t) { - return t === 1 ? 1 : 1 - Math.pow(2, -10 * t) + return t == 1 ? 1 : 1 - Math.pow(2, -10 * t) }, inout(t) { - return t === 0 + return t == 0 ? 0 - : t === 1 + : t == 1 ? 1 : t < 0.5 ? Math.pow(2, 20 * t - 10) / 2 @@ -93,26 +93,26 @@ Ease.sine = { Ease.elastic = { in(t) { - return t === 0 + return t == 0 ? 0 - : t === 1 + : t == 1 ? 1 : -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * this.c4) }, out(t) { - return t === 0 + return t == 0 ? 0 - : t === 1 + : t == 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * this.c4) + 1 }, inout(t) { - t === 0 + t == 0 ? 0 - : t === 1 + : t == 1 ? 1 : t < 0.5 ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * this.c5)) / 2 @@ -159,8 +159,8 @@ var Tween = { var defn = Object.create(this.default) Object.assign(defn, options) - if (defn.loop === "circle") tvals.push(tvals[0]) - else if (defn.loop === "yoyo") { + if (defn.loop == "circle") tvals.push(tvals[0]) + else if (defn.loop == "yoyo") { for (var i = tvals.length - 2; i >= 0; i--) tvals.push(tvals[i]) } @@ -170,15 +170,15 @@ var Tween = { defn.fn = function (dt) { defn.accum += dt - if (defn.accum >= defn.time && defn.loop === "hold") { - if (typeof target === "string") obj[target] = tvals[tvals.length - 1] + if (defn.accum >= defn.time && defn.loop == "hold") { + if (typeof target == "string") obj[target] = tvals[tvals.length - 1] else target(tvals[tvals.length - 1]) defn.pause() defn.cb.call(obj) return } defn.pct = (defn.accum % defn.time) / defn.time - if (defn.loop === "none" && defn.accum >= defn.time) defn.stop() + if (defn.loop == "none" && defn.accum >= defn.time) defn.stop() var t = defn.whole ? defn.ease(defn.pct) : defn.pct var nval = t / slicelen @@ -186,7 +186,7 @@ var Tween = { nval -= i if (!defn.whole) nval = defn.ease(nval) - if (typeof target === "string") obj[target] = tvals[i].lerp(tvals[i + 1], nval) + if (typeof target == "string") obj[target] = tvals[i].lerp(tvals[i + 1], nval) else target(tvals[i].lerp(tvals[i + 1], nval)) } @@ -199,7 +199,7 @@ var Tween = { } defn.restart = function () { defn.accum = 0 - if (typeof target === "string") obj[target] = tvals[0] + if (typeof target == "string") obj[target] = tvals[0] else target(tvals[0]) } defn.stop = function () { diff --git a/scripts/base.cm b/scripts/base.cm index d33424c6..3b579f0f 100644 --- a/scripts/base.cm +++ b/scripts/base.cm @@ -1,5 +1,5 @@ Object.mixin = function (target, source) { - if (typeof source !== "object") return target; + if (typeof source != "object") return target; Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); return target; }; @@ -13,7 +13,7 @@ Object.mixin[cell.DOC] = `Copy all property descriptors from 'source' into 'targ Object.defineProperty(Object.prototype, "mixin", { value: function mixin(obj) { - if (typeof obj === "string") obj = use(obj); + if (typeof obj == "string") obj = use(obj); if (obj) Object.mixin(this, obj); }, }); @@ -43,7 +43,7 @@ and 'endidx' (exclusive). If 'endidx' is omitted, it defaults to 'index + 1'. Object.defineProperty(String.prototype, "tolast", { value: function (val) { var idx = this.lastIndexOf(val); - if (idx === -1) return this.slice(); + if (idx == -1) return this.slice(); return this.slice(0, idx); }, }); @@ -75,7 +75,7 @@ Object.defineProperty(String.prototype, "next", { else if (!from) from = 0; var find = this.slice(from).search(char[0]); - if (find === -1) return -1; + if (find == -1) return -1; else return from + find; var i = 0; @@ -110,7 +110,7 @@ Object.defineProperty(String.prototype, "prev", { count--; } - if (find === -1) return 0; + if (find == -1) return 0; else return find; }, }); @@ -166,7 +166,7 @@ Object.defineProperty(String.prototype, "up_path", { Object.defineProperty(String.prototype, "fromlast", { value: function (val) { var idx = this.lastIndexOf(val); - if (idx === -1) return ""; + if (idx == -1) return ""; return this.slice(idx + 1); }, }); @@ -181,7 +181,7 @@ If 'val' is not found, an empty string is returned. Object.defineProperty(String.prototype, "tofirst", { value: function (val) { var idx = this.indexOf(val); - if (idx === -1) return this.slice(); + if (idx == -1) return this.slice(); return this.slice(0, idx); }, }); @@ -196,7 +196,7 @@ of 'val' (excluded). If 'val' is not found, the entire string is returned. Object.defineProperty(String.prototype, "fromfirst", { value: function (val) { var idx = this.indexOf(val); - if (idx === -1) return this; + if (idx == -1) return this; return this.slice(idx + val.length); }, }); @@ -211,7 +211,7 @@ If 'val' is not found, the entire string is returned. Object.defineProperty(String.prototype, "name", { value: function () { var idx = this.indexOf("/"); - if (idx === -1) return this.tolast("."); + if (idx == -1) return this.tolast("."); return this.fromlast("/").tolast("."); }, }); @@ -251,7 +251,7 @@ If no '/' is present, the entire string is returned. Object.defineProperty(String.prototype, "updir", { value: function () { - if (this.lastIndexOf("/") === this.length - 1) return this.slice(0, this.length - 1); + if (this.lastIndexOf("/") == this.length - 1) return this.slice(0, this.length - 1); var dir = (this + "/").dir(); return dir.dir(); }, @@ -317,13 +317,13 @@ The resulting array is entirely new. Object.defineProperty(Array.prototype, "equal", { value: function equal(b) { - if (this.length !== b.length) return false; + if (this.length != b.length) return false; if (b == null) return false; - if (this === b) return true; - return JSON.stringify(this) === JSON.stringify(b); + if (this == b) return true; + return JSON.stringify(this) == JSON.stringify(b); for (var i = 0; i < this.length; i++) { - if (!this[i] === b[i]) return false; + if (!this[i] == b[i]) return false; } return true; }, diff --git a/scripts/config.ce b/scripts/config.ce index 3f3d54e1..664d7b05 100644 --- a/scripts/config.ce +++ b/scripts/config.ce @@ -40,7 +40,7 @@ function parse_key(key) { function get_nested(obj, path) { var current = obj for (var segment of path) { - if (!current || typeof current !== 'object') return undefined + if (!current || typeof current != 'object') return undefined current = current[segment] } return current @@ -51,7 +51,7 @@ function set_nested(obj, path, value) { var current = obj for (var i = 0; i < path.length - 1; i++) { var segment = path[i] - if (!current[segment] || typeof current[segment] !== 'object') { + if (!current[segment] || typeof current[segment] != 'object') { current[segment] = {} } current = current[segment] @@ -62,8 +62,8 @@ function set_nested(obj, path, value) { // Parse value string into appropriate type function parse_value(str) { // Boolean - if (str === 'true') return true - if (str === 'false') return false + if (str == 'true') return true + if (str == 'false') return false // Number (including underscores) var num_str = str.replace(/_/g, '') @@ -76,8 +76,8 @@ function parse_value(str) { // Format value for display function format_value(val) { - if (typeof val === 'string') return '"' + val + '"' - if (typeof val === 'number' && val >= 1000) { + if (typeof val == 'string') return '"' + val + '"' + if (typeof val == 'number' && val >= 1000) { // Add underscores to large numbers return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '_') } @@ -90,7 +90,7 @@ function print_config(obj, prefix = '') { var val = obj[key] var full_key = prefix ? prefix + '.' + key : key - if (val && typeof val === 'object' && !Array.isArray(val)) { + if (val && typeof val == 'object' && !Array.isArray(val)) { print_config(val, full_key) } else { log.console(full_key + ' = ' + format_value(val)) @@ -99,7 +99,7 @@ function print_config(obj, prefix = '') { } // Main command handling -if (args.length === 0) { +if (args.length == 0) { print_help() $_.stop() return @@ -137,9 +137,9 @@ switch (command) { var path = parse_key(key) var value = get_nested(config, path) - if (value === undefined) { + if (value == undefined) { log.error("Key not found: " + key) - } else if (value && typeof value === 'object' && !Array.isArray(value)) { + } else if (value && typeof value == 'object' && !Array.isArray(value)) { // Print all nested values print_config(value, key) } else { @@ -159,7 +159,7 @@ switch (command) { var value = parse_value(value_str) // Validate system keys - if (path[0] === 'system') { + if (path[0] == 'system') { var valid_system_keys = [ 'ar_timer', 'actor_memory', 'net_service', 'reply_timeout', 'actor_max', 'stack_max' @@ -193,7 +193,7 @@ switch (command) { switch (actor_cmd) { case 'list': - if (Object.keys(config.actors[actor_name]).length === 0) { + if (Object.keys(config.actors[actor_name]).length == 0) { log.console("No configuration for actor: " + actor_name) } else { log.console("# Configuration for actor: " + actor_name) @@ -212,7 +212,7 @@ switch (command) { var path = parse_key(key) var value = get_nested(config.actors[actor_name], path) - if (value === undefined) { + if (value == undefined) { log.error("Key not found for actor " + actor_name + ": " + key) } else { log.console('actors.' + actor_name + '.' + key + ' = ' + format_value(value)) diff --git a/scripts/doc.cm b/scripts/doc.cm index 8bc139f9..505754d6 100644 --- a/scripts/doc.cm +++ b/scripts/doc.cm @@ -5,20 +5,20 @@ function docOf(obj, prop) { // 1) If `block` is a string, that's the entire doc for `obj`. // If a sub-property is requested, we have nowhere to look → return ''. - if (typeof block === 'string') { + if (typeof block == 'string') { return prop ? '' : block; } // 2) Otherwise, if `block` is an object: // (a) With no `prop`, return block.doc or block[cell.DOC]. // (b) If `prop` is given, look for doc specifically for that property (just one level). - if (typeof block === 'object') { + if (typeof block == 'object') { // 2a) No property → top-level doc if (!prop) { - if (typeof block.doc === 'string') { + if (typeof block.doc == 'string') { return block.doc; } - if (typeof block[cell.DOC] === 'string') { + if (typeof block[cell.DOC] == 'string') { return block[cell.DOC]; } return ''; @@ -27,14 +27,14 @@ function docOf(obj, prop) { // 2b) If a prop is requested → see if there's a doc string or object for that property var subBlock = block[prop]; if (!subBlock) return ''; - if (typeof subBlock === 'string') { + if (typeof subBlock == 'string') { return subBlock; } - if (typeof subBlock === 'object') { - if (typeof subBlock.doc === 'string') { + if (typeof subBlock == 'object') { + if (typeof subBlock.doc == 'string') { return subBlock.doc; } - if (typeof subBlock[cell.DOC] === 'string') { + if (typeof subBlock[cell.DOC] == 'string') { return subBlock[cell.DOC]; } return ''; @@ -94,7 +94,7 @@ function parseDocStr(docStr) { if (returnLines.length) { // If there were param lines, ensure blank line before the returns - if (paramLines.length && returnLines[0] !== '') { + if (paramLines.length && returnLines[0] != '') { final.push(''); } final.push.apply(final, returnLines); @@ -131,14 +131,14 @@ function walkObject(obj, lines, level, name) { var propNames = Object.getOwnPropertyNames(obj); for (var i = 0; i < propNames.length; i++) { var prop = propNames[i]; - if (prop === 'constructor') continue; + if (prop == 'constructor') continue; var desc = Object.getOwnPropertyDescriptor(obj, prop); if (!desc) continue; // Check if accessor property (getter/setter) - var hasGetter = typeof desc.get === 'function'; - var hasSetter = typeof desc.set === 'function'; + var hasGetter = typeof desc.get == 'function'; + var hasSetter = typeof desc.set == 'function'; if (hasGetter || hasSetter) { writeProperty(lines, obj, prop, desc, level); @@ -150,11 +150,11 @@ function walkObject(obj, lines, level, name) { var val = desc.value; // If it's a function, treat it like a method - if (typeof val === 'function') { + if (typeof val == 'function') { writeMethod(lines, obj, prop, val, level); } // If it's an object, just print doc for that object (no deep recursion) - else if (val && typeof val === 'object') { + else if (val && typeof val == 'object') { writeSubObject(lines, obj, prop, val, level); } // Otherwise, it's a primitive or something else @@ -192,8 +192,8 @@ function writeProperty(lines, parentObj, prop, desc, level) { var heading = '#'.repeat(level + 2) + ' ' + prop + ' accessor'; lines.push(heading + '\n'); - var hasGetter = typeof desc.get === 'function'; - var hasSetter = typeof desc.set === 'function'; + var hasGetter = typeof desc.get == 'function'; + var hasSetter = typeof desc.set == 'function'; if (hasGetter && !hasSetter) { lines.push('(read only)\n'); diff --git a/scripts/engine.cm b/scripts/engine.cm index 27345849..28141d9d 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -303,7 +303,7 @@ function deepFreeze(object) { for (var name of propNames) { var value = object[name]; - if ((value && typeof value === "object") || typeof value === "function") { + if ((value && typeof value == "object") || typeof value == "function") { deepFreeze(value); } } @@ -451,7 +451,7 @@ function handle_host(e) { break case "disconnect": peer_queue.delete(e.peer) - for (var id in peers) if (peers[id] === e.peer) delete peers[id] + for (var id in peers) if (peers[id] == e.peer) delete peers[id] log.system('portal got disconnect from ' + e.peer.address + ":" + e.peer.port) break case "receive": @@ -461,7 +461,7 @@ function handle_host(e) { data.replycc[ACTORDATA].port = e.peer.port } function populate_actor_addresses(obj) { - if (typeof obj !== 'object' || obj === null) return + if (typeof obj != 'object' || obj == null) return if (obj[ACTORDATA] && !obj[ACTORDATA].address) { obj[ACTORDATA].address = e.peer.address obj[ACTORDATA].port = e.peer.port @@ -494,7 +494,7 @@ $_.start = function start(cb, program, ...args) { if (!program) return var id = guid() - if (args.length === 1 && Array.isArray(args[0])) + if (args.length == 1 && Array.isArray(args[0])) args = args[0] var startup = { @@ -543,7 +543,7 @@ $_.delay[cell.DOC] = "used to schedule the invocation of a function..." var couplings = new Set() $_.couple = function couple(actor) { - if (actor === $_) return // can't couple to self + if (actor == $_) return // can't couple to self couplings.add(actor[ACTORDATA].id) sys_msg(actor, {kind:'couple', from: $_}) log.system(`coupled to ${actor}`) @@ -569,10 +569,10 @@ function actor_send(actor, message) { if (!is_actor(actor) && !is_actor(actor.replycc)) throw new Error(`Must send to an actor object. Attempted send to ${json.encode(actor)}`) - if (typeof message !== 'object') throw new Error('Must send an object record.') + if (typeof message != 'object') throw new Error('Must send an object record.') // message to self - if (actor[ACTORDATA].id === cell.id) { + if (actor[ACTORDATA].id == cell.id) { if (receive_fn) receive_fn(message.data) return } @@ -627,10 +627,10 @@ function send_messages() { var replies = {} globalThis.send = function send(actor, message, reply) { - if (typeof actor !== 'object') + if (typeof actor != 'object') throw new Error('Must send to an actor object. Provided: ' + actor); - if (typeof message !== 'object') + if (typeof message != 'object') throw new Error('Message must be an object') var send = {type:"user", data: message} @@ -763,7 +763,7 @@ function handle_message(msg) { Object.defineProperty(letter, HEADER, { value: msg, enumerable: false }) - Object.defineProperty(letter, ACTORDATA, { // this is so is_actor === true + Object.defineProperty(letter, ACTORDATA, { // this is so is_actor == true value: { reply: msg.reply }, enumerable: false }) diff --git a/scripts/get.ce b/scripts/get.ce index 64627d97..26db7815 100644 --- a/scripts/get.ce +++ b/scripts/get.ce @@ -19,7 +19,7 @@ var parsed = shop.parse_locator(locator) // If no version specified, append @head if (!parsed) { - if (locator.indexOf('@') === -1) { + if (locator.indexOf('@') == -1) { locator = locator + '@head' parsed = shop.parse_locator(locator) } diff --git a/scripts/jswota.cm b/scripts/jswota.cm index ef082d35..347b9c2a 100644 --- a/scripts/jswota.cm +++ b/scripts/jswota.cm @@ -71,21 +71,21 @@ function encode_key(key) function encode_val(b, val) { var type = typeof val - if (type === 'number') { + if (type == 'number') { b.write_blob(FP_HEADER) b.write_number(val) - } else if (type === 'string') { + } else if (type == 'string') { b.write_fit(utf8.byte_length(val), 56) b.write_blob(TEXT) b.write_blob(utf8.encode(val)) - } else if (type === 'boolean') { + } else if (type == 'boolean') { if (val) b.write_blob(TRUE_SYMBOL) else b.write_blob(FALSE_SYMBOL) - } else if (type === 'undefined') { + } else if (type == 'undefined') { b.write_blob(NULL_SYMBOL) - } else if (type === 'object') { + } else if (type == 'object') { if (Array.isArray(val)) { b.write_fit(val.length, 56) b.write_blob(ARRAY) @@ -100,7 +100,7 @@ function encode_val(b, val) b.write_fit(keys.length, 56) b.write_blob(RECORD) for (var key of keys) { - if (typeof val[key] === 'function') continue + if (typeof val[key] == 'function') continue b.write_blob(encode_key(key)) encode_val(b, val[key]) } diff --git a/scripts/list.ce b/scripts/list.ce index 1f480e5f..649344b8 100644 --- a/scripts/list.ce +++ b/scripts/list.ce @@ -16,7 +16,7 @@ if (!config) { } // List dependencies -if (!config.dependencies || Object.keys(config.dependencies).length === 0) { +if (!config.dependencies || Object.keys(config.dependencies).length == 0) { log.console("No modules installed") return } diff --git a/scripts/mod.ce b/scripts/mod.ce index 844dda63..7b813da7 100644 --- a/scripts/mod.ce +++ b/scripts/mod.ce @@ -60,7 +60,7 @@ uses.download = function() } else if (!io.exists(cache_path)) { log.console(`${mod}: cache missing, will download`) need_download = true - } else if (remote_commit && (!lock.modules[mod].commit || lock.modules[mod].commit !== remote_commit)) { + } else if (remote_commit && (!lock.modules[mod].commit || lock.modules[mod].commit != remote_commit)) { log.console(`${mod}: remote has new commit`) log.console(` local: ${lock.modules[mod].commit || 'unknown'}`) log.console(` remote: ${remote_commit}`) @@ -74,7 +74,7 @@ uses.download = function() var hash = crypto.hash(zip) var hash_b32 = text(hash, "t") - if (hash_b32 !== lock.modules[mod].hash) { + if (hash_b32 != lock.modules[mod].hash) { log.console(`${mod}: hash mismatch, will redownload`) log.console(` expected: ${lock.modules[mod].hash}`) log.console(` actual: ${hash_b32}`) @@ -136,7 +136,7 @@ uses.download = function() // Strip the module name prefix if present var prefix = mod + '/' - if (filename.indexOf(prefix) === 0) + if (filename.indexOf(prefix) == 0) filename = filename.substring(prefix.length) // Skip if filename is empty after stripping diff --git a/scripts/module_resolver.cm b/scripts/module_resolver.cm index 856c4483..9161ccff 100644 --- a/scripts/module_resolver.cm +++ b/scripts/module_resolver.cm @@ -38,9 +38,9 @@ function resolve_relative(base, relative) { for (var i = 0; i < rel_parts.length; i++) { var part = rel_parts[i] - if (part === '.') { + if (part == '.') { continue - } else if (part === '..') { + } else if (part == '..') { parts.pop() } else { parts.push(part) @@ -82,7 +82,7 @@ ModuleResolver.check_alias = function(request) { } // Check for single-alias fallback - if (config.dependencies && Object.keys(config.dependencies).length === 1) { + if (config.dependencies && Object.keys(config.dependencies).length == 1) { // If only one dependency and no local file matches, route there var only_dep = Object.keys(config.dependencies)[0] return '/' + only_dep + '/' + request diff --git a/scripts/parseq.cm b/scripts/parseq.cm index 3560e147..b5485228 100644 --- a/scripts/parseq.cm +++ b/scripts/parseq.cm @@ -25,7 +25,7 @@ function make_reason (factory, excuse, evidence) { } function is_requestor (fn) { - return typeof fn === 'function' && (fn.length === 1 || fn.length === 2) + return typeof fn == 'function' && (fn.length == 1 || fn.length == 2) } function check_requestors (list, factory) { @@ -34,13 +34,13 @@ function check_requestors (list, factory) { } function check_callback (cb, factory) { - if (typeof cb !== 'function' || cb.length !== 2) + if (typeof cb != 'function' || cb.length != 2) throw make_reason(factory, 'Not a callback.', cb) } function schedule (fn, seconds) { - if (seconds === undefined || seconds <= 0) return fn() - if (typeof delay === 'function') return delay(fn, seconds) + if (seconds == undefined || seconds <= 0) return fn() + if (typeof delay == 'function') return delay(fn, seconds) throw make_reason('schedule', '@.delay capability required for timeouts.') } @@ -54,7 +54,7 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) { function cancel (reason = make_reason(factory, 'Cancel.')) { if (timer_cancel) timer_cancel(), timer_cancel = undefined if (!cancel_list) return - cancel_list.forEach(c => { try { if (typeof c === 'function') c(reason) } catch (_) {} }) + cancel_list.forEach(c => { try { if (typeof c == 'function') c(reason) } catch (_) {} }) cancel_list = undefined } @@ -65,23 +65,23 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) { try { cancel_list[idx] = req(function req_cb (val, reason) { - if (!cancel_list || idx === undefined) return + if (!cancel_list || idx == undefined) return cancel_list[idx] = undefined action(val, reason, idx) idx = undefined - if (factory === 'sequence') start_requestor(val) + if (factory == 'sequence') start_requestor(val) else if (throttle) start_requestor(initial) }, value) } catch (ex) { action(undefined, ex, idx) idx = undefined - if (factory === 'sequence') start_requestor(value) + if (factory == 'sequence') start_requestor(value) else if (throttle) start_requestor(initial) } } - if (time_limit !== undefined) { - if (typeof time_limit !== 'number' || time_limit < 0) + if (time_limit != undefined) { + if (typeof time_limit != 'number' || time_limit < 0) throw make_reason(factory, 'Bad time limit.', time_limit) if (time_limit > 0) timer_cancel = schedule(() => cancel(make_reason(factory, 'Timeout.', time_limit)), time_limit) } @@ -96,7 +96,7 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) { function _normalize (collection, factory) { if (Array.isArray(collection)) return { names: null, list: collection } - if (collection && typeof collection === 'object') { + if (collection && typeof collection == 'object') { const names = Object.keys(collection) const list = names.map(k => collection[k]).filter(is_requestor) return { names, list } @@ -114,7 +114,7 @@ function _denormalize (names, list) { function par_all (collection, time_limit, throttle) { const factory = 'par_all' const { names, list } = _normalize(collection, factory) - if (list.length === 0) return (cb, v) => cb(names ? {} : []) + if (list.length == 0) return (cb, v) => cb(names ? {} : []) check_requestors(list, factory) return function par_all_req (cb, initial) { @@ -123,12 +123,12 @@ function par_all (collection, time_limit, throttle) { const results = new Array(list.length) const cancel = run(factory, list, initial, (val, reason, idx) => { - if (val === undefined) { + if (val == undefined) { cancel(reason) return cb(undefined, reason) } results[idx] = val - if (--pending === 0) cb(_denormalize(names, results)) + if (--pending == 0) cb(_denormalize(names, results)) }, time_limit, throttle) return cancel @@ -138,7 +138,7 @@ function par_all (collection, time_limit, throttle) { function par_any (collection, time_limit, throttle) { const factory = 'par_any' const { names, list } = _normalize(collection, factory) - if (list.length === 0) return (cb, v) => cb(names ? {} : []) + if (list.length == 0) return (cb, v) => cb(names ? {} : []) check_requestors(list, factory) return function par_any_req (cb, initial) { @@ -148,10 +148,10 @@ function par_any (collection, time_limit, throttle) { const cancel = run(factory, list, initial, (val, reason, idx) => { pending-- - if (val !== undefined) successes[idx] = val - if (successes.some(v => v !== undefined)) { + if (val != undefined) successes[idx] = val + if (successes.some(v => v != undefined)) { if (!pending) cancel(make_reason(factory, 'Finished.')) - return cb(_denormalize(names, successes.filter(v => v !== undefined))) + return cb(_denormalize(names, successes.filter(v => v != undefined))) } if (!pending) cb(undefined, make_reason(factory, 'No successes.')) }, time_limit, throttle) @@ -161,8 +161,8 @@ function par_any (collection, time_limit, throttle) { } function race (list, time_limit, throttle) { - const factory = throttle === 1 ? 'fallback' : 'race' - if (!Array.isArray(list) || list.length === 0) + const factory = throttle == 1 ? 'fallback' : 'race' + if (!Array.isArray(list) || list.length == 0) throw make_reason(factory, 'No requestors.') check_requestors(list, factory) @@ -171,11 +171,11 @@ function race (list, time_limit, throttle) { let done = false const cancel = run(factory, list, initial, (val, reason, idx) => { if (done) return - if (val !== undefined) { + if (val != undefined) { done = true cancel(make_reason(factory, 'Loser.', idx)) cb(val) - } else if (--list.length === 0) { + } else if (--list.length == 0) { done = true cancel(reason) cb(undefined, reason) @@ -193,7 +193,7 @@ function sequence (list, time_limit) { const factory = 'sequence' if (!Array.isArray(list)) throw make_reason(factory, 'Not an array.', list) check_requestors(list, factory) - if (list.length === 0) return (cb, v) => cb(v) + if (list.length == 0) return (cb, v) => cb(v) return function sequence_req (cb, initial) { check_callback(cb, factory) @@ -203,7 +203,7 @@ function sequence (list, time_limit) { if (idx >= list.length) return cb(value) try { list[idx++](function seq_cb (val, reason) { - if (val === undefined) return cb(undefined, reason) + if (val == undefined) return cb(undefined, reason) next(val) }, value) } catch (ex) { diff --git a/scripts/shop.cm b/scripts/shop.cm index f87606ca..671d0347 100644 --- a/scripts/shop.cm +++ b/scripts/shop.cm @@ -50,7 +50,7 @@ Shop.init = function() { // Parse module locator (e.g., "git.world/jj/mod@v0.6.3") Shop.parse_locator = function(locator) { var parts = locator.split('@') - if (parts.length !== 2) { + if (parts.length != 2) { return null } diff --git a/scripts/test.ce b/scripts/test.ce index 5ba03a4e..29541a49 100644 --- a/scripts/test.ce +++ b/scripts/test.ce @@ -2,7 +2,7 @@ var def = arg -if (arg.length === 0) +if (arg.length == 0) arg = [ 'send', 'stop', diff --git a/scripts/text.cm b/scripts/text.cm index 633d3626..90897ac6 100644 --- a/scripts/text.cm +++ b/scripts/text.cm @@ -17,7 +17,7 @@ function to_radix(num, radix) { var negative = n < 0; n = Math.abs(n); - if (n === 0) return "0"; + if (n == 0) return "0"; while (n > 0) { result = digits[n % radix] + result; @@ -29,9 +29,9 @@ function to_radix(num, radix) { // Insert separator every n digits from right function add_separator(str, sep, n) { - if (!n || n === 0) return str; + if (!n || n == 0) return str; - var negative = str[0] === '-'; + var negative = str[0] == '-'; if (negative) str = str.substring(1); var parts = str.split('.'); @@ -41,7 +41,7 @@ function add_separator(str, sep, n) { // Add separators to integer part var result = ""; for (var i = integer.length - 1, count = 0; i >= 0; i--) { - if (count === n && i !== integer.length - 1) { + if (count == n && i != integer.length - 1) { result = sep + result; count = 0; } @@ -55,14 +55,14 @@ function add_separator(str, sep, n) { // Format number with separator from left function add_separator_left(str, sep, n) { - if (!n || n === 0) return str; + if (!n || n == 0) return str; - var negative = str[0] === '-'; + var negative = str[0] == '-'; if (negative) str = str.substring(1); var result = ""; for (var i = 0, count = 0; i < str.length; i++) { - if (count === n && i !== 0) { + if (count == n && i != 0) { result += sep; count = 0; } @@ -87,7 +87,7 @@ function text() { var bit_length = arg.length; var result = ""; - if (typeof format === 'string') { + if (typeof format == 'string') { // Extract style from format var style = ''; for (var i = 0; i < format.length; i++) { @@ -120,7 +120,7 @@ function text() { value = (value << 1) | (bit ? 1 : 0); bits++; - if (bits === 3) { + if (bits == 3) { result += value.toString(); bits = 0; value = 0; @@ -150,13 +150,13 @@ function text() { var all_codepoints = true; for (var i = 0; i < arg.length; i++) { var item = arg[i]; - if (!(typeof item === 'number' && item >= 0 && item <= 0x10FFFF && item === Math.floor(item))) { + if (!(typeof item == 'number' && item >= 0 && item <= 0x10FFFF && item == Math.floor(item))) { all_codepoints = false; break; } } - if (all_codepoints && separator === "") { + if (all_codepoints && separator == "") { // Use utf8 module to convert codepoints to string return utf8.from_codepoints(arg); } else { @@ -166,7 +166,7 @@ function text() { if (i > 0) result += separator; var item = arg[i]; - if (typeof item === 'number' && item >= 0 && item <= 0x10FFFF && item === Math.floor(item)) { + if (typeof item == 'number' && item >= 0 && item <= 0x10FFFF && item == Math.floor(item)) { // Single codepoint - use utf8 module result += utf8.from_codepoints([item]); } else { @@ -178,16 +178,16 @@ function text() { } // Handle number conversion - if (typeof arg === 'number') { + if (typeof arg == 'number') { var format = arguments[1]; // Simple radix conversion - if (typeof format === 'number') { + if (typeof format == 'number') { return to_radix(arg, format); } // Format string conversion - if (typeof format === 'string') { + if (typeof format == 'string') { return format_number(arg, format); } @@ -196,13 +196,13 @@ function text() { } // Handle text operations - if (typeof arg === 'string') { - if (arguments.length === 1) return arg; + if (typeof arg == 'string') { + if (arguments.length == 1) return arg; var from = arguments[1]; var to = arguments[2]; - if (typeof from !== 'number' || typeof to !== 'number') return arg; + if (typeof from != 'number' || typeof to != 'number') return arg; var len = arg.length; @@ -211,8 +211,8 @@ function text() { if (to < 0) to += len; // Default values - if (from === undefined) from = 0; - if (to === undefined) to = len; + if (from == undefined) from = 0; + if (to == undefined) to = len; // Validate range if (from < 0 || from > to || to > len) return null; @@ -261,8 +261,8 @@ function format_number(num, format) { if (i < format.length) return null; // Real number styles - if (style === 'e' || style === 'n' || style === 's' || - style === 'u' || style === 'd' || style === 'v' || style === 'l') { + if (style == 'e' || style == 'n' || style == 's' || + style == 'u' || style == 'd' || style == 'v' || style == 'l') { var decimal_point = '.'; var separator = ''; @@ -314,15 +314,15 @@ function format_number(num, format) { break; } - if (separation === 0) separation = default_separation; - if (places === 0 && style !== 'e' && style !== 'n') places = default_places; + if (separation == 0) separation = default_separation; + if (places == 0 && style != 'e' && style != 'n') places = default_places; // Format the number - if (style === 'e') { + if (style == 'e') { // Scientific notation var str = places > 0 ? num.toExponential(places) : num.toExponential(); return str; - } else if (style === 'n' && (Math.abs(num) >= 1e21 || (Math.abs(num) < 1e-6 && num !== 0))) { + } else if (style == 'n' && (Math.abs(num) >= 1e21 || (Math.abs(num) < 1e-6 && num != 0))) { // Use scientific notation for extreme values return num.toExponential(); } else { @@ -335,7 +335,7 @@ function format_number(num, format) { } // Replace decimal point if needed - if (decimal_point !== '.') { + if (decimal_point != '.') { str = str.replace('.', decimal_point); } @@ -349,8 +349,8 @@ function format_number(num, format) { } // Integer styles - if (style === 'i' || style === 'b' || style === 'o' || - style === 'h' || style === 't') { + if (style == 'i' || style == 'b' || style == 'o' || + style == 'h' || style == 't') { var radix = 10; var default_separation = 0; @@ -384,15 +384,15 @@ function format_number(num, format) { break; } - if (separation === 0) separation = default_separation; - if (places === 0) places = default_places; + if (separation == 0) separation = default_separation; + if (places == 0) places = default_places; // Convert to integer var n = Math.trunc(num); var str = to_radix(n, radix).toUpperCase(); // Pad with zeros if needed - var negative = str[0] === '-'; + var negative = str[0] == '-'; if (negative) str = str.substring(1); while (str.length < places) { diff --git a/scripts/time.cm b/scripts/time.cm index 3c152227..fed678b1 100644 --- a/scripts/time.cm +++ b/scripts/time.cm @@ -41,10 +41,10 @@ time.week2day = function() { return time.week / time.day; }; /* leap-year helpers */ time.yearsize = function yearsize(y) { - if (y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)) return 366; + if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) return 366; return 365; }; -time.isleap = function(y) { return time.yearsize(y) === 366; }; +time.isleap = function(y) { return time.yearsize(y) == 366; }; /* timecode utility */ time.timecode = function(t, fps = 24) @@ -64,7 +64,7 @@ function record(num = now(), dst = computer_dst()) { /* caller passed an existing record → return it verbatim */ - if (typeof num === "object") return num; + if (typeof num == "object") return num; /* -------------------------------------------------------------------- */ /* convert seconds-since-epoch → broken-down record */ @@ -107,7 +107,7 @@ function record(num = now(), rec.yday = day; /* month & month-day */ - if (time.yearsize(y) === 366) monthdays[1] = 29; + if (time.yearsize(y) == 366) monthdays[1] = 29; var m = 0; for (; day >= monthdays[m]; m++) day -= monthdays[m]; rec.month = m; @@ -119,7 +119,7 @@ function record(num = now(), function number(rec = now()) { /* fall through for numeric input or implicit “now” */ - if (typeof rec === "number") return rec; + if (typeof rec == "number") return rec; /* -------------------------------------------------------------------- */ /* record → seconds-since-epoch */ @@ -165,15 +165,15 @@ function text(num = now(), zone = computer_zone(), dst = computer_dst()) { - var rec = (typeof num === "number") ? record(num, zone, dst) : num; + var rec = (typeof num == "number") ? record(num, zone, dst) : num; zone = rec.zone; dst = rec.dst; /* am/pm */ if (fmt.includes("a")) { if (rec.hour >= 13) { rec.hour -= 12; fmt = fmt.replaceAll("a", "PM"); } - else if (rec.hour === 12) { fmt = fmt.replaceAll("a", "PM"); } - else if (rec.hour === 0) { rec.hour = 12; fmt = fmt.replaceAll("a", "AM"); } + else if (rec.hour == 12) { fmt = fmt.replaceAll("a", "PM"); } + else if (rec.hour == 0) { rec.hour = 12; fmt = fmt.replaceAll("a", "AM"); } else fmt = fmt.replaceAll("a", "AM"); } diff --git a/scripts/toml.cm b/scripts/toml.cm index 9ccb7442..300c1806 100644 --- a/scripts/toml.cm +++ b/scripts/toml.cm @@ -42,9 +42,9 @@ function parse_toml(text) { } else if (value.startsWith('[') && value.endsWith(']')) { // Array current_section[key] = parse_array(value) - } else if (value === 'true' || value === 'false') { + } else if (value == 'true' || value == 'false') { // Boolean - current_section[key] = value === 'true' + current_section[key] = value == 'true' } else if (!isNaN(Number(value))) { // Number current_section[key] = Number(value) @@ -70,10 +70,10 @@ function parse_array(str) { for (var i = 0; i < str.length; i++) { var char = str[i] - if (char === '"' && (i === 0 || str[i-1] !== '\\')) { + if (char == '"' && (i == 0 || str[i-1] != '\\')) { in_quotes = !in_quotes current += char - } else if (char === ',' && !in_quotes) { + } else if (char == ',' && !in_quotes) { items.push(parse_value(current.trim())) current = '' } else { @@ -91,8 +91,8 @@ function parse_array(str) { function parse_value(str) { if (str.startsWith('"') && str.endsWith('"')) { return str.slice(1, -1).replace(/\\"/g, '"') - } else if (str === 'true' || str === 'false') { - return str === 'true' + } else if (str == 'true' || str == 'false') { + return str == 'true' } else if (!isNaN(Number(str))) { return Number(str) } else { @@ -104,11 +104,11 @@ function encode_toml(obj) { var result = [] function encode_value(value) { - if (typeof value === 'string') { + if (typeof value == 'string') { return '"' + value.replace(/"/g, '\\"') + '"' - } else if (typeof value === 'boolean') { + } else if (typeof value == 'boolean') { return value ? 'true' : 'false' - } else if (typeof value === 'number') { + } else if (typeof value == 'number') { return String(value) } else if (Array.isArray(value)) { var items = [] @@ -125,7 +125,7 @@ function encode_toml(obj) { for (var i = 0; i < keys.length; i++) { var key = keys[i] var value = obj[key] - if (value === null || typeof value !== 'object' || Array.isArray(value)) { + if (value == null || typeof value != 'object' || Array.isArray(value)) { result.push(key + ' = ' + encode_value(value)) } } @@ -138,7 +138,7 @@ function encode_toml(obj) { var key = keys[i] var value = obj[key] - if (value !== null && typeof value === 'object' && !Array.isArray(value)) { + if (value != null && typeof value == 'object' && !Array.isArray(value)) { // Nested object - create section var section_path = path ? path + '.' + key : key result.push('[' + section_path + ']') @@ -148,7 +148,7 @@ function encode_toml(obj) { for (var j = 0; j < section_keys.length; j++) { var sk = section_keys[j] var sv = value[sk] - if (sv === null || typeof sv !== 'object' || Array.isArray(sv)) { + if (sv == null || typeof sv != 'object' || Array.isArray(sv)) { result.push(sk + ' = ' + encode_value(sv)) } } diff --git a/scripts/update.ce b/scripts/update.ce index 59f1cf60..04ab860c 100644 --- a/scripts/update.ce +++ b/scripts/update.ce @@ -77,7 +77,7 @@ for (var alias in deps_to_check) { local_commit: null, remote_commit: remote_commit }) - } else if (local_commit !== remote_commit) { + } else if (local_commit != remote_commit) { log.console(" Update available!") log.console(" Local: " + local_commit.substring(0, 8)) log.console(" Remote: " + remote_commit.substring(0, 8)) @@ -95,7 +95,7 @@ for (var alias in deps_to_check) { } } -if (updates_available.length === 0) { +if (updates_available.length == 0) { log.console("\nAll dependencies are up to date!") $_.stop() return diff --git a/scripts/util.cm b/scripts/util.cm index c0673e51..a08948e3 100644 --- a/scripts/util.cm +++ b/scripts/util.cm @@ -4,7 +4,7 @@ return util util.dainty_assign = function (target, source) { Object.keys(source).forEach(function (k) { - if (typeof source[k] === "function") return + if (typeof source[k] == "function") return if (!(k in target)) return if (Array.isArray(source[k])) target[k] = deep_copy(source[k]) else if (Object.isObject(source[k])) Object.dainty_assign(target[k], source[k]) @@ -16,11 +16,11 @@ util.get = function (obj, path, defValue) { if (!path) return undefined var pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g) var result = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj) - return result === undefined ? defValue : result + return result == undefined ? defValue : result } util.isEmpty = function(o) { - return Object.keys(o).length === 0 + return Object.keys(o).length == 0 } util.dig = function (obj, path, def = {}) { @@ -43,11 +43,11 @@ util.access = function (obj, name) { util.mergekey = function (o1, o2, k) { if (!o2) return - if (typeof o2[k] === "object") { + if (typeof o2[k] == "object") { if (Array.isArray(o2[k])) o1[k] = deep_copy(o2[k]) else { if (!o1[k]) o1[k] = {} - if (typeof o1[k] === "object") util.merge(o1[k], o2[k]) + if (typeof o1[k] == "object") util.merge(o1[k], o2[k]) else o1[k] = o2[k] } } else o1[k] = o2[k] @@ -74,15 +74,15 @@ util.obj_lerp = function(a,b,t) { } util.normalizeSpacing = function normalizeSpacing(spacing) { - if (typeof spacing === 'number') { + if (typeof spacing == 'number') { return {l: spacing, r: spacing, t: spacing, b: spacing} } else if (Array.isArray(spacing)) { - if (spacing.length === 2) { + if (spacing.length == 2) { return {l: spacing[0], r: spacing[0], t: spacing[1], b: spacing[1]} - } else if (spacing.length === 4) { + } else if (spacing.length == 4) { return {l: spacing[0], r: spacing[1], t: spacing[2], b: spacing[3]} } - } else if (typeof spacing === 'object') { + } else if (typeof spacing == 'object') { return {l: spacing.l || 0, r: spacing.r || 0, t: spacing.t || 0, b: spacing.b || 0} } else { return {l:0, r:0, t:0, b:0} diff --git a/source/quickjs.c b/source/quickjs.c index d78fe3cb..4a8831ca 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -14967,6 +14967,16 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, tag1 = JS_VALUE_GET_NORM_TAG(op1); tag2 = JS_VALUE_GET_NORM_TAG(op2); + + /* throw on any mismatched non-numeric tags */ + if (tag1 != tag2 + && !((tag1 == JS_TAG_INT || tag1 == JS_TAG_FLOAT64) + && (tag2 == JS_TAG_INT || tag2 == JS_TAG_FLOAT64))) { + JS_ThrowTypeError(ctx, + "Strict equality: cannot compare two differing types"); + goto done_no_free; + } + switch(tag1) { case JS_TAG_BOOL: if (tag1 != tag2) { @@ -21768,13 +21778,8 @@ static __exception int next_token(JSParseState *s) break; case '=': if (p[1] == '=') { - if (p[2] == '=') { - p += 3; - s->token.val = TOK_STRICT_EQ; - } else { - p += 2; - s->token.val = TOK_EQ; - } + p += 2; + s->token.val = TOK_STRICT_EQ; } else if (p[1] == '>') { p += 2; s->token.val = TOK_ARROW; @@ -21784,13 +21789,8 @@ static __exception int next_token(JSParseState *s) break; case '!': if (p[1] == '=') { - if (p[2] == '=') { - p += 3; - s->token.val = TOK_STRICT_NEQ; - } else { - p += 2; - s->token.val = TOK_NEQ; - } + p += 2; + s->token.val = TOK_STRICT_NEQ; } else { goto def_token; } @@ -26424,12 +26424,6 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level, break; case 5: switch(op) { - case TOK_EQ: - opcode = OP_eq; - break; - case TOK_NEQ: - opcode = OP_neq; - break; case TOK_STRICT_EQ: opcode = OP_strict_eq; break; diff --git a/tests/blob.ce b/tests/blob.ce index f2d105c3..088c104e 100644 --- a/tests/blob.ce +++ b/tests/blob.ce @@ -2,7 +2,7 @@ var Blob = use('blob'); var os = use('os'); -log.console("=== Blob Module Test Suite ===\n"); +log.console("== Blob Module Test Suite ==\n"); var passed = 0; var failed = 0; @@ -25,7 +25,7 @@ function assert(condition, message) { } function assertEqual(actual, expected, message) { - if (actual !== expected) { + if (actual != expected) { throw new Error(message || "Expected " + expected + ", got " + actual); } } @@ -148,7 +148,7 @@ test("Blob copy constructor", function() { test("Blob partial copy constructor", function() { var b1 = new Blob(); for (var i = 0; i < 10; i++) { - b1.write_bit(i % 2 === 0); + b1.write_bit(i % 2 == 0); } stone(b1); @@ -207,7 +207,7 @@ test("Write pad and check padding", function() { test("Read blob from stone blob", function() { var b1 = new Blob(); for (var i = 0; i < 16; i++) { - b1.write_bit(i % 3 === 0); + b1.write_bit(i % 3 == 0); } stone(b1); @@ -216,8 +216,8 @@ test("Read blob from stone blob", function() { assertEqual(b2.length, 8, "Read blob should have 8 bits"); // Check the pattern - assertEqual(b2.read_logical(2), true); // Original bit 6 (6 % 3 === 0) - assertEqual(b2.read_logical(5), true); // Original bit 9 (9 % 3 === 0) + assertEqual(b2.read_logical(2), true); // Original bit 6 (6 % 3 == 0) + assertEqual(b2.read_logical(5), true); // Original bit 9 (9 % 3 == 0) }); // Test 14: Stone immutability @@ -246,7 +246,7 @@ test("Multiple stone calls are safe and stone.p works", function() { assertEqual(b.read_logical(0), true, "Blob data should remain intact"); // Verify blob.stone is not available - assert(b.stone === undefined, "blob.stone should not be available as a method"); + assert(b.stone == undefined, "blob.stone should not be available as a method"); }); // Test 16: Invalid constructor arguments @@ -311,7 +311,7 @@ test("Large blob handling", function() { // Write many bits for (var i = 0; i < testSize; i++) { - b.write_bit(i % 7 === 0); + b.write_bit(i % 7 == 0); } assertEqual(b.length, testSize, "Should have " + testSize + " bits"); @@ -405,10 +405,10 @@ test("Invalid read positions", function() { }); // Print summary -log.console("\n=== Test Summary ==="); +log.console("\n== Test Summary =="); log.console("Total tests: " + (passed + failed)); log.console("Passed: " + passed); log.console("Failed: " + failed); -log.console("\nOverall: " + (failed === 0 ? "PASSED" : "FAILED")); +log.console("\nOverall: " + (failed == 0 ? "PASSED" : "FAILED")); $_.stop() \ No newline at end of file diff --git a/tests/fit.ce b/tests/fit.ce index dd70e5df..e66bc956 100644 --- a/tests/fit.ce +++ b/tests/fit.ce @@ -6,7 +6,7 @@ var tests_failed = 0; function test(description, actual, expected) { tests_run++; - if (actual === expected) { + if (actual == expected) { tests_passed++; log.console("✓", description, "=", actual); } else { diff --git a/tests/kim.ce b/tests/kim.ce index 89aa4ca0..a5fc30c0 100644 --- a/tests/kim.ce +++ b/tests/kim.ce @@ -5,8 +5,8 @@ var blob = use('blob') var test1 = "Hello, World!"; var encoded1 = kim.encode(test1); var decoded1 = kim.decode(encoded1); -log.console("ASCII test:", test1 === decoded1 ? "PASS" : "FAIL"); -if (test1 !== decoded1) { +log.console("ASCII test:", test1 == decoded1 ? "PASS" : "FAIL"); +if (test1 != decoded1) { log.console(" Expected:", test1); log.console(" Got:", decoded1); } @@ -15,8 +15,8 @@ if (test1 !== decoded1) { var test2 = "Hello, 世界! 🌍 Привет мир"; var encoded2 = kim.encode(test2); var decoded2 = kim.decode(encoded2); -log.console("Unicode test:", test2 === decoded2 ? "PASS" : "FAIL"); -if (test2 !== decoded2) { +log.console("Unicode test:", test2 == decoded2 ? "PASS" : "FAIL"); +if (test2 != decoded2) { log.console(" Expected:", test2); log.console(" Got:", decoded2); } @@ -27,14 +27,14 @@ var encoded3 = kim.encode(test3); log.console(typeof encoded3) log.console(encoded3 instanceof blob) var decoded3 = kim.decode(encoded3); -log.console("Empty string test:", test3 === decoded3 ? "PASS" : "FAIL"); +log.console("Empty string test:", test3 == decoded3 ? "PASS" : "FAIL"); // Test various Unicode ranges var test4 = "αβγδε АБВГД 你好 😀😎🎉 ∑∏∫"; var encoded4 = kim.encode(test4); var decoded4 = kim.decode(encoded4); -log.console("Mixed Unicode test:", test4 === decoded4 ? "PASS" : "FAIL"); -if (test4 !== decoded4) { +log.console("Mixed Unicode test:", test4 == decoded4 ? "PASS" : "FAIL"); +if (test4 != decoded4) { log.console(" Expected:", test4); log.console(" Got:", decoded4); } diff --git a/tests/modules.ce b/tests/modules.ce index d9233532..b950cc35 100644 --- a/tests/modules.ce +++ b/tests/modules.ce @@ -4,7 +4,7 @@ var io = use('io') var shop = use('shop') var time = use('time') -log.console("=== Testing Module System ===") +log.console("== Testing Module System ==") // Test 1: TOML parser log.console("\n1. Testing TOML parser...") @@ -54,7 +54,7 @@ var tests = [ for (var i = 0; i < tests.length; i++) { var test = tests[i] var result = resolver.resolve(test.input) - if (result === test.expected) { + if (result == test.expected) { log.console("✓ " + test.input + " -> " + result) } else { log.console("✗ " + test.input + " -> " + result + " (expected " + test.expected + ")") @@ -71,6 +71,6 @@ io.rm(test_dir + '/.cell/modules') io.rm(test_dir + '/.cell') io.rm(test_dir) -log.console("\n=== Module System Test Complete ===") +log.console("\n== Module System Test Complete ==") $_.stop() \ No newline at end of file diff --git a/tests/nota.ce b/tests/nota.ce index dcb07c2f..eb29b06f 100644 --- a/tests/nota.ce +++ b/tests/nota.ce @@ -21,9 +21,9 @@ var EPSILON = 1e-12 // Deep comparison function for objects and arrays function deepCompare(expected, actual, path = '') { - if (expected === actual) return { passed: true, messages: [] }; + if (expected == actual) return { passed: true, messages: [] }; - if (typeof expected === 'number' && typeof actual === 'number') { + if (typeof expected == 'number' && typeof actual == 'number') { if (isNaN(expected) && isNaN(actual)) return { passed: true, messages: [] }; @@ -50,7 +50,7 @@ function deepCompare(expected, actual, path = '') { actual = Array.from(new Uint8Array(actual)); if (Array.isArray(expected) && Array.isArray(actual)) { - if (expected.length !== actual.length) + if (expected.length != actual.length) return { passed: false, messages: [`Array length mismatch at ${path}: expected ${expected.length}, got ${actual.length}`] @@ -60,14 +60,14 @@ function deepCompare(expected, actual, path = '') { const result = deepCompare(expected[i], actual[i], `${path}[${i}]`); if (!result.passed) messages.push(...result.messages); } - return { passed: messages.length === 0, messages }; + return { passed: messages.length == 0, messages }; } - if (typeof expected === 'object' && expected !== null && - typeof actual === 'object' && actual !== null) { + if (typeof expected == 'object' && expected != null && + typeof actual == 'object' && actual != null) { const expKeys = Object.keys(expected).sort(); const actKeys = Object.keys(actual).sort(); - if (JSON.stringify(expKeys) !== JSON.stringify(actKeys)) + if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) return { passed: false, messages: [`Object keys mismatch at ${path}: expected ${expKeys}, got ${actKeys}`] @@ -77,7 +77,7 @@ function deepCompare(expected, actual, path = '') { const result = deepCompare(expected[key], actual[key], `${path}.${key}`); if (!result.passed) messages.push(...result.messages); } - return { passed: messages.length === 0, messages }; + return { passed: messages.length == 0, messages }; } return { @@ -170,23 +170,23 @@ var testCases = [ // Replacer tests { input: { a: 1, b: 2 }, - replacer: (key, value) => typeof value === 'number' ? value * 2 : value, + replacer: (key, value) => typeof value == 'number' ? value * 2 : value, expected: { a: 2, b: 4 }, testType: 'replacer' }, { input: { x: "test", y: 5 }, - replacer: (key, value) => key === 'x' ? value + "!" : value, + replacer: (key, value) => key == 'x' ? value + "!" : value, expected: { x: "test!", y: 5 }, testType: 'replacer' }, // Reviver tests { input: { a: 1, b: 2 }, - reviver: (key, value) => typeof value === 'number' ? value * 3 : value, + reviver: (key, value) => typeof value == 'number' ? value * 3 : value, expected: { a: 3, b: 6 }, testType: 'reviver' }, { input: { x: "test", y: 10 }, - reviver: (key, value) => key === 'y' ? value + 1 : value, + reviver: (key, value) => key == 'y' ? value + 1 : value, expected: { x: "test", y: 11 }, testType: 'reviver' } ]; @@ -209,7 +209,7 @@ for (let test of testCases) { } else { if (test.expectedHex) { let encodedHex = bufferToHex(encoded); - if (encodedHex !== test.expectedHex.toLowerCase()) { + if (encodedHex != test.expectedHex.toLowerCase()) { messages.push( `Hex encoding differs (informational): Expected: ${test.expectedHex} diff --git a/tests/overling.ce b/tests/overling.ce index cacf102e..e0f50b97 100644 --- a/tests/overling.ce +++ b/tests/overling.ce @@ -67,7 +67,7 @@ var tests = [ for (var i = 0; i < targetCount; i++) { $_.start(function(greet) { underlingCount++; - if (underlingCount === targetCount) { + if (underlingCount == targetCount) { done({ passed: true, messages: [] @@ -137,7 +137,7 @@ var tests = [ // Message receiver $_.receiver(function(msg) { - if (msg.type === 'run_tests') { + if (msg.type == 'run_tests') { startTime = time.number(); var testsCompleted = 0; diff --git a/tests/portal.ce b/tests/portal.ce index fc2487cf..4ae999a1 100644 --- a/tests/portal.ce +++ b/tests/portal.ce @@ -3,7 +3,7 @@ var password = "abc123" $_.portal(e => { - if (e.password !== password) + if (e.password != password) send(e, {reason:"Password does not match."}); else send(e, $_) diff --git a/tests/qr_drag.ce b/tests/qr_drag.ce index e3d6693d..b121bd53 100644 --- a/tests/qr_drag.ce +++ b/tests/qr_drag.ce @@ -129,7 +129,7 @@ function extract_qr_surface(surface) var display = undefined $_.receiver(e => { - if (e.type === 'quit') + if (e.type == 'quit') os.exit() switch(e.type) { diff --git a/tests/test_actor_access.ce b/tests/test_actor_access.ce index 7a51bb33..92db5efb 100644 --- a/tests/test_actor_access.ce +++ b/tests/test_actor_access.ce @@ -2,7 +2,7 @@ log.console("Testing actor access to $_:"); // In an actor script, $_ should be available -if (typeof $_ !== 'undefined') { +if (typeof $_ != 'undefined') { log.console("✓ Actor has access to $_"); log.console(" $_.random is a", typeof $_.random); log.console(" $_.clock is a", typeof $_.clock); diff --git a/tests/test_child_actor.ce b/tests/test_child_actor.ce index c91e93bd..f309ff0e 100644 --- a/tests/test_child_actor.ce +++ b/tests/test_child_actor.ce @@ -1,7 +1,7 @@ // Child actor test log.console("Child actor spawned"); -if (typeof $_ !== 'undefined') { +if (typeof $_ != 'undefined') { log.console("✓ Child actor has access to $_"); } else { log.error("✗ Child actor does NOT have access to $_"); diff --git a/tests/test_module.ce b/tests/test_module.ce index e17e275f..62958de7 100644 --- a/tests/test_module.ce +++ b/tests/test_module.ce @@ -1,7 +1,7 @@ // Test module - should NOT have access to $_ function test() { - if (typeof $_ !== 'undefined') { + if (typeof $_ != 'undefined') { log.error("✗ Module incorrectly has access to $_!"); return "ERROR: Module has $_ access"; } else { diff --git a/tests/test_use_args.ce b/tests/test_use_args.ce index 8615fe76..894ab8e8 100644 --- a/tests/test_use_args.ce +++ b/tests/test_use_args.ce @@ -15,4 +15,4 @@ log.console("Module 2 all args:", module2.allArgs()); // Test 3: Verify modules are cached (should return same as module1) var module3 = use('test_args'); log.console("Module 3 (cached) message:", module3.message); -log.console("Are module1 and module3 the same?", module1 === module3); \ No newline at end of file +log.console("Are module1 and module3 the same?", module1 == module3); \ No newline at end of file diff --git a/tests/text.ce b/tests/text.ce index d998b70f..b6114b6c 100644 --- a/tests/text.ce +++ b/tests/text.ce @@ -4,14 +4,14 @@ log.console("Testing text module...") log.console("") // Test array to text conversion -log.console("=== Testing array to text conversion ===") +log.console("== Testing array to text conversion ==") // Basic array concatenation var arr1 = ["Hello", " ", "World"] var result1 = text(arr1) log.console("text(['Hello', ' ', 'World']) = '" + result1 + "'") log.console("Expected: 'Hello World'") -log.console("Passed: " + (result1 === "Hello World")) +log.console("Passed: " + (result1 == "Hello World")) log.console("") // Array with separator @@ -19,7 +19,7 @@ var arr2 = ["one", "two", "three"] var result2 = text(arr2, ", ") log.console("text(['one', 'two', 'three'], ', ') = '" + result2 + "'") log.console("Expected: 'one, two, three'") -log.console("Passed: " + (result2 === "one, two, three")) +log.console("Passed: " + (result2 == "one, two, three")) log.console("") // Unicode codepoints @@ -27,7 +27,7 @@ var arr3 = [72, 101, 108, 108, 111] var result3 = text(arr3) log.console("text([72, 101, 108, 108, 111]) = '" + result3 + "'") log.console("Expected: 'Hello'") -log.console("Passed: " + (result3 === "Hello")) +log.console("Passed: " + (result3 == "Hello")) log.console("") // Mixed array with text and codepoints @@ -35,11 +35,11 @@ var arr4 = ["Hi", 32, "there", 33] var result4 = text(arr4) log.console("text(['Hi', 32, 'there', 33]) = '" + result4 + "'") log.console("Expected: 'Hi there!'") -log.console("Passed: " + (result4 === "Hi there!")) +log.console("Passed: " + (result4 == "Hi there!")) log.console("") // Test number to text conversion with radix -log.console("=== Testing number to text with radix ===") +log.console("== Testing number to text with radix ==") var tests_radix = [ {num: 12, radix: 10, expected: "12"}, @@ -57,12 +57,12 @@ for (var i = 0; i < tests_radix.length; i++) { var result = text(test.num, test.radix) log.console("text(" + test.num + ", " + test.radix + ") = '" + result + "'") log.console("Expected: '" + test.expected + "'") - log.console("Passed: " + (result === test.expected)) + log.console("Passed: " + (result == test.expected)) } log.console("") // Test formatted number conversion -log.console("=== Testing formatted number conversion ===") +log.console("== Testing formatted number conversion ==") var num = 123456789.1 var format_tests = [ @@ -85,12 +85,12 @@ for (var i = 0; i < format_tests.length; i++) { var result = text(num, test.fmt) log.console("text(" + num + ", '" + test.fmt + "') = '" + result + "'") log.console("Expected: '" + test.expected + "'") - log.console("Passed: " + (result === test.expected)) + log.console("Passed: " + (result == test.expected)) } log.console("") // Test integer formatting -log.console("=== Testing integer formatting ===") +log.console("== Testing integer formatting ==") var int_tests = [ {num: 12, fmt: "4b8", expected: "0000_1100"}, @@ -106,12 +106,12 @@ for (var i = 0; i < int_tests.length; i++) { var result = text(test.num, test.fmt) log.console("text(" + test.num + ", '" + test.fmt + "') = '" + result + "'") log.console("Expected: '" + test.expected + "'") - log.console("Passed: " + (result === test.expected)) + log.console("Passed: " + (result == test.expected)) } log.console("") // Test text substring operations -log.console("=== Testing text substring operations ===") +log.console("== Testing text substring operations ==") var str = "miskatonic" var substr_tests = [ @@ -128,36 +128,36 @@ var substr_tests = [ for (var i = 0; i < substr_tests.length; i++) { var test = substr_tests[i] - var result = test.to === undefined ? text(str, test.from) : text(str, test.from, test.to) - var args = test.to === undefined ? test.from : test.from + ", " + test.to - log.console("text('" + str + "', " + args + ") = " + (result === null ? "null" : "'" + result + "'")) - log.console("Expected: " + (test.expected === null ? "null" : "'" + test.expected + "'")) - log.console("Passed: " + (result === test.expected)) + var result = test.to == undefined ? text(str, test.from) : text(str, test.from, test.to) + var args = test.to == undefined ? test.from : test.from + ", " + test.to + log.console("text('" + str + "', " + args + ") = " + (result == null ? "null" : "'" + result + "'")) + log.console("Expected: " + (test.expected == null ? "null" : "'" + test.expected + "'")) + log.console("Passed: " + (result == test.expected)) } log.console("") // Test edge cases -log.console("=== Testing edge cases ===") +log.console("== Testing edge cases ==") // Empty array var empty_result = text([]) log.console("text([]) = '" + empty_result + "'") -log.console("Passed: " + (empty_result === "")) +log.console("Passed: " + (empty_result == "")) // Single element array var single_result = text([42]) log.console("text([42]) = '" + single_result + "'") -log.console("Passed: " + (single_result === "42")) +log.console("Passed: " + (single_result == "42")) // Text identity var text_result = text("hello") log.console("text('hello') = '" + text_result + "'") -log.console("Passed: " + (text_result === "hello")) +log.console("Passed: " + (text_result == "hello")) // Invalid format var invalid_result = text(123, "xyz") log.console("text(123, 'xyz') = " + invalid_result) -log.console("Passed: " + (invalid_result === null)) +log.console("Passed: " + (invalid_result == null)) // Very small numbers with 'n' format var tiny = 0.0000001 @@ -174,7 +174,7 @@ log.console("Should use scientific notation: " + (huge_result.indexOf('e') > -1) log.console("") // Summary -log.console("=== Test Summary ===") +log.console("== Test Summary ==") log.console("All major test categories completed.") log.console("The text module provides:") log.console("- Array to text conversion with Unicode support") diff --git a/tests/text_utf8.ce b/tests/text_utf8.ce index 42f0b128..f18c57a3 100644 --- a/tests/text_utf8.ce +++ b/tests/text_utf8.ce @@ -10,14 +10,14 @@ var decoded_text = text(encoded_blob); log.console("Blob to text test:"); log.console(" Original:", test_string); log.console(" Decoded:", decoded_text); -log.console(" Match:", test_string === decoded_text ? "PASS" : "FAIL"); +log.console(" Match:", test_string == decoded_text ? "PASS" : "FAIL"); // Test array of codepoints conversion var codepoints = [72, 101, 108, 108, 111, 44, 32, 19990, 30028, 33, 32, 127757]; var from_codepoints = text(codepoints); log.console("\nCodepoints to text test:"); log.console(" From codepoints:", from_codepoints); -log.console(" Match:", from_codepoints === test_string ? "PASS" : "FAIL"); +log.console(" Match:", from_codepoints == test_string ? "PASS" : "FAIL"); // Test array with separator var words = ["Hello", "world", "from", "text"]; @@ -25,7 +25,7 @@ var joined = text(words, " "); log.console("\nArray with separator test:"); log.console(" Joined:", joined); log.console(" Expected: Hello world from text"); -log.console(" Match:", joined === "Hello world from text" ? "PASS" : "FAIL"); +log.console(" Match:", joined == "Hello world from text" ? "PASS" : "FAIL"); // Test mixed array with codepoints var mixed = [72, "ello", 32, "world"]; @@ -33,7 +33,7 @@ var mixed_result = text(mixed, ""); log.console("\nMixed array test:"); log.console(" Result:", mixed_result); log.console(" Expected: Hello world"); -log.console(" Match:", mixed_result === "Hello world" ? "PASS" : "FAIL"); +log.console(" Match:", mixed_result == "Hello world" ? "PASS" : "FAIL"); // Test blob encoding formats still work var test_data = utf8.encode("ABC"); diff --git a/tests/toml.ce b/tests/toml.ce index 5664c030..d2a67b63 100644 --- a/tests/toml.ce +++ b/tests/toml.ce @@ -82,14 +82,14 @@ log.console("") // Verify round-trip conversion log.console("Verifying round-trip conversion...") function deep_equal(a, b) { - if (a === b) return true + if (a == b) return true if (a == null || b == null) return false - if (typeof a !== typeof b) return false + if (typeof a != typeof b) return false - if (typeof a === 'object') { + if (typeof a == 'object') { var keys_a = Object.keys(a) var keys_b = Object.keys(b) - if (keys_a.length !== keys_b.length) return false + if (keys_a.length != keys_b.length) return false for (var i = 0; i < keys_a.length; i++) { if (!deep_equal(a[keys_a[i]], b[keys_a[i]])) return false diff --git a/tests/utf8.ce b/tests/utf8.ce index 41a2bd4a..4d8093b0 100644 --- a/tests/utf8.ce +++ b/tests/utf8.ce @@ -5,7 +5,7 @@ var test1 = "Hello"; log.console("ASCII length test:"); log.console(" Characters:", utf8.length(test1)); log.console(" Bytes:", utf8.byte_length(test1)); -log.console(" Match:", utf8.length(test1) === utf8.byte_length(test1) ? "PASS" : "FAIL"); +log.console(" Match:", utf8.length(test1) == utf8.byte_length(test1) ? "PASS" : "FAIL"); var test2 = "Hello 世界"; log.console("\nMixed ASCII/Unicode length test:"); @@ -19,14 +19,14 @@ var codepoints = utf8.codepoints(test3); log.console("\nCodepoints test:"); log.console(" String:", test3); log.console(" Codepoints:", codepoints); -log.console(" A=65:", codepoints[0] === 65 ? "PASS" : "FAIL"); -log.console(" 😀=128512:", codepoints[1] === 128512 ? "PASS" : "FAIL"); -log.console(" B=66:", codepoints[2] === 66 ? "PASS" : "FAIL"); +log.console(" A=65:", codepoints[0] == 65 ? "PASS" : "FAIL"); +log.console(" 😀=128512:", codepoints[1] == 128512 ? "PASS" : "FAIL"); +log.console(" B=66:", codepoints[2] == 66 ? "PASS" : "FAIL"); // Test from_codepoints var reconstructed = utf8.from_codepoints(codepoints); log.console(" Reconstructed:", reconstructed); -log.console(" Match:", test3 === reconstructed ? "PASS" : "FAIL"); +log.console(" Match:", test3 == reconstructed ? "PASS" : "FAIL"); // Test encode/decode var test4 = "UTF-8 encoding: 你好世界 🌍"; @@ -35,7 +35,7 @@ var decoded = utf8.decode(encoded); log.console("\nEncode/decode test:"); log.console(" Original:", test4); log.console(" Decoded:", decoded); -log.console(" Match:", test4 === decoded ? "PASS" : "FAIL"); +log.console(" Match:", test4 == decoded ? "PASS" : "FAIL"); // Test validation log.console("\nValidation tests:"); diff --git a/tests/wota.ce b/tests/wota.ce index a0944c2c..610f4f4a 100644 --- a/tests/wota.ce +++ b/tests/wota.ce @@ -52,13 +52,13 @@ function blob_to_hex(blob) { return bytes.map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() } -function is_blob(x) { return x && typeof x === 'object' && typeof x.length === 'number' && typeof x.read_logical === 'function' } +function is_blob(x) { return x && typeof x == 'object' && typeof x.length == 'number' && typeof x.read_logical == 'function' } /* Deep comparison capable of Blobs + tolerance for floating diff */ function deep_compare(expected, actual, path = '') { - if (expected === actual) return { passed: true, messages: [] } + if (expected == actual) return { passed: true, messages: [] } - if (typeof expected === 'number' && typeof actual === 'number') { + if (typeof expected == 'number' && typeof actual == 'number') { if (isNaN(expected) && isNaN(actual)) return { passed: true, messages: [] } var diff = Math.abs(expected - actual) if (diff <= EPSILON) return { passed: true, messages: [] } @@ -67,37 +67,37 @@ function deep_compare(expected, actual, path = '') { if (is_blob(expected) && is_blob(actual)) { stone_if_needed(expected); stone_if_needed(actual) - if (expected.length !== actual.length) + if (expected.length != actual.length) return { passed: false, messages: [`Blob length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } for (var i = 0; i < expected.length; i++) { - if (expected.read_logical(i) !== actual.read_logical(i)) + if (expected.read_logical(i) != actual.read_logical(i)) return { passed: false, messages: [`Blob bit mismatch at ${path}[${i}]`] } } return { passed: true, messages: [] } } if (Array.isArray(expected) && Array.isArray(actual)) { - if (expected.length !== actual.length) + if (expected.length != actual.length) return { passed: false, messages: [`Array length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } var msgs = [] for (var i = 0; i < expected.length; i++) { var res = deep_compare(expected[i], actual[i], `${path}[${i}]`) if (!res.passed) msgs.push(...res.messages) } - return { passed: msgs.length === 0, messages: msgs } + return { passed: msgs.length == 0, messages: msgs } } - if (typeof expected === 'object' && expected && typeof actual === 'object' && actual) { + if (typeof expected == 'object' && expected && typeof actual == 'object' && actual) { var expKeys = Object.keys(expected).sort() var actKeys = Object.keys(actual).sort() - if (JSON.stringify(expKeys) !== JSON.stringify(actKeys)) + if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) return { passed: false, messages: [`Object keys mismatch at ${path}: ${expKeys} vs ${actKeys}`] } var msgs = [] for (var k of expKeys) { var res = deep_compare(expected[k], actual[k], `${path}.${k}`) if (!res.passed) msgs.push(...res.messages) } - return { passed: msgs.length === 0, messages: msgs } + return { passed: msgs.length == 0, messages: msgs } } return { passed: false, messages: [`Value mismatch at ${path}: ${JSON.stringify(expected)} vs ${JSON.stringify(actual)}`] } @@ -158,11 +158,11 @@ var testCases = [ { input: { '': '' }, expectedHex: '311010' }, { input: 1e-10, expectedHex: 'd00a01' }, - { input: { a: 1, b: 2 }, replacer: (k, v) => typeof v === 'number' ? v * 2 : v, expected: { a: 2, b: 4 }, testType: 'replacer' }, - { input: { x: 'test', y: 5 }, replacer: (k, v) => k === 'x' ? v + '!' : v, expected: { x: 'test!', y: 5 }, testType: 'replacer' }, + { input: { a: 1, b: 2 }, replacer: (k, v) => typeof v == 'number' ? v * 2 : v, expected: { a: 2, b: 4 }, testType: 'replacer' }, + { input: { x: 'test', y: 5 }, replacer: (k, v) => k == 'x' ? v + '!' : v, expected: { x: 'test!', y: 5 }, testType: 'replacer' }, - { input: { a: 1, b: 2 }, reviver: (k, v) => typeof v === 'number' ? v * 3 : v, expected: { a: 3, b: 6 }, testType: 'reviver' }, - { input: { x: 'test', y: 10 }, reviver: (k, v) => k === 'y' ? v + 1 : v, expected: { x: 'test', y: 11 }, testType: 'reviver' } + { input: { a: 1, b: 2 }, reviver: (k, v) => typeof v == 'number' ? v * 3 : v, expected: { a: 3, b: 6 }, testType: 'reviver' }, + { input: { x: 'test', y: 10 }, reviver: (k, v) => k == 'y' ? v + 1 : v, expected: { x: 'test', y: 11 }, testType: 'reviver' } ] /*──────────────────────────────────────────────────────────────────────────*/ @@ -184,12 +184,12 @@ for (var t of testCases) { else { if (t.expectedHex) { var gotHex = blob_to_hex(enc) - if (gotHex !== t.expectedHex.toLowerCase()) + if (gotHex != t.expectedHex.toLowerCase()) msgs.push(`Hex encoding differs (info): exp ${t.expectedHex}, got ${gotHex}`) } var dec = t.reviver ? wota.decode(enc, t.reviver) : wota.decode(enc) - var exp = t.expected !== undefined ? t.expected : t.input + var exp = t.expected != undefined ? t.expected : t.input var cmp = deep_compare(exp, dec) if (!cmp.passed) { passed = false; msgs.push(...cmp.messages) } @@ -215,7 +215,7 @@ for (var r of results) { } log.console(`\nResult: ${passCount}/${testCount} tests passed`) -if (passCount === testCount) { log.console('Overall: PASSED'); os.exit(0) } +if (passCount == testCount) { log.console('Overall: PASSED'); os.exit(0) } log.console('Overall: FAILED') $_.stop() \ No newline at end of file