From c9adbed3ffc9dd577eed2ccdc8533b71efa12b61 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 17 Jun 2025 14:32:27 -0500 Subject: [PATCH] remove undefined; only use null now --- examples/nat.ce | 2 +- prosperon/_sprite.cm | 14 +- prosperon/clay.cm | 14 +- prosperon/controller.cm | 4 +- prosperon/examples/bunnymark/main.ce | 2 +- prosperon/examples/chess/movement.cm | 4 +- prosperon/examples/chess/rules.cm | 4 +- prosperon/examples/pong/main.ce | 2 +- prosperon/examples/snake/main.ce | 2 +- prosperon/examples/tetris/main.ce | 6 +- prosperon/graphics.cm | 10 +- prosperon/imgui.cm | 6 +- prosperon/prosperon.ce | 8 +- prosperon/resources.cm | 6 +- prosperon/scenetree.cm | 12 +- prosperon/sdl_gpu.cm | 12 +- prosperon/sdl_video.ce | 22 +- prosperon/sound.cm | 2 +- prosperon/tests/animation.ce | 2 +- prosperon/tests/bunnymark.ce | 2 +- prosperon/tests/camera.ce | 4 +- prosperon/tilemap.cm | 8 +- prosperon/tween.cm | 8 +- scripts/base.cm | 2 +- scripts/config.ce | 6 +- scripts/docstrings.cm | 40 +- scripts/engine.cm | 12 +- scripts/http.cm | 2 +- scripts/io.cm | 8 +- scripts/jswota.cm | 4 +- scripts/miniz.cm | 4 +- scripts/nota.cm | 4 +- scripts/parseq.cm | 40 +- scripts/text.cm | 4 +- scripts/time.cm | 4 + scripts/util.cm | 6 +- scripts/wota.cm | 4 +- source/cell.c | 28 +- source/jsffi.c | 54 +- source/qjs_actor.c | 10 +- source/qjs_blob.c | 16 +- source/qjs_dmon.c | 8 +- source/qjs_enet.c | 30 +- source/qjs_fd.c | 4 +- source/qjs_geometry.c | 26 +- source/qjs_imgui.cpp | 80 +- source/qjs_io.c | 10 +- source/qjs_macros.h | 30 +- source/qjs_math.c | 24 +- source/qjs_miniz.c | 2 +- source/qjs_nota.c | 33 +- source/qjs_num.c | 4 +- source/qjs_os.c | 18 +- source/qjs_qr.c | 12 +- source/qjs_renderer.c | 36 +- source/qjs_rtree.c | 2 +- source/qjs_sdl.c | 44 +- source/qjs_sdl_gpu.c | 24 +- source/qjs_sdl_surface.c | 14 +- source/qjs_sdl_video.c | 142 ++-- source/qjs_socket.c | 22 +- source/qjs_soloud.c | 8 +- source/qjs_spline.c | 4 +- source/qjs_sprite.c | 4 +- source/qjs_steam.cpp | 22 +- source/qjs_transform.c | 18 +- source/qjs_utf8.c | 2 +- source/qjs_wota.c | 41 +- source/quickjs-libc.c | 80 +- source/quickjs-opcode.h | 4 - source/quickjs.c | 1156 ++++++++++++-------------- source/quickjs.h | 8 +- source/sprite.c | 2 +- source/transform.c | 6 +- tests/blob.ce | 2 +- tests/comments.ce | 2 +- tests/nota.ce | 2 +- tests/num_property_test.ce | 2 +- tests/qr_drag.ce | 8 +- tests/test_actor_access.ce | 2 +- tests/test_child_actor.ce | 2 +- tests/test_module.ce | 2 +- tests/text.ce | 12 +- tests/unneeded.ce | 2 +- tests/wota.ce | 4 +- 85 files changed, 1132 insertions(+), 1232 deletions(-) diff --git a/examples/nat.ce b/examples/nat.ce index 9f244f8e..a082fc32 100644 --- a/examples/nat.ce +++ b/examples/nat.ce @@ -18,7 +18,7 @@ $_.portal(e => { send(waiting_client, e.actor) send(e, waiting_client.actor) - waiting_client = undefined + waiting_client = null return } diff --git a/prosperon/_sprite.cm b/prosperon/_sprite.cm index 66c2f4e8..1c25564d 100644 --- a/prosperon/_sprite.cm +++ b/prosperon/_sprite.cm @@ -2,7 +2,7 @@ var graphics = use('graphics') var color = use('color') var sprite = { - image: undefined, + image: null, set color(x) { this._sprite.color = x; }, get color() { return this._sprite.color; }, anim_speed: 1, @@ -26,8 +26,8 @@ var sprite = { this.del_anim?.(); this.del_anim = () => { - this.del_anim = undefined; - advance = undefined; + this.del_anim = null; + advance = null; stop?.(); }; @@ -102,11 +102,11 @@ var sprite = { }, garbage: function() { this.del_anim?.(); - this.anim = undefined; + this.anim = null; tree.delete(this._sprite) - this.transform.parent = undefined + this.transform.parent = null for (var t of this.transform.children()) - t.parent = undefined + t.parent = null delete this.transform.sprite delete this._sprite // log.console("CLEARED SPRITE") @@ -216,7 +216,7 @@ sprite.to_queue = function(ysort = false) }; var culled = sprite.tree.query(camrect) if (culled.length == 0) return []; - var cmd = graphics.make_sprite_queue(culled, prosperon.camera, undefined, 1); + var cmd = graphics.make_sprite_queue(culled, prosperon.camera, null, 1); return cmd; } diff --git a/prosperon/clay.cm b/prosperon/clay.cm index d7eb7343..c9d5812d 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -11,18 +11,18 @@ var input = use('input') var lay_ctx = layout.make_context(); var clay_base = { - font: undefined, - background_image: undefined, + font: null, + background_image: null, slice: 0, font: 'smalle.16', - font_size: undefined, + font_size: null, color: [1,1,1,1], spacing:0, padding:0, margin:0, offset:[0,0], - size:undefined, - background_color: undefined + size:null, + background_color: null }; var root_item; @@ -216,8 +216,8 @@ clay.button = function button(str, action, config = {}) config.action = action; } -var hovered = undefined; -clay.newframe = function() { hovered = undefined; } +var hovered = null; +clay.newframe = function() { hovered = null; } // mousepos given in hud coordinates clay.draw_commands = function draw_commands(cmds, pos = [0,0], mousepos = prosperon.camera.screen2hud(input.mouse.screenpos())) diff --git a/prosperon/controller.cm b/prosperon/controller.cm index d21f65b4..d18b6148 100644 --- a/prosperon/controller.cm +++ b/prosperon/controller.cm @@ -109,7 +109,7 @@ 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()]; - return undefined; + return null; }; input.print_pawn_kbm = function (pawn) { @@ -180,7 +180,7 @@ input.tabcomplete = function tabcomplete(val, list) { return list[0]; } - var ret = undefined; + var ret = null; var i = val.length; while (!ret && list.length != 0) { var char = list[0][i]; diff --git a/prosperon/examples/bunnymark/main.ce b/prosperon/examples/bunnymark/main.ce index 31ee372b..56a779f8 100644 --- a/prosperon/examples/bunnymark/main.ce +++ b/prosperon/examples/bunnymark/main.ce @@ -66,5 +66,5 @@ this.hud = function() { draw.images(bunnyTex, bunnies) var msg = 'FPS: ' + fpsAvg.toFixed(2) + ' Bunnies: ' + bunnies.length - draw.text(msg, {x:0, y:0, width:config.width, height:40}, undefined, 0, color.white, 0) + draw.text(msg, {x:0, y:0, width:config.width, height:40}, null, 0, color.white, 0) } diff --git a/prosperon/examples/chess/movement.cm b/prosperon/examples/chess/movement.cm index 19d42603..32ba6ead 100644 --- a/prosperon/examples/chess/movement.cm +++ b/prosperon/examples/chess/movement.cm @@ -8,8 +8,8 @@ MovementSystem.prototype.tryMove = function (piece, to) { 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 ?? t[0], + to.y ?? to[1]]; if (!this.grid.inBounds(dest)) return false; if (!this.rules.canMove(piece, piece.coord, dest, this.grid)) return false; diff --git a/prosperon/examples/chess/rules.cm b/prosperon/examples/chess/rules.cm index 323cb0af..d14d5fcd 100644 --- a/prosperon/examples/chess/rules.cm +++ b/prosperon/examples/chess/rules.cm @@ -1,6 +1,6 @@ /* 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 ?? c[0] } +function cy(c) { return c.y ?? c[1] } /* simple move-shape checks */ var deltas = { diff --git a/prosperon/examples/pong/main.ce b/prosperon/examples/pong/main.ce index 768852d7..be1958c5 100644 --- a/prosperon/examples/pong/main.ce +++ b/prosperon/examples/pong/main.ce @@ -82,5 +82,5 @@ this.hud = function() { // Simple score display var msg = score1 + " " + score2 - draw.text(msg, {x:0, y:10, width:config.width, height:40}, undefined, 0, color.white, 0) + draw.text(msg, {x:0, y:10, width:config.width, height:40}, null, 0, color.white, 0) } diff --git a/prosperon/examples/snake/main.ce b/prosperon/examples/snake/main.ce index d7830f56..36e979a4 100644 --- a/prosperon/examples/snake/main.ce +++ b/prosperon/examples/snake/main.ce @@ -92,7 +92,7 @@ this.hud = function() { if (gameState == "gameover") { var msg = "GAME OVER! Press SPACE to restart." - draw.text(msg, {x:0, y:config.height*0.5-10, width:config.width, height:20}, undefined, 0, color.white) + draw.text(msg, {x:0, y:config.height*0.5-10, width:config.width, height:20}, null, 0, color.white) } } diff --git a/prosperon/examples/tetris/main.ce b/prosperon/examples/tetris/main.ce index b7f0837c..a3423030 100644 --- a/prosperon/examples/tetris/main.ce +++ b/prosperon/examples/tetris/main.ce @@ -249,7 +249,7 @@ this.hud = function() { } // Next piece window - draw.text("Next", {x:70, y:5, width:50, height:10}, undefined, 0, color.white) + draw.text("Next", {x:70, y:5, width:50, height:10}, null, 0, color.white) if (nextPiece) { for (var i=0; i { imgui.text(log.transcript); - replstr = imgui.textinput(undefined, replstr); + replstr = imgui.textinput(null, replstr); imgui.button("submit", _ => { eval(replstr); replstr = ""; @@ -242,14 +242,14 @@ imgui.imagebutton[cell.DOC] = `Create an ImageButton widget which displays a tex imgui.textinput[cell.DOC] = `Show a single-line text input widget. :param label: The label text next to the input box. -:param text: The current text. If undefined, the box starts empty. +:param text: The current text. If null, the box starts empty. :return: The updated text string after user editing. `; imgui.textbox[cell.DOC] = `Show a multi-line text input widget. :param label: The label text next to the input box. -:param text: The current multi-line text. If undefined, starts empty. +:param text: The current multi-line text. If null, starts empty. :return: The updated text after user editing. `; diff --git a/prosperon/prosperon.ce b/prosperon/prosperon.ce index 8f496a76..6da6bae5 100644 --- a/prosperon/prosperon.ce +++ b/prosperon/prosperon.ce @@ -108,7 +108,7 @@ var camera = { ortho:true, anchor:[0.5,0.5],//{x:0.5,y:0.5}, rotation:[0,0,0,1], - surface: undefined + surface: null } var util = use('util') @@ -278,13 +278,13 @@ function translate_draw_commands(commands) { var parseq = use('parseq', $_.delay) // Wrap `send(actor,msg,cb)` into a parseq “requestor” -// • on success: cb(data) → value=data, reason=undefined -// • on failure: cb(undefined,err) +// • on success: cb(data) → value=data, reason=null +// • on failure: cb(null,err) function rpc_req(actor, msg) { return (cb, _) => { send(actor, msg, data => { if (data.error) - cb(undefined, data) + cb(null, data) else cb(data) }) diff --git a/prosperon/resources.cm b/prosperon/resources.cm index 840cb1b9..d170f973 100644 --- a/prosperon/resources.cm +++ b/prosperon/resources.cm @@ -41,12 +41,12 @@ function isRecognizedExtension(ext) { } function find_in_path(filename, exts = []) { - if (typeof filename != 'string') return undefined + if (typeof filename != 'string') return null if (filename.includes('.')) { var candidate = filename // possibly need "/" ? if (io.exists(candidate) && !io.is_directory(candidate)) return candidate - return undefined + return null } // Only check extensions if exts is provided and not empty @@ -60,7 +60,7 @@ function find_in_path(filename, exts = []) { var candidate = filename if (io.exists(candidate) && !io.is_directory(candidate)) return candidate } - return undefined + return null } // Return a canonical path (the real directory plus the path) diff --git a/prosperon/scenetree.cm b/prosperon/scenetree.cm index 463e246a..061a1b55 100644 --- a/prosperon/scenetree.cm +++ b/prosperon/scenetree.cm @@ -16,8 +16,8 @@ function add_timer(obj, fn, seconds) { var stop = function () { if (!timer) return timers.delete(stop) - timer.fn = undefined - timer = undefined + timer.fn = null + timer = null } function execute() { @@ -203,7 +203,7 @@ actor.spawn = function spawn(script, config, actor_context) { prog.prog_fn.call(underling, actor_dollar) } catch(e) { throw e; } - if (underling[DEAD]) return undefined; + if (underling[DEAD]) return null; if (typeof config == 'object') Object.assign(underling, config) @@ -276,7 +276,7 @@ ex.all_objects = function (fn, startobj = world) { ex.all_objects[cell.DOC] = ` :param fn: A callback function that receives each object. If it returns a truthy value, iteration stops and that value is returned. :param startobj: The root object at which iteration begins, default is the global "world". -:return: The first truthy value returned by fn, or undefined if none. +:return: The first truthy value returned by fn, or null if none. Iterate over each object (and its sub-objects) in the hierarchy, calling fn for each one. ` @@ -379,10 +379,10 @@ var script_fn = function script_fn(path, args) { // Create a context object with args var context = Object.create(parsed.module_ret) context.__args__ = 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 mod_script = `(function setup_${module_name}_module(){ var self = this; var $ = this; var exports = {}; var module = {exports: exports}; var define = null; 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 == null || 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 6c21472d..fb08469e 100644 --- a/prosperon/sdl_gpu.cm +++ b/prosperon/sdl_gpu.cm @@ -138,14 +138,14 @@ function get_pipeline_ubo_slot(pipeline, name) { if (ubo.name.endsWith(name)) return i; } - return undefined; + return null; } get_pipeline_ubo_slot[cell.DOC] = `Return the index of a uniform buffer block within the pipeline's vertex reflection data by name suffix. :param pipeline: The pipeline whose vertex reflection is inspected. :param name: A string suffix to match against the uniform buffer block name. -:return: The integer index of the matching UBO, or undefined if not found. +:return: The integer index of the matching UBO, or null if not found. ` function transpose4x4(val) { @@ -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 (camslot != null) cmds.camera(camera, camslot); modelslot = get_pipeline_ubo_slot(pipeline, "model"); - if (typeof modelslot != 'undefined') { + if (modelslot != null) { 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 (camslot != null) cmds.hud(camera.size, camslot); for (var group of hud_queue) { @@ -661,7 +661,7 @@ function mask(image, pos, scale, rotation = 0, ref = 1) { var pipe = stencil_writer(ref); render.use_shader('sprite.cg', pipe); var t = new transform; - t.trs(pos, undefined, scale); + t.trs(pos, null, scale); set_model(t); render.use_mat({ diffuse:image.texture, diff --git a/prosperon/sdl_video.ce b/prosperon/sdl_video.ce index 50349966..b56c872e 100644 --- a/prosperon/sdl_video.ce +++ b/prosperon/sdl_video.ce @@ -17,8 +17,8 @@ var default_window = { height: 480, // Position - can be numbers or "centered" - x: undefined, // SDL_WINDOWPOS_UNDEFINED by default - y: undefined, // SDL_WINDOWPOS_UNDEFINED by default + x: null, // SDL_WINDOWPOS_null by default + y: null, // SDL_WINDOWPOS_null by default // Window behavior flags resizable: true, @@ -52,7 +52,7 @@ var default_window = { metal: false, // Force Metal context (macOS) // Advanced properties - parent: undefined, // Parent window for tooltips/popups/modal + parent: null, // Parent window for tooltips/popups/modal modal: false, // Modal to parent window (requires parent) externalGraphicsContext: false, // Use external graphics context @@ -129,7 +129,7 @@ function handle_window(msg) { switch (msg.op) { case 'destroy': win.destroy(); - win = undefined + win = null return {success: true}; case 'show': @@ -157,7 +157,7 @@ function handle_window(msg) { case 'set': var prop = msg.data ? msg.data.property : null; - var value = msg.data ? msg.data.value : undefined; + var value = msg.data ? msg.data.value : null; if (!prop) return {error: "Missing property name"}; // Validate property is settable @@ -220,7 +220,7 @@ function handle_window(msg) { // Renderer operation functions var renderfuncs = { destroy: function(msg) { - ren = undefined + ren = null return {success: true}; }, @@ -269,7 +269,7 @@ var renderfuncs = { } // Special handling for render target - if (prop == 'target' && value != null && value != undefined) { + if (prop == 'target' && value != null && value != null) { var tex = resources.texture[value]; if (!tex) return {error: "Invalid texture id"}; value = tex; @@ -522,7 +522,7 @@ function handle_texture(msg) { case 'set': var prop = msg.data ? msg.data.property : null; - var value = msg.data ? msg.data.value : undefined; + var value = msg.data ? msg.data.value : null; if (!prop) return {error: "Missing property name"}; // Validate property is settable @@ -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 == null) 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 == null) return {error: "Missing capture parameter"}; mouse.capture(msg.data); return {success: true}; @@ -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 == null) return {error: "Missing cursor type"}; var cursor = mouse.create_system_cursor(msg.data); var cursor_id = allocate_id(); resources.cursor[cursor_id] = cursor; diff --git a/prosperon/sound.cm b/prosperon/sound.cm index 31ce5d73..ea199ec4 100644 --- a/prosperon/sound.cm +++ b/prosperon/sound.cm @@ -34,7 +34,7 @@ audio.cry = function cry(file) { if (!voice) return; return function() { voice.stop(); - voice = undefined; + voice = null; } }; audio.cry[doc.sym] = diff --git a/prosperon/tests/animation.ce b/prosperon/tests/animation.ce index 9daa66a1..14e7275c 100644 --- a/prosperon/tests/animation.ce +++ b/prosperon/tests/animation.ce @@ -53,7 +53,7 @@ var camera = { fov:50, near_z: 0, far_z: 1000, - surface: undefined, + surface: null, viewport: {x:0,y:0,width:1,height:1}, ortho:true, anchor:[0,0], diff --git a/prosperon/tests/bunnymark.ce b/prosperon/tests/bunnymark.ce index 2de2b9bd..69698968 100644 --- a/prosperon/tests/bunnymark.ce +++ b/prosperon/tests/bunnymark.ce @@ -18,7 +18,7 @@ var camera = { fov:50, near_z: 0, far_z: 1000, - surface: undefined, + surface: null, viewport: {x:0,y:0,width:1,height:1}, ortho:true, anchor:[0,0], diff --git a/prosperon/tests/camera.ce b/prosperon/tests/camera.ce index 1d97c4fe..359555b7 100644 --- a/prosperon/tests/camera.ce +++ b/prosperon/tests/camera.ce @@ -19,7 +19,7 @@ var camera = { fov:50, near_z: 0, far_z: 1000, - surface: undefined, + surface: null, viewport: {x:0,y:0,width:1,height:1}, ortho:true, anchor:[0.5,0.5], @@ -31,7 +31,7 @@ var hudcam = { fov:50, near_z: 0, far_z: 1000, - surface: undefined, + surface: null, viewport: {x:0,y:0,width:1,height:1}, ortho:true, anchor:[0,0], diff --git a/prosperon/tilemap.cm b/prosperon/tilemap.cm index cf5712e8..d5d80323 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] != null) { var result = fn(map.tiles[x][y], { x: x + map.offset_x, y: y + map.offset_y }); - if (result != undefined) { + if (result != null) { map.tiles[x][y] = result; } } @@ -32,7 +32,7 @@ tilemap.prototype = at(pos) { var x = pos.x - this.offset_x; var y = pos.y - this.offset_y; - if (!this.tiles[x]) return undefined; + if (!this.tiles[x]) return null; return this.tiles[x][y]; }, @@ -51,7 +51,7 @@ tilemap.prototype = for (var i = 0; i < this.tiles.length; i++) { if (!this.tiles[i]) this.tiles[i] = []; var new_col = []; - for (var j = 0; j < shift; j++) new_col[j] = undefined; + for (var j = 0; j < shift; j++) new_col[j] = null; this.tiles[i] = new_col.concat(this.tiles[i]); } this.offset_y = pos.y; diff --git a/prosperon/tween.cm b/prosperon/tween.cm index 3287185e..f64770e7 100644 --- a/prosperon/tween.cm +++ b/prosperon/tween.cm @@ -128,10 +128,10 @@ var tween = function (from, to, time, fn, cb) { function cleanup() { stop() - fn = undefined - stop = undefined - cb = undefined - update = undefined + fn = null + stop = null + cb = null + update = null } var update = function tween_update(dt) { diff --git a/scripts/base.cm b/scripts/base.cm index fe88695e..3b42f20c 100644 --- a/scripts/base.cm +++ b/scripts/base.cm @@ -177,7 +177,7 @@ Object.defineProperty(Array.prototype, "delete", { value: function(item) { var idx = this.indexOf(item); if (idx > -1) this.splice(idx,1); - return undefined; + return null; } }); diff --git a/scripts/config.ce b/scripts/config.ce index 664d7b05..0acef3b6 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 null current = current[segment] } return current @@ -137,7 +137,7 @@ switch (command) { var path = parse_key(key) var value = get_nested(config, path) - if (value == undefined) { + if (value == null) { log.error("Key not found: " + key) } else if (value && typeof value == 'object' && !Array.isArray(value)) { // Print all nested values @@ -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 == null) { log.error("Key not found for actor " + actor_name + ": " + key) } else { log.console('actors.' + actor_name + '.' + key + ' = ' + format_value(value)) diff --git a/scripts/docstrings.cm b/scripts/docstrings.cm index eeefb89f..f2c02640 100644 --- a/scripts/docstrings.cm +++ b/scripts/docstrings.cm @@ -66,24 +66,24 @@ Angles in degrees or radians must first be converted prior to making a quaternio `; prosperon.c_types.transform[cell.DOC].parent = `Get or set the transform's parent. If set, this transform becomes a child of -the parent (re-parenting). Must be another transform object or undefined. +the parent (re-parenting). Must be another transform object or null. -:param value: (when setting) Another transform or undefined. +:param value: (when setting) Another transform or null. :return: The current parent transform (when getting), or None (when setting). `; prosperon.c_types.transform[cell.DOC].change_hook = `A user-supplied function that's called whenever the transform's local matrix changes. -If undefined, no hook is called. +If null, no hook is called. :param value: (when setting) A function. -:return: The current function or undefined. +:return: The current function or null. `; prosperon.c_types.transform[cell.DOC].trs = `Set the transform's position, rotation, and scale in one call. -:param pos: [x,y,z] for position, or undefined to keep existing. -:param quat: [qx,qy,qz,qw] for rotation, or undefined. -:param scale: [sx,sy,sz] for scale, or undefined. +:param pos: [x,y,z] for position, or null to keep existing. +:param quat: [qx,qy,qz,qw] for rotation, or null. +:param scale: [sx,sy,sz] for scale, or null. :return: None `; @@ -231,7 +231,7 @@ prosperon.c_types.datastream[cell.DOC].framerate = `Return the framerate (FPS) o prosperon.c_types.datastream[cell.DOC].callback = `A function to call whenever a new frame is decoded. If not set, no callback is invoked. :param fn: (when setting) A function that receives (surface). -:return: The existing function or undefined if none. +:return: The existing function or null if none. `; @@ -325,10 +325,10 @@ prosperon.c_types.SDL_Camera[cell.DOC] = {} prosperon.c_types.SDL_Camera[cell.DOC][cell.DOC] = `A handle to a physical camera device. Freed when references drop or camera is closed. `; -prosperon.c_types.SDL_Camera[cell.DOC].frame = `Acquire the latest camera frame (as an SDL_Surface). Returns undefined if no +prosperon.c_types.SDL_Camera[cell.DOC].frame = `Acquire the latest camera frame (as an SDL_Surface). Returns null if no new frame is available yet. Throws on error. -:return: SDL_Surface or undefined. +:return: SDL_Surface or null. `; prosperon.c_types.SDL_Camera[cell.DOC].release_frame = `Release a frame surface previously acquired via camera.frame(). Must be @@ -376,9 +376,9 @@ prosperon.c_types.SDL_Window[cell.DOC].keyboard_shown = `Return whether the on-s :return: True if shown, false otherwise. `; -prosperon.c_types.SDL_Window[cell.DOC].theme = `Currently returns undefined. Placeholder for retrieving OS window theme info. +prosperon.c_types.SDL_Window[cell.DOC].theme = `Currently returns null. Placeholder for retrieving OS window theme info. -:return: undefined +:return: null `; prosperon.c_types.SDL_Window[cell.DOC].safe_area = `Return a rect describing any OS-specific "safe" region for UI, e.g. on iPhone with a notch. @@ -502,7 +502,7 @@ prosperon.c_types.SDL_Renderer[cell.DOC].tile = `Tile a texture repeatedly withi :return: None `; -prosperon.c_types.SDL_Renderer[cell.DOC].get_image = `Read back the rendered pixels into a new SDL_Surface. If rect is undefined, capture entire output. +prosperon.c_types.SDL_Renderer[cell.DOC].get_image = `Read back the rendered pixels into a new SDL_Surface. If rect is null, capture entire output. :param rect: Optional {x,y,w,h}. :return: An SDL_Surface with the requested region's pixels. @@ -518,7 +518,7 @@ prosperon.c_types.SDL_Renderer[cell.DOC].fasttext = `Draw debug text using an in prosperon.c_types.SDL_Renderer[cell.DOC].geometry = `Render custom geometry from a mesh object {pos, uv, color, indices, count} with an optional texture. -:param texture: The SDL_Texture or undefined. +:param texture: The SDL_Texture or null. :param meshObject: The geometry data with typed arrays. :return: None `; @@ -536,15 +536,15 @@ For example, (320, 240) can auto-scale up to the window resolution. :return: None `; -prosperon.c_types.SDL_Renderer[cell.DOC].viewport = `Set the clipping viewport for rendering. Pass undefined to use the full render target. +prosperon.c_types.SDL_Renderer[cell.DOC].viewport = `Set the clipping viewport for rendering. Pass null to use the full render target. -:param rect: {x, y, w, h}, or undefined. +:param rect: {x, y, w, h}, or null. :return: None `; -prosperon.c_types.SDL_Renderer[cell.DOC].clip = `Set or clear the clipping rectangle for drawing. Pass undefined to clear. +prosperon.c_types.SDL_Renderer[cell.DOC].clip = `Set or clear the clipping rectangle for drawing. Pass null to clear. -:param rect: {x, y, w, h} or undefined. +:param rect: {x, y, w, h} or null. :return: None `; @@ -579,9 +579,9 @@ prosperon.c_types.SDL_Renderer[cell.DOC].screen2world = `Convert a screen coordi :return: [wx, wy] in world space `; -prosperon.c_types.SDL_Renderer[cell.DOC].target = `Set or clear the current render target texture. Pass undefined to reset to the default/window. +prosperon.c_types.SDL_Renderer[cell.DOC].target = `Set or clear the current render target texture. Pass null to reset to the default/window. -:param texture: An SDL_Texture or undefined +:param texture: An SDL_Texture or null :return: None `; diff --git a/scripts/engine.cm b/scripts/engine.cm index 9cfb3155..68999d8c 100644 --- a/scripts/engine.cm +++ b/scripts/engine.cm @@ -375,10 +375,10 @@ $_.clock = function(fn) { $_.clock[cell.DOC] = "takes a function input value that will eventually be called with the current time in number form." var underlings = new Set() // this is more like "all actors that are notified when we die" -var overling = undefined -var root = undefined +var overling = null +var root = null -var receive_fn = undefined +var receive_fn = null var greeters = {} // Router functions for when messages are received for a specific actor globalThis.is_actor = function is_actor(actor) { @@ -426,8 +426,8 @@ $_.connection[cell.DOC] = "The connection function takes a callback function, an var peers = {} var id_address = {} var peer_queue = new Map() -var portal = undefined -var portal_fn = undefined +var portal = null +var portal_fn = null $_.portal = function(fn, port) { if (portal) throw new Error(`Already started a portal listening on ${portal.port}`) @@ -649,7 +649,7 @@ globalThis.send = function send(actor, message, reply) { replies[id] = reply $_.delay(_ => { if (replies[id]) { - replies[id](undefined, "timeout") + replies[id](null, "timeout") delete replies[id] } }, REPLYTIMEOUT) diff --git a/scripts/http.cm b/scripts/http.cm index ea36c081..779f5bed 100644 --- a/scripts/http.cm +++ b/scripts/http.cm @@ -8,7 +8,7 @@ This function enqueues an HTTP GET request for the specified URL. It supports bo :param options: Either a callback function or an object with optional properties: - 'callback': A function invoked upon request completion, receiving an object with 'data' (string or null) and 'error' (string or null) properties. - 'on_data': A function invoked for each chunk of streaming data, receiving a string chunk as its argument. If supplied, 'callback.data' will be null. -:return: undefined +:return: null :throws: - An error if the URL is not a string or is invalid. - An error if the options argument is neither a function nor an object. diff --git a/scripts/io.cm b/scripts/io.cm index c68e8d73..b8215026 100644 --- a/scripts/io.cm +++ b/scripts/io.cm @@ -72,11 +72,11 @@ Throw on error. :return: None ` -io.mount[cell.DOC] = `Mount a directory or archive at the specified mount point. An undefined mount +io.mount[cell.DOC] = `Mount a directory or archive at the specified mount point. An null mount point mounts to '/'. Throw on error. :param archiveOrDir: The directory or archive to mount. -:param mountPoint: The path at which to mount. If omitted or undefined, '/' is used. +:param mountPoint: The path at which to mount. If omitted or null, '/' is used. :return: None ` @@ -145,10 +145,10 @@ operations. Throw on error. ` io.realdir[cell.DOC] = `Return the actual, real directory (on the host filesystem) that contains the given -file path. Return undefined if not found. +file path. Return null if not found. :param path: The file path whose real directory is requested. -:return: A string with the real directory path, or undefined. +:return: A string with the real directory path, or null. ` io.searchpath[cell.DOC] = `Return an array of all directories in the current paths. diff --git a/scripts/jswota.cm b/scripts/jswota.cm index 347b9c2a..190da5ad 100644 --- a/scripts/jswota.cm +++ b/scripts/jswota.cm @@ -83,7 +83,7 @@ function encode_val(b, val) b.write_blob(TRUE_SYMBOL) else b.write_blob(FALSE_SYMBOL) - } else if (type == 'undefined') { + } else if (type == 'null') { b.write_blob(NULL_SYMBOL) } else if (type == 'object') { if (Array.isArray(val)) { @@ -118,7 +118,7 @@ function encode(val) function decode(b) { - return undefined + return null } return { INT, FP_HEADER, ARRAY, RECORD, BLOB, TEXT, NULL_SYMBOL, FALSE_SYMBOL, TRUE_SYMBOL, PRIVATE_SYMBOL, SYSTEM_SYMBOL, encode, decode } \ No newline at end of file diff --git a/scripts/miniz.cm b/scripts/miniz.cm index 25c821bf..1e606c01 100644 --- a/scripts/miniz.cm +++ b/scripts/miniz.cm @@ -1,14 +1,14 @@ var miniz = this miniz.read[cell.DOC] = `Create a zip reader from the given ArrayBuffer containing an entire ZIP archive. -Return undefined if the data is invalid. +Return null if the data is invalid. :param data: An ArrayBuffer with the entire ZIP file. :return: A 'zip reader' object with methods for reading from the archive (mod, exists, slurp). ` miniz.write[cell.DOC] = `Create a zip writer that writes to the specified file path. Overwrites the file if -it already exists. Return undefined on error. +it already exists. Return null on error. :param path: The file path where the ZIP archive will be written. :return: A 'zip writer' object with methods for adding files to the archive (add_file). diff --git a/scripts/nota.cm b/scripts/nota.cm index c7336e30..d0e58d49 100644 --- a/scripts/nota.cm +++ b/scripts/nota.cm @@ -31,10 +31,10 @@ This function serializes JavaScript values (such as numbers, strings, booleans, nota.decode[cell.DOC] = `Decode a NOTA-encoded ArrayBuffer into a JavaScript value. -This function deserializes a NOTA-formatted ArrayBuffer into its corresponding JavaScript representation, such as a number, string, boolean, array, object, or ArrayBuffer. If the input is invalid or empty, it returns undefined. +This function deserializes a NOTA-formatted ArrayBuffer into its corresponding JavaScript representation, such as a number, string, boolean, array, object, or ArrayBuffer. If the input is invalid or empty, it returns null. :param buffer: An ArrayBuffer containing NOTA-encoded data to decode. -:return: The decoded JavaScript value (e.g., number, string, boolean, array, object, or ArrayBuffer), or undefined if no argument is provided. +:return: The decoded JavaScript value (e.g., number, string, boolean, array, object, or ArrayBuffer), or null if no argument is provided. ` return nota diff --git a/scripts/parseq.cm b/scripts/parseq.cm index 7e227ae3..e2faaa35 100644 --- a/scripts/parseq.cm +++ b/scripts/parseq.cm @@ -14,7 +14,7 @@  Each factory returns a **requestor** function as described by the spec. */ -def delay = arg[0] // may be undefined +def delay = arg[0] // may be null // ———————————————————————————————————————— helpers @@ -39,7 +39,7 @@ function check_callback (cb, factory) { } function schedule (fn, seconds) { - if (seconds == undefined || seconds <= 0) return fn() + if (seconds == null || seconds <= 0) return fn() if (typeof delay == 'function') return delay(fn, seconds) throw make_reason('schedule', '@.delay capability required for timeouts.') } @@ -52,10 +52,10 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) { let timer_cancel function cancel (reason = make_reason(factory, 'Cancel.')) { - if (timer_cancel) timer_cancel(), timer_cancel = undefined + if (timer_cancel) timer_cancel(), timer_cancel = null if (!cancel_list) return cancel_list.forEach(c => { try { if (typeof c == 'function') c(reason) } catch (_) {} }) - cancel_list = undefined + cancel_list = null } function start_requestor (value) { @@ -65,22 +65,22 @@ 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 - cancel_list[idx] = undefined + if (!cancel_list || idx == null) return + cancel_list[idx] = null action(val, reason, idx) - idx = undefined + idx = null if (factory == 'sequence') start_requestor(val) else if (throttle) start_requestor(initial) }, value) } catch (ex) { - action(undefined, ex, idx) - idx = undefined + action(null, ex, idx) + idx = null if (factory == 'sequence') start_requestor(value) else if (throttle) start_requestor(initial) } } - if (time_limit != undefined) { + if (time_limit != null) { 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) @@ -123,9 +123,9 @@ function par_all (collection, time_limit, throttle) { def results = new Array(list.length) def cancel = run(factory, list, initial, (val, reason, idx) => { - if (val == undefined) { + if (val == null) { cancel(reason) - return cb(undefined, reason) + return cb(null, reason) } results[idx] = val if (--pending == 0) cb(_denormalize(names, results)) @@ -148,12 +148,12 @@ function par_any (collection, time_limit, throttle) { def cancel = run(factory, list, initial, (val, reason, idx) => { pending-- - if (val != undefined) successes[idx] = val - if (successes.some(v => v != undefined)) { + if (val != null) successes[idx] = val + if (successes.some(v => v != null)) { if (!pending) cancel(make_reason(factory, 'Finished.')) - return cb(_denormalize(names, successes.filter(v => v != undefined))) + return cb(_denormalize(names, successes.filter(v => v != null))) } - if (!pending) cb(undefined, make_reason(factory, 'No successes.')) + if (!pending) cb(null, make_reason(factory, 'No successes.')) }, time_limit, throttle) return cancel @@ -171,14 +171,14 @@ function race (list, time_limit, throttle) { let done = false def cancel = run(factory, list, initial, (val, reason, idx) => { if (done) return - if (val != undefined) { + if (val != null) { done = true cancel(make_reason(factory, 'Loser.', idx)) cb(val) } else if (--list.length == 0) { done = true cancel(reason) - cb(undefined, reason) + cb(null, reason) } }, time_limit, throttle) return cancel @@ -203,11 +203,11 @@ 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 == null) return cb(null, reason) next(val) }, value) } catch (ex) { - cb(undefined, ex) + cb(null, ex) } } diff --git a/scripts/text.cm b/scripts/text.cm index 90897ac6..06ca262e 100644 --- a/scripts/text.cm +++ b/scripts/text.cm @@ -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 == null) from = 0; + if (to == null) to = len; // Validate range if (from < 0 || from > to || to > len) return null; diff --git a/scripts/time.cm b/scripts/time.cm index fed678b1..f42b29e6 100644 --- a/scripts/time.cm +++ b/scripts/time.cm @@ -124,6 +124,10 @@ function number(rec = now()) /* -------------------------------------------------------------------- */ /* record → seconds-since-epoch */ + log.console(typeof rec) + log.console(rec) + log.console(rec.minute) + var c = 0; var year = rec.year || 0; var hour = rec.hour || 0; diff --git a/scripts/util.cm b/scripts/util.cm index 6f5e7b85..09d67139 100644 --- a/scripts/util.cm +++ b/scripts/util.cm @@ -13,10 +13,10 @@ util.dainty_assign = function (target, source) { } util.get = function (obj, path, defValue) { - if (!path) return undefined + if (!path) return null 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 == null ? defValue : result } util.isEmpty = function(o) { @@ -36,7 +36,7 @@ util.access = function (obj, name) { var dig = name.split(".") for (var i of dig) { obj = obj[i] - if (!obj) return undefined + if (!obj) return null } return obj } diff --git a/scripts/wota.cm b/scripts/wota.cm index d90b0860..692671be 100644 --- a/scripts/wota.cm +++ b/scripts/wota.cm @@ -33,11 +33,11 @@ This function serializes JavaScript values (such as numbers, strings, booleans, wota.decode[cell.DOC] = `Decode a WOTA-encoded ArrayBuffer into a JavaScript value. -This function deserializes a WOTA-formatted ArrayBuffer into its corresponding JavaScript representation, such as a number, string, boolean, array, object, or ArrayBuffer. If the input is invalid or empty, it returns undefined. +This function deserializes a WOTA-formatted ArrayBuffer into its corresponding JavaScript representation, such as a number, string, boolean, array, object, or ArrayBuffer. If the input is invalid or empty, it returns null. :param buffer: An ArrayBuffer containing WOTA-encoded data to decode. :param reviver: An optional function that transforms the decoded values. -:return: The decoded JavaScript value (e.g., number, string, boolean, array, object, or ArrayBuffer), or undefined if no argument is provided. +:return: The decoded JavaScript value (e.g., number, string, boolean, array, object, or ArrayBuffer), or null if no argument is provided. ` return wota diff --git a/source/cell.c b/source/cell.c index 5ede7449..76f250c6 100644 --- a/source/cell.c +++ b/source/cell.c @@ -378,7 +378,7 @@ void actor_unneeded(cell_rt *actor, JSValue fn, double seconds) JS_FreeValue(actor->context, actor->unneeded); if (!JS_IsFunction(actor->context, fn)) { - actor->unneeded = JS_UNDEFINED; + actor->unneeded = JS_NULL; goto END; } @@ -398,10 +398,10 @@ cell_rt *create_actor(void *wota) cell_rt *actor = calloc(sizeof(*actor), 1); actor->heap = mi_heap_new(); actor->init_wota = wota; - actor->idx_buffer = JS_UNDEFINED; - actor->message_handle = JS_UNDEFINED; - actor->unneeded = JS_UNDEFINED; - actor->on_exception = JS_UNDEFINED; + actor->idx_buffer = JS_NULL; + actor->message_handle = JS_NULL; + actor->unneeded = JS_NULL; + actor->on_exception = JS_NULL; actor->actor_sym = JS_ATOM_NULL; arrsetcap(actor->letters, 5); @@ -476,9 +476,9 @@ static Uint32 actor_remove_cb(cell_rt *actor, Uint32 id, Uint32 interval) { actor->disrupt = 1; - if (!JS_IsUndefined(actor->unneeded)) { + if (!JS_IsNull(actor->unneeded)) { SDL_LockMutex(actor->mutex); - JSValue ret = JS_Call(actor->context, actor->unneeded, JS_UNDEFINED, 0, NULL); + JSValue ret = JS_Call(actor->context, actor->unneeded, JS_NULL, 0, NULL); uncaught_exception(actor->context, ret); SDL_UnlockMutex(actor->mutex); } @@ -574,11 +574,11 @@ void actor_turn(cell_rt *actor) size_t size = l.blob_data->length / 8; // Convert bits to bytes JSValue arg = js_new_blob_stoned_copy(actor->context, l.blob_data->data, size); blob_destroy(l.blob_data); - result = JS_Call(actor->context, actor->message_handle, JS_UNDEFINED, 1, &arg); + result = JS_Call(actor->context, actor->message_handle, JS_NULL, 1, &arg); uncaught_exception(actor->context, result); JS_FreeValue(actor->context, arg); } else if (l.type == LETTER_CALLBACK) { - result = JS_Call(actor->context, l.callback, JS_UNDEFINED, 0, NULL); + result = JS_Call(actor->context, l.callback, JS_NULL, 0, NULL); uncaught_exception(actor->context, result); JS_FreeValue(actor->context, l.callback); } @@ -627,7 +627,7 @@ JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv) JS_ToFloat64(js, &seconds, argv[1]); if (seconds <= 0) { actor_clock(actor, argv[0]); - return JS_UNDEFINED; + return JS_NULL; } SDL_LockMutex(actor->msg_mutex); @@ -643,11 +643,11 @@ JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *arg cell_rt *actor = JS_GetContextOpaque(js); uint32_t timer_id; JS_ToUint32(js, &timer_id, argv[0]); - if (timer_id == -1) return JS_UNDEFINED; + if (timer_id == -1) return JS_NULL; SDL_RemoveTimer(timer_id); - JSValue cb = JS_UNDEFINED; + JSValue cb = JS_NULL; SDL_LockMutex(actor->msg_mutex); int id = hmgeti(actor->timers, timer_id); @@ -659,7 +659,7 @@ JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *arg JS_FreeValue(js,cb); - return JS_UNDEFINED; + return JS_NULL; } // Wrapper struct to keep the array pointer stable @@ -788,7 +788,7 @@ int uncaught_exception(JSContext *js, JSValue v) } JSValue exp = JS_GetException(js); - JSValue ret = JS_Call(js, rt->on_exception, JS_UNDEFINED, 1, &exp); + JSValue ret = JS_Call(js, rt->on_exception, JS_NULL, 1, &exp); JS_FreeValue(js,ret); JS_FreeValue(js, exp); JS_FreeValue(js,v); diff --git a/source/jsffi.c b/source/jsffi.c index 5dd73298..a7532038 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -243,8 +243,8 @@ void free_gpu_buffer(JSRuntime *rt, void *opaque, void *ptr) JSValue make_gpu_buffer(JSContext *js, void *data, size_t size, int type, int elements, int copy, int index) { JSValue tstack[3]; - tstack[1] = JS_UNDEFINED; - tstack[2] = JS_UNDEFINED; + tstack[1] = JS_NULL; + tstack[2] = JS_NULL; // TODO: always copying; implement "takeover" tstack[0] = js_new_blob_stoned_copy(js,data,size);//, make_gpu_buffer, NULL, 1); // JSValue ret = JS_NewTypedArray(js, 3, tstack, type); @@ -253,7 +253,7 @@ JSValue make_gpu_buffer(JSContext *js, void *data, size_t size, int type, int el // JS_SetPropertyStr(js,ret,"index", JS_NewBool(js,index)); // JS_FreeValue(js,tstack[0]); // return ret; - return JS_UNDEFINED; + return JS_NULL; } void *get_gpu_buffer(JSContext *js, JSValue argv, size_t *stride, size_t *size) @@ -272,7 +272,7 @@ JSValue make_quad_indices_buffer(JSContext *js, int quads) { cell_rt *rt = JS_GetContextOpaque(js); int count = quads*6; - if (!JS_IsUndefined(rt->idx_buffer) && rt->idx_count >= count) + if (!JS_IsNull(rt->idx_buffer) && rt->idx_count >= count) return JS_DupValue(js,rt->idx_buffer); int verts = quads*4; @@ -286,7 +286,7 @@ JSValue make_quad_indices_buffer(JSContext *js, int quads) indices[i+5] = v+1; } - if (!JS_IsUndefined(rt->idx_buffer)) + if (!JS_IsNull(rt->idx_buffer)) JS_FreeValue(js,rt->idx_buffer); // rt->idx_buffer = make_gpu_buffer(js,indices, sizeof(*indices)*count, JS_TYPED_ARRAY_UINT16, 1,0,1); @@ -380,10 +380,10 @@ double js2angle(JSContext *js,JSValue v) { typedef HMM_Vec4 colorf; colorf js2color(JSContext *js,JSValue v) { - if (JS_IsUndefined(v)) return (colorf){1,1,1,1}; + if (JS_IsNull(v)) return (colorf){1,1,1,1}; JSValue c[4]; for (int i = 0; i < 4; i++) c[i] = JS_GetPropertyUint32(js,v,i); - float a = JS_IsUndefined(c[3]) ? 1.0 : js2number(js,c[3]); + float a = JS_IsNull(c[3]) ? 1.0 : js2number(js,c[3]); colorf color = { .r = js2number(js,c[0]), .g = js2number(js,c[1]), @@ -532,7 +532,7 @@ JSValue vecarr2js(JSContext *js,HMM_Vec2 *points, int n) { } rect js2rect(JSContext *js,JSValue v) { - if (JS_IsUndefined(v)) return (rect){0,0,1,1}; + if (JS_IsNull(v)) return (rect){0,0,1,1}; rect rect; JS_GETATOM(js,rect.x,v,x,number) JS_GETATOM(js,rect.y,v,y,number) @@ -550,7 +550,7 @@ rect js2rect(JSContext *js,JSValue v) { irect js2irect(JSContext *js, JSValue v) { - if (JS_IsUndefined(v)) return (irect){0,0,1,1}; + if (JS_IsNull(v)) return (irect){0,0,1,1}; irect rect; JS_GETATOM(js,rect.x,v,x,number) JS_GETATOM(js,rect.y,v,y,number) @@ -694,7 +694,7 @@ JSC_CCALL(os_make_text_buffer, JSValue js_util_camera_globals(JSContext *js, JSValue self, int argc, JSValue *argv) { JSValue camera = argv[0]; - if(JS_IsUndefined(camera)) return JS_UNDEFINED; + if(JS_IsNull(camera)) return JS_NULL; HMM_Vec2 size; HMM_Vec3 pos; HMM_Quat rotation; double fov = 0; int ortho; double near_z = 0; double far_z = 0; @@ -815,10 +815,10 @@ JSC_CCALL(array_lerp, ) JSValue js_array_get_x(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js,self,0); } -JSValue js_array_set_x(JSContext *js, JSValue self, JSValue val) { JS_SetPropertyUint32(js,self,0,val); return JS_UNDEFINED; } +JSValue js_array_set_x(JSContext *js, JSValue self, JSValue val) { JS_SetPropertyUint32(js,self,0,val); return JS_NULL; } JSValue js_array_get_y(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js,self,1); } -JSValue js_array_set_y(JSContext *js, JSValue self, JSValue val) { JS_SetPropertyUint32(js,self,1,val); return JS_UNDEFINED; } +JSValue js_array_set_y(JSContext *js, JSValue self, JSValue val) { JS_SetPropertyUint32(js,self,1,val); return JS_NULL; } JSValue js_array_get_xy(JSContext *js, JSValue self) { @@ -832,7 +832,7 @@ JSValue js_array_set_xy(JSContext *js, JSValue self, JSValue v) { JS_SetPropertyUint32(js,self,0,JS_GetPropertyUint32(js,v,0)); JS_SetPropertyUint32(js,self,1,JS_GetPropertyUint32(js,v,1)); - return JS_UNDEFINED; + return JS_NULL; } // Single-value accessors @@ -841,25 +841,25 @@ JSValue js_array_get_r(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js, self, 0); } JSValue js_array_set_r(JSContext *js, JSValue self, JSValue val) -{ JS_SetPropertyUint32(js, self, 0, val); return JS_UNDEFINED; } +{ JS_SetPropertyUint32(js, self, 0, val); return JS_NULL; } JSValue js_array_get_g(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js, self, 1); } JSValue js_array_set_g(JSContext *js, JSValue self, JSValue val) -{ JS_SetPropertyUint32(js, self, 1, val); return JS_UNDEFINED; } +{ JS_SetPropertyUint32(js, self, 1, val); return JS_NULL; } JSValue js_array_get_b(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js, self, 2); } JSValue js_array_set_b(JSContext *js, JSValue self, JSValue val) -{ JS_SetPropertyUint32(js, self, 2, val); return JS_UNDEFINED; } +{ JS_SetPropertyUint32(js, self, 2, val); return JS_NULL; } JSValue js_array_get_a(JSContext *js, JSValue self) { return JS_GetPropertyUint32(js, self, 3); } JSValue js_array_set_a(JSContext *js, JSValue self, JSValue val) -{ JS_SetPropertyUint32(js, self, 3, val); return JS_UNDEFINED; } +{ JS_SetPropertyUint32(js, self, 3, val); return JS_NULL; } // Multi-value accessors @@ -877,7 +877,7 @@ JSValue js_array_set_rgb(JSContext *js, JSValue self, JSValue val) JS_SetPropertyUint32(js, self, 0, JS_GetPropertyUint32(js, val, 0)); JS_SetPropertyUint32(js, self, 1, JS_GetPropertyUint32(js, val, 1)); JS_SetPropertyUint32(js, self, 2, JS_GetPropertyUint32(js, val, 2)); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_array_get_rgba(JSContext *js, JSValue self) @@ -896,7 +896,7 @@ JSValue js_array_set_rgba(JSContext *js, JSValue self, JSValue val) JS_SetPropertyUint32(js, self, 1, JS_GetPropertyUint32(js, val, 1)); JS_SetPropertyUint32(js, self, 2, JS_GetPropertyUint32(js, val, 2)); JS_SetPropertyUint32(js, self, 3, JS_GetPropertyUint32(js, val, 3)); - return JS_UNDEFINED; + return JS_NULL; } static const JSCFunctionListEntry js_array_funcs[] = { @@ -1218,7 +1218,7 @@ JSValue make_color_buffer(JSContext *js, colorf c, int verts) } JSC_CCALL(os_make_line_prim, - return JS_UNDEFINED; + return JS_NULL; /* JSValue prim = JS_NewObject(js); HMM_Vec2 *v = js2cpvec2arr(js,argv[0]); @@ -1262,7 +1262,7 @@ JSC_CCALL(os_make_line_prim, ) static void render_frame(plm_t *mpeg, plm_frame_t *frame, datastream *ds) { - if (JS_IsUndefined(ds->callback)) return; + if (JS_IsNull(ds->callback)) return; uint8_t *rgb = malloc(frame->height*frame->width*4); memset(rgb,255,frame->height*frame->width*4); plm_frame_to_rgba(frame, rgb, frame->width*4); @@ -1278,7 +1278,7 @@ static void render_frame(plm_t *mpeg, plm_frame_t *frame, datastream *ds) { JSValue s[1]; s[0] = surfData; JSValue cb = JS_DupValue(ds->js,ds->callback); - JSValue ret = JS_Call(ds->js, cb, JS_UNDEFINED, 1, s); + JSValue ret = JS_Call(ds->js, cb, JS_NULL, 1, s); JS_FreeValue(ds->js,cb); free(rgb); uncaught_exception(ds->js,ret); @@ -1290,7 +1290,7 @@ JSC_CCALL(os_make_video, datastream *ds = ds_openvideo(data, len); if (!ds) return JS_ThrowReferenceError(js, "Video file was not valid."); ds->js = js; - ds->callback = JS_UNDEFINED; + ds->callback = JS_NULL; plm_set_video_decode_callback(ds->plm, render_frame, ds); return datastream2js(js,ds); ) @@ -1314,7 +1314,7 @@ JSC_CCALL(os_rectpack, int packed = stbrp_pack_rects(ctx, rects, num); if (!packed) { - return JS_UNDEFINED; + return JS_NULL; } ret = JS_NewArray(js); @@ -1339,7 +1339,7 @@ JSC_CCALL(os_insertion_sort, while (j >= 0) { JSValue arr_j = JS_GetPropertyUint32(js, arr, j); - JSValue ret = JS_Call(js, cmp, JS_UNDEFINED, 2, (JSValue[]){ arr_j, key }); + JSValue ret = JS_Call(js, cmp, JS_NULL, 2, (JSValue[]){ arr_j, key }); if (JS_IsException(ret)) { JS_FreeValue(js,arr_j); JS_FreeValue(js,key); @@ -1367,13 +1367,13 @@ JSC_CCALL(os_power_state, SDL_PowerState state = SDL_GetPowerInfo(NULL, NULL); switch(state) { case SDL_POWERSTATE_ERROR: return JS_ThrowTypeError(js, "Error determining power status"); - case SDL_POWERSTATE_UNKNOWN: return JS_UNDEFINED; + case SDL_POWERSTATE_UNKNOWN: return JS_NULL; case SDL_POWERSTATE_ON_BATTERY: return JS_NewString(js, "on battery"); case SDL_POWERSTATE_NO_BATTERY: return JS_NewString(js, "no battery"); case SDL_POWERSTATE_CHARGING: return JS_NewString(js, "charging"); case SDL_POWERSTATE_CHARGED: return JS_NewString(js, "charged"); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(os_cull_sprites, diff --git a/source/qjs_actor.c b/source/qjs_actor.c index ebc623d0..a9b5a2d0 100644 --- a/source/qjs_actor.c +++ b/source/qjs_actor.c @@ -20,7 +20,7 @@ cell_rt *js2actor(JSContext *js, JSValue v) cell_rt *crt = JS_GetContextOpaque(js); JSValue actor_data = JS_GetProperty(js, v, crt->actor_sym); - if (JS_IsUndefined(actor_data)) { + if (JS_IsNull(actor_data)) { JS_FreeValue(js, actor_data); return NULL; } @@ -28,7 +28,7 @@ cell_rt *js2actor(JSContext *js, JSValue v) JSValue id_val = JS_GetPropertyStr(js, actor_data, "id"); JS_FreeValue(js, actor_data); - if (JS_IsUndefined(id_val)) { + if (JS_IsNull(id_val)) { JS_FreeValue(js, id_val); return NULL; } @@ -78,7 +78,7 @@ JSC_CCALL(os_createactor, if (rt->disrupt) return JS_ThrowInternalError(js, "Can't start a new actor while disrupting."); - void *startup = value2wota(js, argv[0], JS_UNDEFINED, NULL); + void *startup = value2wota(js, argv[0], JS_NULL, NULL); create_actor(startup); ) @@ -98,7 +98,7 @@ JSC_CCALL(os_mailbox_push, JS_FreeCString(js,id); /* JSValue sys = JS_GetPropertyStr(js, argv[1], "__SYSTEM__"); - if (!JS_IsUndefined(sys)) { + if (!JS_IsNull(sys)) { const char *k = JS_ToCString(js,sys); int stop = 0; if (strcmp(k, "stop") == 0) { @@ -108,7 +108,7 @@ JSC_CCALL(os_mailbox_push, JS_FreeValue(js,sys); JS_FreeCString(js,k); - if (stop) return JS_UNDEFINED; + if (stop) return JS_NULL; } */ size_t size; diff --git a/source/qjs_blob.c b/source/qjs_blob.c index ed302c08..ad494bec 100644 --- a/source/qjs_blob.c +++ b/source/qjs_blob.c @@ -60,7 +60,7 @@ static JSValue js_blob_constructor(JSContext *ctx, JSValueConst new_target, size_t bits_written = 0; while (bits_written < length_bits) { - JSValue randval = JS_Call(ctx, argv[1], JS_UNDEFINED, 0, NULL); + JSValue randval = JS_Call(ctx, argv[1], JS_NULL, 0, NULL); if (JS_IsException(randval)) { blob_destroy(bd); return JS_EXCEPTION; @@ -151,7 +151,7 @@ static JSValue js_blob_write_bit(JSContext *ctx, JSValueConst this_val, if (blob_write_bit(bd, bit_val) < 0) { return JS_ThrowTypeError(ctx, "write_bit: cannot write (maybe stone or OOM)"); } - return JS_UNDEFINED; + return JS_NULL; } // blob.write_blob(second_blob) @@ -173,7 +173,7 @@ static JSValue js_blob_write_blob(JSContext *ctx, JSValueConst this_val, return JS_ThrowTypeError(ctx, "write_blob: cannot write to stone blob or OOM"); } - return JS_UNDEFINED; + return JS_NULL; } // blob.write_dec64(number) @@ -194,7 +194,7 @@ static JSValue js_blob_write_number(JSContext *ctx, JSValueConst this_val, if (blob_write_dec64(bd, d) < 0) return JS_ThrowTypeError(ctx, "write_dec64: cannot write to stone blob or OOM"); - return JS_UNDEFINED; + return JS_NULL; } // blob.write_fit(value, len) @@ -217,7 +217,7 @@ static JSValue js_blob_write_fit(JSContext *ctx, JSValueConst this_val, return JS_ThrowTypeError(ctx, "write_fit: value doesn't fit in specified bits, stone blob, or OOM"); } - return JS_UNDEFINED; + return JS_NULL; } // blob.write_kim(fit) @@ -239,7 +239,7 @@ static JSValue js_blob_write_text(JSContext *ctx, JSValueConst this_val, } JS_FreeCString(ctx,str); - return JS_UNDEFINED; + return JS_NULL; } // blob.write_pad(block_size) @@ -258,7 +258,7 @@ static JSValue js_blob_write_pad(JSContext *ctx, JSValueConst this_val, if (blob_write_pad(bd, block_size) < 0) return JS_ThrowTypeError(ctx, "write_pad: cannot write (stone blob, OOM, or invalid block size)"); - return JS_UNDEFINED; + return JS_NULL; } // blob.read_logical(from) @@ -439,7 +439,7 @@ static JSValue js_blob_stone(JSContext *ctx, JSValueConst this_val, if (!bd->is_stone) { blob_make_stone(bd); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_blob_stonep(JSContext *ctx, JSValueConst this_val, diff --git a/source/qjs_dmon.c b/source/qjs_dmon.c index d783acd4..085975eb 100644 --- a/source/qjs_dmon.c +++ b/source/qjs_dmon.c @@ -73,7 +73,7 @@ JSValue js_dmon_watch(JSContext *js, JSValue self, int argc, JSValue *argv) return JS_ThrowReferenceError(js, "Already watching a directory."); watched = dmon_watch(".", watch_cb, DMON_WATCHFLAGS_RECURSIVE, NULL); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_dmon_unwatch(JSContext *js, JSValue self, int argc, JSValue *argv) @@ -83,7 +83,7 @@ JSValue js_dmon_unwatch(JSContext *js, JSValue self, int argc, JSValue *argv) dmon_unwatch(watched); watched.id = 0; - return JS_UNDEFINED; + return JS_NULL; } JSValue js_dmon_poll(JSContext *js, JSValueConst this_val, int argc, JSValueConst *argv) { @@ -110,9 +110,9 @@ JSValue js_dmon_poll(JSContext *js, JSValueConst this_val, int argc, JSValueCons JS_SetPropertyStr(js, jsevent, "root", JS_NewString(js, event.rootdir)); JS_SetPropertyStr(js, jsevent, "file", JS_NewString(js, event.filepath)); JS_SetPropertyStr(js, jsevent, "old", JS_NewString(js, event.oldfilepath)); - JS_Call(js, argv[0], JS_UNDEFINED, 1, &jsevent); + JS_Call(js, argv[0], JS_NULL, 1, &jsevent); } - return JS_UNDEFINED; + return JS_NULL; } static const JSCFunctionListEntry js_dmon_funcs[] = { diff --git a/source/qjs_enet.c b/source/qjs_enet.c index 9da8c046..4751415b 100644 --- a/source/qjs_enet.c +++ b/source/qjs_enet.c @@ -34,13 +34,13 @@ static void js_enet_peer_finalizer(JSRuntime *rt, JSValue val) static JSValue js_enet_initialize(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { if (enet_initialize() != 0) return JS_ThrowInternalError(ctx, "Error initializing ENet"); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_deinitialize(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { enet_deinitialize(); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_host_create(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -163,12 +163,12 @@ static JSValue js_enet_host_service(JSContext *ctx, JSValueConst this_val, int a break; } - uncaught_exception(ctx, JS_Call(ctx, callback, JS_UNDEFINED, 1, &event_obj)); + uncaught_exception(ctx, JS_Call(ctx, callback, JS_NULL, 1, &event_obj)); JS_FreeValue(ctx, event_obj); } JS_FreeValue(ctx, callback); - return JS_UNDEFINED; + return JS_NULL; } /* Host connect: client -> connect to server */ @@ -201,7 +201,7 @@ static JSValue js_enet_host_flush(JSContext *ctx, JSValueConst this_val, int arg ENetHost *host = JS_GetOpaque(this_val, enet_host_id); if (!host) return JS_EXCEPTION; enet_host_flush(host); - return JS_UNDEFINED; + return JS_NULL; } /* Broadcast a string or ArrayBuffer */ @@ -231,7 +231,7 @@ static JSValue js_enet_host_broadcast(JSContext *ctx, JSValueConst this_val, int if (!packet) return JS_ThrowInternalError(ctx, "Failed to create ENet packet"); enet_host_broadcast(host, 0, packet); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_host_get_port(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) @@ -264,7 +264,7 @@ static JSValue js_enet_peer_disconnect(JSContext *ctx, JSValueConst this_val, in ENetPeer *peer = JS_GetOpaque(this_val, enet_peer_class_id); if (!peer) return JS_EXCEPTION; enet_peer_disconnect(peer, 0); - return JS_UNDEFINED; + return JS_NULL; } /* Peer send must only accept string or ArrayBuffer */ @@ -294,7 +294,7 @@ static JSValue js_enet_peer_send(JSContext *ctx, JSValueConst this_val, int argc if (!packet) return JS_ThrowInternalError(ctx, "Failed to create ENet packet"); if (enet_peer_send(peer, 0, packet) < 0) return JS_ThrowInternalError(ctx, "Unable to send packet"); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_disconnect_now(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -302,7 +302,7 @@ static JSValue js_enet_peer_disconnect_now(JSContext *ctx, JSValueConst this_val ENetPeer *peer = JS_GetOpaque(this_val, enet_peer_class_id); if (!peer) return JS_EXCEPTION; enet_peer_disconnect_now(peer, 0); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_disconnect_later(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -310,7 +310,7 @@ static JSValue js_enet_peer_disconnect_later(JSContext *ctx, JSValueConst this_v ENetPeer *peer = JS_GetOpaque(this_val, enet_peer_class_id); if (!peer) return JS_EXCEPTION; enet_peer_disconnect_later(peer, 0); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_reset(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -318,7 +318,7 @@ static JSValue js_enet_peer_reset(JSContext *ctx, JSValueConst this_val, int arg ENetPeer *peer = JS_GetOpaque(this_val, enet_peer_class_id); if (!peer) return JS_EXCEPTION; enet_peer_reset(peer); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_ping(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -326,7 +326,7 @@ static JSValue js_enet_peer_ping(JSContext *ctx, JSValueConst this_val, int argc ENetPeer *peer = JS_GetOpaque(this_val, enet_peer_class_id); if (!peer) return JS_EXCEPTION; enet_peer_ping(peer); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_throttle_configure(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -339,7 +339,7 @@ static JSValue js_enet_peer_throttle_configure(JSContext *ctx, JSValueConst this return JS_ThrowTypeError(ctx, "Expected 3 int arguments: interval, acceleration, deceleration"); enet_peer_throttle_configure(peer, interval, acceleration, deceleration); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_enet_peer_timeout(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -352,7 +352,7 @@ static JSValue js_enet_peer_timeout(JSContext *ctx, JSValueConst this_val, int a return JS_ThrowTypeError(ctx, "Expected 3 integer arguments: timeout_limit, timeout_min, timeout_max"); enet_peer_timeout(peer, timeout_limit, timeout_min, timeout_max); - return JS_UNDEFINED; + return JS_NULL; } /* Class definitions */ @@ -372,7 +372,7 @@ JSValue js_enet_resolve_hostname(JSContext *js, JSValue self, int argc, JSValue // TODO: implement const char *hostname = JS_ToCString(js, argv[0]); JS_FreeCString(js, hostname); - return JS_UNDEFINED; + return JS_NULL; } /* Function lists */ diff --git a/source/qjs_fd.c b/source/qjs_fd.c index 2a63aa10..1f1f9d49 100644 --- a/source/qjs_fd.c +++ b/source/qjs_fd.c @@ -147,7 +147,7 @@ JSC_CCALL(fd_fsync, if (fsync(fd) != 0) return JS_ThrowReferenceError(js, "fsync failed: %s", strerror(errno)); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(fd_close, @@ -157,7 +157,7 @@ JSC_CCALL(fd_close, if (close(fd) != 0) return JS_ThrowReferenceError(js, "close failed: %s", strerror(errno)); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(fd_fstat, diff --git a/source/qjs_geometry.c b/source/qjs_geometry.c index bff791d4..feef2529 100644 --- a/source/qjs_geometry.c +++ b/source/qjs_geometry.c @@ -445,10 +445,10 @@ static BufferCheckResult get_or_extend_buffer( int copy, int index ) { - BufferCheckResult res = { JS_UNDEFINED, NULL, 0, 0 }; - if (!JS_IsUndefined(old_mesh)) { + BufferCheckResult res = { JS_NULL, NULL, 0, 0 }; + if (!JS_IsNull(old_mesh)) { JSValue old_buf = JS_GetPropertyStr(js, old_mesh, prop); - if (!JS_IsUndefined(old_buf)) { + if (!JS_IsNull(old_buf)) { size_t old_size; void *data = get_gpu_buffer(js, old_buf, NULL, &old_size); if (data && old_size >= needed_size) { @@ -520,7 +520,7 @@ JSC_CCALL(gpu_make_sprite_mesh, } // Check old mesh - JSValue old_mesh = JS_UNDEFINED; + JSValue old_mesh = JS_NULL; if (argc > 1) old_mesh = argv[1]; @@ -577,9 +577,9 @@ JSC_CCALL(gpu_make_sprite_mesh, free(colordata); // Free old buffer values if they were fetched - if (!JS_IsUndefined(pos_chk.val)) JS_FreeValue(js, pos_chk.val); - if (!JS_IsUndefined(uv_chk.val)) JS_FreeValue(js, uv_chk.val); - if (!JS_IsUndefined(color_chk.val)) JS_FreeValue(js, color_chk.val); + if (!JS_IsNull(pos_chk.val)) JS_FreeValue(js, pos_chk.val); + if (!JS_IsNull(uv_chk.val)) JS_FreeValue(js, uv_chk.val); + if (!JS_IsNull(color_chk.val)) JS_FreeValue(js, color_chk.val); return ret; ) @@ -685,11 +685,11 @@ JSC_CCALL(gpu_make_sprite_queue, rect uv; rect uv_px; - JSValue cur_img = JS_UNDEFINED; + JSValue cur_img = JS_NULL; for (size_t i = 0; i < quads; i++) { sprite *s = &sprites[i]; - if (JS_IsUndefined(cur_img) || !JS_StrictEq(js, s->image, cur_img)) { + if (JS_IsNull(cur_img) || !JS_StrictEq(js, s->image, cur_img)) { cur_img = s->image; JS_GETATOM(js, uv, cur_img, rect, rect) JS_GETATOM(js, uv_px, cur_img, rect_px, rect) @@ -732,7 +732,7 @@ JSC_CCALL(gpu_make_sprite_queue, int first_index = 0; int count = 0; int n = 0; - JSValue img = JS_UNDEFINED; + JSValue img = JS_NULL; for (int i = 0; i < quads; i++) { if (!JS_SameValue(js, sprites[i].image, img)) { @@ -832,7 +832,7 @@ JSC_CCALL(geometry_tilemap_to_data, int col_len = JS_ArrayLength(js, col); for (int y = 0; y < col_len; y++) { JSValue tile = JS_GetPropertyUint32(js, col, y); - if (!JS_IsUndefined(tile) && !JS_IsNull(tile)) { + if (!JS_IsNull(tile) && !JS_IsNull(tile)) { tile_count++; } JS_FreeValue(js, tile); @@ -865,7 +865,7 @@ JSC_CCALL(geometry_tilemap_to_data, int col_len = JS_ArrayLength(js, col); for (int y = 0; y < col_len; y++) { JSValue tile = JS_GetPropertyUint32(js, col, y); - if (!JS_IsUndefined(tile) && !JS_IsNull(tile)) { + if (!JS_IsNull(tile) && !JS_IsNull(tile)) { // Calculate world position float world_x = (x + offset_x) * size_x; float world_y = (y + offset_y) * size_y; @@ -895,7 +895,7 @@ JSC_CCALL(geometry_tilemap_to_data, SDL_FColor default_color = {1.0f, 1.0f, 1.0f, 1.0f}; if (JS_IsObject(tile)) { JSValue color_val = JS_GetPropertyStr(js, tile, "color"); - if (!JS_IsUndefined(color_val)) { + if (!JS_IsNull(color_val)) { HMM_Vec4 color = js2color(js, color_val); default_color.r = color.r; default_color.g = color.g; diff --git a/source/qjs_imgui.cpp b/source/qjs_imgui.cpp index 93059ff9..ababd01d 100644 --- a/source/qjs_imgui.cpp +++ b/source/qjs_imgui.cpp @@ -106,38 +106,38 @@ JSC_CCALL(imgui_window, const char *str = JS_ToCString(js,argv[0]); bool active = true; ImGui::Begin(str, &active); - JS_Call(js, argv[1], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[1], JS_NULL, 0, NULL); ImGui::End(); JS_FreeCString(js,str); return JS_NewBool(js,active); ) JSC_SCALL(imgui_menu, if (ImGui::BeginMenu(str)) { - JS_Call(js, argv[1], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[1], JS_NULL, 0, NULL); ImGui::EndMenu(); } ) JSC_CCALL(imgui_menubar, if (ImGui::BeginMenuBar()) { - JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[0], JS_NULL, 0, NULL); ImGui::EndMenuBar(); } ) JSC_CCALL(imgui_mainmenubar, if (ImGui::BeginMainMenuBar()) { - JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[0], JS_NULL, 0, NULL); ImGui::EndMainMenuBar(); } ) JSC_CCALL(imgui_menuitem, const char *name = JS_ToCString(js,argv[0]); - const char *keyfn = JS_IsUndefined(argv[1]) ? NULL : JS_ToCString(js,argv[1]); - bool on = JS_IsUndefined(argv[3]) ? false : JS_ToBool(js,argv[3]); + const char *keyfn = JS_IsNull(argv[1]) ? NULL : JS_ToCString(js,argv[1]); + bool on = JS_IsNull(argv[3]) ? false : JS_ToBool(js,argv[3]); if (ImGui::MenuItem(JS_ToBool(js,argv[0]) ? name : "##empty" ,keyfn, &on)) - JS_Call(js, argv[2], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[2], JS_NULL, 0, NULL); if (!JS_IsNull(argv[0])) JS_FreeCString(js,name); if (keyfn) JS_FreeCString(js,keyfn); @@ -147,7 +147,7 @@ JSC_CCALL(imgui_menuitem, JSC_SCALL(imgui_plot, if (ImPlot::BeginPlot(str)) { - JS_Call(js, argv[1], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[1], JS_NULL, 0, NULL); ImPlot::EndPlot(); } ) @@ -173,7 +173,7 @@ void fill_plotdata(JSContext *js, JSValue v, JSValue last) else { // Fill it with the x axis being the array index for (int i = 0; i < JS_ArrayLength(js, v); i++) { - if (JS_IsUndefined(js_getpropidx(v,i))) continue; + if (JS_IsNull(js_getpropidx(v,i))) continue; ImVec2 c; c.x = i; c.y = js2number(js, js_getpropidx(v,i)); @@ -181,7 +181,7 @@ void fill_plotdata(JSContext *js, JSValue v, JSValue last) } } - if (!JS_IsUndefined(last)) { + if (!JS_IsNull(last)) { int frame = js2number(js, last); ImVec2 c = js2vec2(js,last); c.y = arrlast(plotdata).y; @@ -195,7 +195,7 @@ PLOT_FN(stairplot, PlotStairs,,ImPlotStairsFlags_Shaded) PLOT_FN(digitalplot, PlotDigital,,0) JSC_SCALL(imgui_barplot, - fill_plotdata(js, argv[1], JS_UNDEFINED); + fill_plotdata(js, argv[1], JS_NULL); ImPlot::PlotBars(str, &plotdata[0].x, &plotdata[0].y, JS_ArrayLength(js, argv[1]), js2number(js, argv[2]), 0, 0, sizeof(ImVec2)); ) @@ -243,7 +243,7 @@ JSC_CCALL(imgui_fitaxis, JSC_SSCALL(imgui_textinput, char buffer[512]; - if (JS_IsUndefined(argv[1])) + if (JS_IsNull(argv[1])) buffer[0] = 0; else strncpy(buffer, str2, sizeof(buffer)-1); @@ -257,7 +257,7 @@ JSC_SSCALL(imgui_textinput, JSC_SSCALL(imgui_textbox, char buffer[512]; - if (JS_IsUndefined(argv[1])) + if (JS_IsNull(argv[1])) buffer[0] = 0; else strncpy(buffer, str2, sizeof(buffer)-1); @@ -273,12 +273,12 @@ JSC_SCALL(imgui_text, ImGui::Text("%s", str) ) JSC_SCALL(imgui_button, if (ImGui::Button(str)) - JS_Call(js, argv[1], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[1], JS_NULL, 0, NULL); ) JSC_SCALL(imgui_slider, -/* float low = JS_IsUndefined(argv[2]) ? 0.0 : js2number(js, argv[2]); - float high = JS_IsUndefined(argv[3]) ? 1.0 : js2number(js, argv[3]); +/* float low = JS_IsNull(argv[2]) ? 0.0 : js2number(js, argv[2]); + float high = JS_IsNull(argv[3]) ? 1.0 : js2number(js, argv[3]); if (JS_IsArray(js, argv[1])) { int n = JS_ArrayLength(js, argv[1]); @@ -306,8 +306,8 @@ JSC_SCALL(imgui_slider, ) JSC_SCALL(imgui_intslider, - int low = JS_IsUndefined(argv[2]) ? 0.0 : js2number(js, argv[2]); - int high = JS_IsUndefined(argv[3]) ? 1.0 : js2number(js, argv[3]); + int low = JS_IsNull(argv[2]) ? 0.0 : js2number(js, argv[2]); + int high = JS_IsNull(argv[3]) ? 1.0 : js2number(js, argv[3]); JSValue arr = JS_NewTypedArray(js, 1, &argv[1], JS_TYPED_ARRAY_INT32); size_t len; @@ -353,7 +353,7 @@ JSC_CCALL(imgui_image, JSC_SCALL(imgui_imagebutton, SDL_GPUTexture *tex = js2SDL_GPUTexture(js,argv[1]); if (ImGui::ImageButton(str, (ImTextureID)tex, ImVec2(100, 100))) - JS_Call(js, argv[2], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[2], JS_NULL, 0, NULL); ) JSC_CCALL(imgui_sameline, ImGui::SameLine(js2number(js, argv[0])) ) @@ -364,21 +364,21 @@ JSC_SCALL(imgui_radio, ret = JS_NewBool(js,ImGui::RadioButton(str, JS_ToBool(js, JSC_SCALL(imgui_tree, if (ImGui::TreeNode(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::TreePop(); } ) JSC_SCALL(imgui_tabbar, if (ImGui::BeginTabBar(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::EndTabBar(); } ) JSC_SCALL(imgui_tab, if (ImGui::BeginTabItem(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::EndTabItem(); } ) @@ -407,7 +407,7 @@ JSC_SCALL(imgui_open_popup, JSC_SCALL(imgui_popup, if (ImGui::BeginPopup(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::EndPopup(); } ) @@ -418,14 +418,14 @@ JSC_CCALL(imgui_close_popup, JSC_SCALL(imgui_modal, if (ImGui::BeginPopupModal(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::EndPopup(); } ) JSC_SCALL(imgui_context, if (ImGui::BeginPopupContextItem(str)) { - JS_Call(js, argv[1],JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1],JS_NULL, 0,NULL); ImGui::EndPopup(); } ) @@ -433,11 +433,11 @@ JSC_SCALL(imgui_context, JSC_SCALL(imgui_table, int flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingStretchProp; bool sort = false; - if (!JS_IsUndefined(argv[3])) sort = true; + if (!JS_IsNull(argv[3])) sort = true; if (sort) flags |= ImGuiTableFlags_Sortable; if (ImGui::BeginTable(str, js2number(js, argv[1]), flags)) { - JS_Call(js, argv[2], JS_UNDEFINED, 0, NULL); + JS_Call(js, argv[2], JS_NULL, 0, NULL); if (sort) { ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs(); @@ -448,7 +448,7 @@ JSC_SCALL(imgui_table, JSValue send[2]; send[0] = JS_NewInt32(js,spec->ColumnIndex); send[1] = JS_NewBool(js,spec->SortDirection == ImGuiSortDirection_Ascending); - JS_Call(js, argv[3], JS_UNDEFINED, 2, send); + JS_Call(js, argv[3], JS_NULL, 2, send); JS_FreeValue(js, send[0]); JS_FreeValue(js, send[1]); } @@ -470,7 +470,7 @@ JSC_SCALL(imgui_dnd, if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) { double n = js2number(js, argv[1]); ImGui::SetDragDropPayload(str, &n, sizeof(n)); -// JS_Call(js, argv[2], JS_UNDEFINED, 2, send); +// JS_Call(js, argv[2], JS_NULL, 2, send); ImGui::EndDragDropSource(); } ) @@ -479,7 +479,7 @@ JSC_SCALL(imgui_dndtarget, if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(str)) { JSValue n = JS_NewFloat64(js,*(double*)payload->Data); - JS_Call(js, argv[1], JS_UNDEFINED, 1, &n); + JS_Call(js, argv[1], JS_NULL, 1, &n); } ImGui::EndDragDropTarget(); } @@ -500,7 +500,7 @@ JSC_SCALL(imgui_color, JSC_CCALL(imgui_startnode, ImNodes::BeginNodeEditor(); - JS_Call(js, argv[0], JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[0], JS_NULL, 0,NULL); ImNodes::EndNodeEditor(); int start_attr; int end_attr; @@ -509,7 +509,7 @@ JSC_CCALL(imgui_startnode, JSValue ab[2]; ab[0] = JS_NewInt32(js,start_attr); ab[1] = JS_NewInt32(js,end_attr); - JS_Call(js,argv[1], JS_UNDEFINED, 2, ab); + JS_Call(js,argv[1], JS_NULL, 2, ab); for (int i = 0; i < 2; i++) JS_FreeValue(js, ab[i]); } @@ -518,7 +518,7 @@ JSC_CCALL(imgui_startnode, if (ImNodes::IsNodeHovered(&node_id)) { JSValue a = JS_NewInt32(js,node_id); - JS_Call(js, argv[2], JS_UNDEFINED, 1,&a); + JS_Call(js, argv[2], JS_NULL, 1,&a); JS_FreeValue(js,a); } @@ -526,26 +526,26 @@ JSC_CCALL(imgui_startnode, if (ImNodes::IsLinkHovered(&link_id)) { JSValue a = JS_NewInt32(js,link_id); - JS_Call(js, argv[3], JS_UNDEFINED, 1,&a); + JS_Call(js, argv[3], JS_NULL, 1,&a); JS_FreeValue(js,a); } ) JSC_CCALL(imgui_node, ImNodes::BeginNode(js2number(js, argv[0])); - JS_Call(js, argv[1], JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1], JS_NULL, 0,NULL); ImNodes::EndNode(); ) JSC_CCALL(imgui_nodein, ImNodes::BeginInputAttribute(js2number(js, argv[0])); - JS_Call(js, argv[1], JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1], JS_NULL, 0,NULL); ImNodes::EndInputAttribute(); ) JSC_CCALL(imgui_nodeout, ImNodes::BeginOutputAttribute(js2number(js, argv[0])); - JS_Call(js, argv[1], JS_UNDEFINED, 0,NULL); + JS_Call(js, argv[1], JS_NULL, 0,NULL); ImNodes::EndOutputAttribute(); ) @@ -681,7 +681,7 @@ static JSValue axis_fmts[10]; void jsformatter(double value, char *buff, int size, JSValue *fmt) { /* JSValue v = JS_NewFloat64(js,value); - const char *str = JS_ToCString(js, JS_Call(js,*fmt, JS_UNDEFINED, 1, &v)); + const char *str = JS_ToCString(js, JS_Call(js,*fmt, JS_NULL, 1, &v)); strncpy(buff,str, size); JS_FreeCString(js, str);*/ } @@ -689,9 +689,9 @@ void jsformatter(double value, char *buff, int size, JSValue *fmt) JSC_CCALL(imgui_axisfmt, int y = num_to_yaxis(js2number(js, argv[0])); - if (!JS_IsUndefined(axis_fmts[y])) { + if (!JS_IsNull(axis_fmts[y])) { JS_FreeValue(js, axis_fmts[y]); - axis_fmts[y] = JS_UNDEFINED; + axis_fmts[y] = JS_NULL; } axis_fmts[y] = JS_DupValue(js,argv[1]); diff --git a/source/qjs_io.c b/source/qjs_io.c index b3104609..3ffbbce2 100644 --- a/source/qjs_io.c +++ b/source/qjs_io.c @@ -159,14 +159,14 @@ JSC_SCALL(io_slurpwrite, JSC_CCALL(io_mount, const char *src = JS_ToCString(js, argv[0]); const char *mountpoint; - if (JS_IsUndefined(argv[1])) + if (JS_IsNull(argv[1])) mountpoint = NULL; else mountpoint = JS_ToCString(js, argv[1]); int prepend = 0; - if (argc > 2 && !JS_IsUndefined(argv[2])) + if (argc > 2 && !JS_IsNull(argv[2])) prepend = JS_ToBool(js, argv[2]); if (!PHYSFS_mount(src, mountpoint, prepend)) @@ -274,7 +274,7 @@ JSC_CCALL(io_globfs, data.globs = globs; const char *path = NULL; - if (!JS_IsUndefined(argv[1])) path = JS_ToCString(js,argv[1]); + if (!JS_IsNull(argv[1])) path = JS_ToCString(js,argv[1]); PHYSFS_enumerate(path, globfs_cb, &data); for (int i = 0; i < globs_len; i++) @@ -297,7 +297,7 @@ JSC_SCALL(io_enumerate, data.globs = NULL; /* not used here */ data.recurse = 0; - if (!JS_IsUndefined(argv[1])) /* parse second arg if provided */ + if (!JS_IsNull(argv[1])) /* parse second arg if provided */ data.recurse = JS_ToBool(js, argv[1]); /* Enumerate the directory given by 'str'. */ @@ -322,7 +322,7 @@ JSC_SCALL(io_open, JSC_SCALL(io_realdir, const char *real = PHYSFS_getRealDir(str); if (!real) - ret = JS_UNDEFINED; + ret = JS_NULL; else ret = JS_NewString(js,real); ) diff --git a/source/qjs_macros.h b/source/qjs_macros.h index dbea403a..7b8218f2 100644 --- a/source/qjs_macros.h +++ b/source/qjs_macros.h @@ -5,13 +5,13 @@ #define JS_SETSIG JSContext *js, JSValue self, JSValue val #define JSC_CCALL(NAME, ...) static JSValue js_##NAME (JSContext *js, JSValue self, int argc, JSValue *argv) { \ - JSValue ret = JS_UNDEFINED; \ + JSValue ret = JS_NULL; \ __VA_ARGS__ ;\ return ret; \ } #define JSC_CCALL_EXTERN(NAME, ...) JSValue js_##NAME (JSContext *js, JSValue self, int argc, JSValue *argv) { \ - JSValue ret = JS_UNDEFINED; \ + JSValue ret = JS_NULL; \ __VA_ARGS__ ;\ return ret; \ } @@ -25,8 +25,8 @@ #define JSC_SSCALL(NAME, ...) JSC_CCALL(NAME, \ const char *str = NULL; \ const char *str2 = NULL; \ - if (!JS_IsUndefined(argv[0])) str = JS_ToCString(js,argv[0]); \ - if (!JS_IsUndefined(argv[1])) str2 = JS_ToCString(js,argv[1]); \ + if (!JS_IsNull(argv[0])) str = JS_ToCString(js,argv[0]); \ + if (!JS_IsNull(argv[1])) str2 = JS_ToCString(js,argv[1]); \ __VA_ARGS__ ; \ JS_FreeCString(js,str2); \ JS_FreeCString(js,str); \ @@ -41,21 +41,21 @@ #define CGETSET_ADD(ID, ENTRY) MIST_CGETSET_DEF(#ENTRY, js_##ID##_get_##ENTRY, js_##ID##_set_##ENTRY) #define CGETSET_ADD_HID(ID, ENTRY) MIST_CGETSET_BASE(#ENTRY, js_##ID##_get_##ENTRY, js_##ID##_set_##ENTRY, JS_PROP_CONFIGURABLE) -#define JSC_DCALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(); return JS_UNDEFINED; } +#define JSC_DCALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(); return JS_NULL; } -#define JSC_1CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0])); return JS_UNDEFINED; } -#define JSC_2CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1])); return JS_UNDEFINED; } -#define JSC_3CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2])); return JS_UNDEFINED; } -#define JSC_4CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3])); return JS_UNDEFINED; } -#define JSC_5CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4])); return JS_UNDEFINED; } -#define JSC_6CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4]), js2number(js,argv[5])); return JS_UNDEFINED; } -#define JSC_7CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4]), js2number(js,argv[5]), js2number(js,argv[6])); return JS_UNDEFINED; } +#define JSC_1CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0])); return JS_NULL; } +#define JSC_2CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1])); return JS_NULL; } +#define JSC_3CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2])); return JS_NULL; } +#define JSC_4CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3])); return JS_NULL; } +#define JSC_5CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4])); return JS_NULL; } +#define JSC_6CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4]), js2number(js,argv[5])); return JS_NULL; } +#define JSC_7CALL(FN) JSValue js_##FN (JSContext *js, JSValue self, int argc, JSValue *argv) { FN(js2number(js,argv[0]), js2number(js,argv[1]), js2number(js,argv[2]), js2number(js,argv[3]), js2number(js,argv[4]), js2number(js,argv[5]), js2number(js,argv[6])); return JS_NULL; } #define GETSETPAIR(ID, ENTRY, TYPE, FN) \ JSValue js_##ID##_set_##ENTRY (JS_SETSIG) { \ js2##ID (js, self)->ENTRY = js2##TYPE (js,val); \ {FN;} \ - return JS_UNDEFINED; \ + return JS_NULL; \ } \ \ JSValue js_##ID##_get_##ENTRY (JSContext *js, JSValue self) { \ @@ -67,9 +67,9 @@ JSValue js_##ID##_get_##ENTRY (JSContext *js, JSValue self) { \ #define JSC_GETSET_CALLBACK(ID, ENTRY) \ JSValue js_##ID##_set_##ENTRY (JS_SETSIG) { \ JSValue fn = js2##ID (js, self)->ENTRY; \ - if (!JS_IsUndefined(fn)) JS_FreeValue(js, fn); \ + if (!JS_IsNull(fn)) JS_FreeValue(js, fn); \ js2##ID (js, self)->ENTRY = JS_DupValue(js, val); \ - return JS_UNDEFINED; \ + return JS_NULL; \ }\ JSValue js_##ID##_get_##ENTRY (JSContext *js, JSValue self) { return JS_DupValue(js, js2##ID (js, self)->ENTRY); } \ diff --git a/source/qjs_math.c b/source/qjs_math.c index c071806c..76e07d67 100644 --- a/source/qjs_math.c +++ b/source/qjs_math.c @@ -68,7 +68,7 @@ static int gcd(int a, int b) { JSC_CCALL(math_rotate, HMM_Vec2 vec = js2vec2(js,argv[0]); double angle = js2angle(js, argv[1]); - HMM_Vec2 pivot = JS_IsUndefined(argv[2]) ? v2zero : js2vec2(js,argv[2]); + HMM_Vec2 pivot = JS_IsNull(argv[2]) ? v2zero : js2vec2(js,argv[2]); vec = HMM_SubV2(vec,pivot); float r = HMM_LenV2(vec); @@ -254,7 +254,7 @@ JSC_CCALL(math_project, if (!a || !b) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } // We'll work up to the smaller length @@ -262,7 +262,7 @@ JSC_CCALL(math_project, if (len == 0) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } // Compute dot products: a·b and b·b @@ -299,14 +299,14 @@ JSC_CCALL(math_midpoint, if (!a || !b) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } size_t len = (alen < blen) ? alen : blen; if (len == 0) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } float *m = (float*)malloc(sizeof(float) * len); @@ -334,14 +334,14 @@ JSC_CCALL(math_reflect, if (!a || !b) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } size_t len = (alen < blen) ? alen : blen; if (len == 0) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } // Reflect vector a across normal b @@ -378,14 +378,14 @@ JSC_CCALL(math_direction, if (!a || !b) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } size_t len = (alen < blen) ? alen : blen; if (len == 0) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } // Direction vector from a to b (normalized) @@ -421,7 +421,7 @@ JSC_CCALL(math_angle, if (!v || len < 2) { free(v); - return JS_UNDEFINED; + return JS_NULL; } // Return angle in radians for 2D vector @@ -438,14 +438,14 @@ JSC_CCALL(math_distance, if (!a || !b) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } size_t len = (alen < blen) ? alen : blen; if (len == 0) { free(a); free(b); - return JS_UNDEFINED; + return JS_NULL; } float distSq = 0.0f; diff --git a/source/qjs_miniz.c b/source/qjs_miniz.c index 6d1b9094..f6cb2f8a 100644 --- a/source/qjs_miniz.c +++ b/source/qjs_miniz.c @@ -210,7 +210,7 @@ JSValue js_writer_add_file(JSContext *js, JSValue self, int argc, JSValue *argv) if (!success) return JS_ThrowInternalError(js, "Failed to add memory to zip"); - return JS_UNDEFINED; + return JS_NULL; } diff --git a/source/qjs_nota.c b/source/qjs_nota.c index c518f422..dae1a7a6 100755 --- a/source/qjs_nota.c +++ b/source/qjs_nota.c @@ -44,7 +44,7 @@ static int nota_stack_has(NotaEncodeContext *enc, JSValueConst val) } static JSValue apply_replacer(NotaEncodeContext *enc, JSValueConst holder, JSValueConst key, JSValueConst val) { - if (JS_IsUndefined(enc->replacer)) return JS_DupValue(enc->ctx, val); + if (JS_IsNull(enc->replacer)) return JS_DupValue(enc->ctx, val); JSValue args[2] = { JS_DupValue(enc->ctx, key), JS_DupValue(enc->ctx, val) }; JSValue result = JS_Call(enc->ctx, enc->replacer, holder, 2, args); @@ -103,17 +103,17 @@ char *js_do_nota_decode(JSContext *js, JSValue *tmp, char *nota, JSValue holder, nota = nota_read_sym(&b, nota); if (b == NOTA_PRIVATE) { JSValue inner; - nota = js_do_nota_decode(js, &inner, nota, holder, JS_UNDEFINED, reviver); + nota = js_do_nota_decode(js, &inner, nota, holder, JS_NULL, reviver); JSValue obj = JS_NewObject(js); cell_rt *crt = JS_GetContextOpaque(js); JS_SetProperty(js, obj, crt->actor_sym, inner); *tmp = obj; } else { switch(b) { - case NOTA_NULL: *tmp = JS_UNDEFINED; break; + case NOTA_NULL: *tmp = JS_NULL; break; case NOTA_FALSE: *tmp = JS_NewBool(js, 0); break; case NOTA_TRUE: *tmp = JS_NewBool(js, 1); break; - default: *tmp = JS_UNDEFINED; break; + default: *tmp = JS_NULL; break; } } break; @@ -124,7 +124,7 @@ char *js_do_nota_decode(JSContext *js, JSValue *tmp, char *nota, JSValue holder, break; } - if (!JS_IsUndefined(reviver)) { + if (!JS_IsNull(reviver)) { JSValue args[2] = { JS_DupValue(js, key), JS_DupValue(js, *tmp) }; JSValue revived = JS_Call(js, reviver, holder, 2, args); JS_FreeValue(js, args[0]); @@ -170,7 +170,6 @@ static void nota_encode_value(NotaEncodeContext *enc, JSValueConst val, JSValueC else nota_write_sym(&enc->nb, NOTA_FALSE); break; case JS_TAG_NULL: - case JS_TAG_UNDEFINED: nota_write_sym(&enc->nb, NOTA_NULL); break; case JS_TAG_OBJECT: { @@ -202,9 +201,9 @@ static void nota_encode_value(NotaEncodeContext *enc, JSValueConst val, JSValueC cell_rt *crt = JS_GetContextOpaque(ctx); JSValue adata = JS_GetProperty(ctx, replaced, crt->actor_sym); - if (!JS_IsUndefined(adata)) { + if (!JS_IsNull(adata)) { nota_write_sym(&enc->nb, NOTA_PRIVATE); - nota_encode_value(enc, adata, replaced, JS_UNDEFINED); + nota_encode_value(enc, adata, replaced, JS_NULL); JS_FreeValue(ctx, adata); break; } @@ -275,10 +274,10 @@ void *value2nota(JSContext *ctx, JSValue v) { enc->ctx = ctx; enc->visitedStack = JS_NewArray(ctx); enc->cycle = 0; - enc->replacer = JS_UNDEFINED; + enc->replacer = JS_NULL; nota_buffer_init(&enc->nb, 128); - nota_encode_value(enc, v, JS_UNDEFINED, JS_NewString(ctx, "")); + nota_encode_value(enc, v, JS_NULL, JS_NewString(ctx, "")); if (enc->cycle) { JS_FreeValue(ctx, enc->visitedStack); @@ -294,10 +293,10 @@ void *value2nota(JSContext *ctx, JSValue v) { } JSValue nota2value(JSContext *js, void *nota) { - if (!nota) return JS_UNDEFINED; + if (!nota) return JS_NULL; JSValue ret; JSValue holder = JS_NewObject(js); - js_do_nota_decode(js, &ret, nota, holder, JS_NewString(js, ""), JS_UNDEFINED); + js_do_nota_decode(js, &ret, nota, holder, JS_NewString(js, ""), JS_NULL); JS_FreeValue(js, holder); return ret; } @@ -309,10 +308,10 @@ static JSValue js_nota_encode(JSContext *ctx, JSValueConst this_val, int argc, J enc->ctx = ctx; enc->visitedStack = JS_NewArray(ctx); enc->cycle = 0; - enc->replacer = (argc > 1 && JS_IsFunction(ctx, argv[1])) ? argv[1] : JS_UNDEFINED; + enc->replacer = (argc > 1 && JS_IsFunction(ctx, argv[1])) ? argv[1] : JS_NULL; nota_buffer_init(&enc->nb, 128); - nota_encode_value(enc, argv[0], JS_UNDEFINED, JS_NewString(ctx, "")); + nota_encode_value(enc, argv[0], JS_NULL, JS_NewString(ctx, "")); if (enc->cycle) { JS_FreeValue(ctx, enc->visitedStack); @@ -330,13 +329,13 @@ static JSValue js_nota_encode(JSContext *ctx, JSValueConst this_val, int argc, J } static JSValue js_nota_decode(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) { - if (argc < 1) return JS_UNDEFINED; + if (argc < 1) return JS_NULL; size_t len; unsigned char *nota = js_get_blob_data(js, &len, argv[0]); - if (!nota) return JS_UNDEFINED; + if (!nota) return JS_NULL; - JSValue reviver = (argc > 1 && JS_IsFunction(js, argv[1])) ? argv[1] : JS_UNDEFINED; + JSValue reviver = (argc > 1 && JS_IsFunction(js, argv[1])) ? argv[1] : JS_NULL; JSValue ret; JSValue holder = JS_NewObject(js); js_do_nota_decode(js, &ret, (char*)nota, holder, JS_NewString(js, ""), reviver); diff --git a/source/qjs_num.c b/source/qjs_num.c index 533a74ec..55d0d8e3 100644 --- a/source/qjs_num.c +++ b/source/qjs_num.c @@ -533,7 +533,7 @@ static JSValue js_array_slice(JSContext *js, JSValueConst self, int argc, JSValu int32_t end = arr->size; // Parse start argument - if (argc >= 1 && !JS_IsUndefined(argv[0])) { + if (argc >= 1 && !JS_IsNull(argv[0])) { if (JS_ToInt32(js, &start, argv[0])) return JS_EXCEPTION; @@ -547,7 +547,7 @@ static JSValue js_array_slice(JSContext *js, JSValueConst self, int argc, JSValu } // Parse end argument - if (argc >= 2 && !JS_IsUndefined(argv[1])) { + if (argc >= 2 && !JS_IsNull(argv[1])) { if (JS_ToInt32(js, &end, argv[1])) return JS_EXCEPTION; diff --git a/source/qjs_os.c b/source/qjs_os.c index d5452f6d..8d354cc9 100644 --- a/source/qjs_os.c +++ b/source/qjs_os.c @@ -56,7 +56,7 @@ JSC_CCALL(os_totalmem, return number2js(js, SDL_GetSystemRAM())) JSC_CCALL(os_platform, return JS_NewString(js,SDL_GetPlatform())) static JSValue js_os_hostname(JSContext *js, JSValue self, int argc, JSValue *argv) { - JSValue ret = JS_UNDEFINED; + JSValue ret = JS_NULL; #ifdef _WIN32 TCHAR buffer[256] = TEXT(""); DWORD size = sizeof(buffer) / sizeof(TCHAR); @@ -71,7 +71,7 @@ static JSValue js_os_hostname(JSContext *js, JSValue self, int argc, JSValue *ar } static JSValue js_os_arch(JSContext *js, JSValue self, int argc, JSValue *argv) { - JSValue ret = JS_UNDEFINED; + JSValue ret = JS_NULL; #if defined(__x86_64__) || defined(_M_X64) return JS_NewString(js,"x64"); #elif defined(__aarch64__) || defined(_M_ARM64) @@ -99,7 +99,7 @@ static JSValue js_os_arch(JSContext *js, JSValue self, int argc, JSValue *argv) } static JSValue js_os_freemem(JSContext *js, JSValue self, int argc, JSValue *argv) { - JSValue ret = JS_UNDEFINED; + JSValue ret = JS_NULL; #ifdef _WIN32 MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); @@ -126,7 +126,7 @@ static JSValue js_os_freemem(JSContext *js, JSValue self, int argc, JSValue *arg } static JSValue js_os_version(JSContext *js, JSValue self, int argc, JSValue *argv) { - JSValue ret = JS_UNDEFINED; + JSValue ret = JS_NULL; #ifdef _WIN32 typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); HMODULE h = GetModuleHandleA("ntdll.dll"); @@ -200,7 +200,7 @@ JS_SetPropertyStr(js, OBJ, #FIELD, TYPE##2js(js,STRUCT.FIELD));\ #define JSJMEMRET(FIELD) JSOBJ_ADD_FIELD(ret, jsmem, FIELD, number) JSC_CCALL(os_mallinfo, - ret = JS_UNDEFINED; + ret = JS_NULL; /*struct mallinfo jsmem = mallinfo(); ret = JS_NewObject(js); JSJMEMRET(arena); @@ -216,7 +216,7 @@ JSC_CCALL(os_mallinfo, ) static JSValue js_os_rusage(JSContext *js, JSValue self, int argc, JSValue *argv) { - JSValue ret = JS_UNDEFINED; + JSValue ret = JS_NULL; ret = JS_NewObject(js); #ifndef _WIN32 @@ -244,12 +244,12 @@ static JSValue js_os_rusage(JSContext *js, JSValue self, int argc, JSValue *argv #ifdef TRACY_ENABLE #include JSC_CCALL(os_frame, - if (!tracy_profiling_enabled) return JS_UNDEFINED; + if (!tracy_profiling_enabled) return JS_NULL; TracyCFrameMark ) JSC_CCALL(os_trace_img, - if (!tracy_profiling_enabled) return JS_UNDEFINED; + if (!tracy_profiling_enabled) return JS_NULL; size_t len; double width, height; JS_ToFloat64(js,&width,argv[1]); @@ -258,7 +258,7 @@ JSC_CCALL(os_trace_img, ) JSC_CCALL(os_trace_message, - if (!tracy_profiling_enabled) return JS_UNDEFINED; + if (!tracy_profiling_enabled) return JS_NULL; size_t len; const char *str = JS_ToCStringLen(js, &len, argv[0]); TracyCMessage(str,len); diff --git a/source/qjs_qr.c b/source/qjs_qr.c index c489dfa5..d7d0d915 100644 --- a/source/qjs_qr.c +++ b/source/qjs_qr.c @@ -24,11 +24,11 @@ static JSValue js_qr_encode(JSContext *js, JSValueConst this_val, int argc, JSVa int use_byte_mode = 0; // Handle options object (argv[1]) - if (argc > 1 && !JS_IsUndefined(argv[1]) && JS_IsObject(argv[1])) { + if (argc > 1 && !JS_IsNull(argv[1]) && JS_IsObject(argv[1])) { JSValue opt = argv[1]; JSValue m = JS_GetPropertyStr(js, opt, "mode"); - if (!JS_IsUndefined(m)) { + if (!JS_IsNull(m)) { const char *smode = JS_ToCString(js, m); if (!smode) { JS_FreeValue(js, m); return JS_EXCEPTION; } if (!strcasecmp(smode, "byte") || !strcasecmp(smode, "binary")) @@ -45,7 +45,7 @@ static JSValue js_qr_encode(JSContext *js, JSValueConst this_val, int argc, JSVa // Version (1-40) JSValue v = JS_GetPropertyStr(js, opt, "version"); - if (!JS_IsUndefined(v)) { + if (!JS_IsNull(v)) { int32_t ver; if (JS_ToInt32(js, &ver, v) || ver < 0 || ver > 40) { JS_FreeValue(js, v); @@ -57,7 +57,7 @@ static JSValue js_qr_encode(JSContext *js, JSValueConst this_val, int argc, JSVa // Error correction level ("l", "m", "q", "h") JSValue l = JS_GetPropertyStr(js, opt, "level"); - if (!JS_IsUndefined(l)) { + if (!JS_IsNull(l)) { const char *level = JS_ToCString(js, l); if (!level) { JS_FreeValue(js, l); @@ -78,7 +78,7 @@ static JSValue js_qr_encode(JSContext *js, JSValueConst this_val, int argc, JSVa // Case sensitivity (true/false) JSValue ci = JS_GetPropertyStr(js, opt, "caseinsensitive"); - if (!JS_IsUndefined(ci)) { + if (!JS_IsNull(ci)) { int bool_val; if (JS_ToBool(js, ci)) { bool_val = 0; // qrencode: 0 = case-insensitive @@ -239,7 +239,7 @@ static JSValue js_qr_rgba(JSContext *js, JSValueConst self, int argc, JSValueCon if (argc > 2) JS_ToUint32(js, &off, argv[2]); JSValue js_w = JS_GetPropertyStr(js, mods, "width"); - if (JS_IsUndefined(js_w)) { + if (JS_IsNull(js_w)) { JS_FreeValue(js, js_w); return JS_ThrowTypeError(js, "mods.width missing"); } diff --git a/source/qjs_renderer.c b/source/qjs_renderer.c index 618834e5..20b58c88 100644 --- a/source/qjs_renderer.c +++ b/source/qjs_renderer.c @@ -48,7 +48,7 @@ JSC_CCALL(SDL_Renderer_draw_color, JSC_CCALL(SDL_Renderer_rect, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { colorf color = js2color(js,argv[1]); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); } @@ -62,7 +62,7 @@ JSC_CCALL(SDL_Renderer_rect, JS_FreeValue(js,val); } SDL_RenderRects(r,rects,len); - return JS_UNDEFINED; + return JS_NULL; } rect rect = js2rect(js,argv[0]); @@ -85,7 +85,7 @@ JSC_CCALL(renderer_load_texture, JSC_CCALL(SDL_Renderer_fillrect, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { colorf color = js2color(js,argv[1]); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); } @@ -112,12 +112,12 @@ JSC_CCALL(renderer_texture, SDL_Texture *tex = js2SDL_Texture(js,argv[0]); rect dst = transform_rect(js2rect(js,argv[1]), &cam_mat); - if (!JS_IsUndefined(argv[3])) { + if (!JS_IsNull(argv[3])) { colorf color = js2color(js,argv[3]); SDL_SetTextureColorModFloat(tex, color.r, color.g, color.b); SDL_SetTextureAlphaModFloat(tex,color.a); } - if (JS_IsUndefined(argv[2])) + if (JS_IsNull(argv[2])) SDL_RenderTexture(renderer,tex,NULL,&dst); else { @@ -137,7 +137,7 @@ JSC_CCALL(renderer_tile, if (!dst.h) dst.h = tex->h; float scale = js2number(js,argv[3]); if (!scale) scale = 1; - if (JS_IsUndefined(argv[2])) + if (JS_IsNull(argv[2])) SDL_RenderTextureTiled(renderer,tex,NULL,scale, &dst); else { rect src = js2rect(js,argv[2]); @@ -154,15 +154,15 @@ JSC_CCALL(renderer_slice9, dst = transform_rect(js2rect(js,argv[1]), &cam_mat); SDL_RenderTexture9Grid(renderer, tex, - JS_IsUndefined(argv[3]) ? NULL : &src, + JS_IsNull(argv[3]) ? NULL : &src, bounds.l, bounds.r, bounds.t, bounds.b, 0.0, - JS_IsUndefined(argv[1]) ? NULL : &dst); + JS_IsNull(argv[1]) ? NULL : &dst); ) JSC_CCALL(renderer_get_image, SDL_Renderer *r = js2SDL_Renderer(js,self); SDL_Surface *surf = NULL; - if (!JS_IsUndefined(argv[0])) { + if (!JS_IsNull(argv[0])) { rect rect = js2rect(js,argv[0]); surf = SDL_RenderReadPixels(r,&rect); } else @@ -173,7 +173,7 @@ JSC_CCALL(renderer_get_image, JSC_SCALL(renderer_fasttext, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (!JS_IsUndefined(argv[2])) { + if (!JS_IsNull(argv[2])) { colorf color = js2color(js,argv[2]); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); } @@ -185,7 +185,7 @@ JSC_SCALL(renderer_fasttext, JSC_CCALL(renderer_line, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { colorf color = js2color(js,argv[1]); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); } @@ -205,7 +205,7 @@ JSC_CCALL(renderer_line, JSC_CCALL(renderer_point, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { colorf color = js2color(js,argv[1]); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); } @@ -220,7 +220,7 @@ JSC_CCALL(renderer_point, JS_FreeValue(js,val); } SDL_RenderPoints(r, points, len); - return JS_UNDEFINED; + return JS_NULL; } HMM_Vec2 point = transform_point(r, js2vec2(js,argv[0]), &cam_mat); @@ -297,7 +297,7 @@ JSC_CCALL(renderer_logical_size, JSC_CCALL(renderer_viewport, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsUndefined(argv[0])) + if (JS_IsNull(argv[0])) SDL_SetRenderViewport(r,NULL); else { rect view = js2rect(js,argv[0]); @@ -319,7 +319,7 @@ JSC_CCALL(renderer_get_viewport, JSC_CCALL(renderer_clip, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsUndefined(argv[0])) + if (JS_IsNull(argv[0])) SDL_SetRenderClipRect(r,NULL); else { rect view = js2rect(js,argv[0]); @@ -376,7 +376,7 @@ JSC_CCALL(renderer_screen2world, JSC_CCALL(renderer_target, SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsUndefined(argv[0])) + if (JS_IsNull(argv[0])) SDL_SetRenderTarget(r, NULL); else { SDL_Texture *tex = js2SDL_Texture(js,argv[0]); @@ -408,12 +408,12 @@ JSC_CCALL(renderer_make_sprite_mesh, HMM_Vec4 color; rect src; - if (JS_IsUndefined(jssrc)) + if (JS_IsNull(jssrc)) src = (rect){.x = 0, .y = 0, .w = 1, .h = 1}; else src = js2rect(js,jssrc); - if (JS_IsUndefined(jscolor)) + if (JS_IsNull(jscolor)) color = (HMM_Vec4){1,1,1,1}; else color = js2vec4(js,jscolor); diff --git a/source/qjs_rtree.c b/source/qjs_rtree.c index 781ed0b9..6785cc81 100644 --- a/source/qjs_rtree.c +++ b/source/qjs_rtree.c @@ -105,7 +105,7 @@ struct rtree_each int rtree_foreach(const NUMTYPE *min, const NUMTYPE *max, const JSValue *value, struct rtree_each *each) { - JSValue ret = JS_Call(each->js, each->fn, JS_UNDEFINED, 0, NULL); + JSValue ret = JS_Call(each->js, each->fn, JS_NULL, 0, NULL); uncaught_exception(each->js, ret); return 1; } diff --git a/source/qjs_sdl.c b/source/qjs_sdl.c index 9eac53dc..3597a07b 100644 --- a/source/qjs_sdl.c +++ b/source/qjs_sdl.c @@ -183,7 +183,7 @@ static SDL_CameraSpec js2cameraspec(JSContext *js, JSValue obj) { JSValue v; v = JS_GetPropertyStr(js, obj, "format"); - if (!JS_IsUndefined(v)) { + if (!JS_IsNull(v)) { const char *s = JS_ToCString(js, v); spec.format = str2pixelformat(s); JS_FreeCString(js, s); @@ -191,23 +191,23 @@ static SDL_CameraSpec js2cameraspec(JSContext *js, JSValue obj) { JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "colorspace"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.colorspace, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.colorspace, v); JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "width"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.width, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.width, v); JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "height"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.height, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.height, v); JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "framerate_numerator"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.framerate_numerator, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.framerate_numerator, v); JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "framerate_denominator"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.framerate_denominator, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.framerate_denominator, v); JS_FreeValue(js, v); return spec; @@ -229,7 +229,7 @@ JSC_CCALL(camera_open, SDL_CameraSpec spec; // Check if a format spec was provided - if (argc > 1 && !JS_IsUndefined(argv[1])) { + if (argc > 1 && !JS_IsNull(argv[1])) { spec = js2cameraspec(js, argv[1]); spec_ptr = &spec; } @@ -300,7 +300,7 @@ JSC_CCALL(camera_capture, const char *msg = SDL_GetError(); if (msg[0] != 0) return JS_ThrowReferenceError(js,"Could not get camera frame: %s", SDL_GetError()); - else return JS_UNDEFINED; + else return JS_NULL; } // Create a copy of the surface @@ -330,7 +330,7 @@ JSC_CCALL(camera_get_driver, if (!cam) return JS_ThrowReferenceError(js,"Self was not a camera: %s", SDL_GetError()); const char *driver = SDL_GetCurrentCameraDriver(); - if (!driver) return JS_UNDEFINED; + if (!driver) return JS_NULL; return JS_NewString(js, driver); ) @@ -415,7 +415,7 @@ static SDL_AudioSpec js2audiospec(JSContext *js, JSValue obj) JSValue v; v = JS_GetPropertyStr(js, obj, "format"); - if (!JS_IsUndefined(v)) { + if (!JS_IsNull(v)) { const char *s = JS_ToCString(js, v); format_str_to_enum(s, &spec.format); JS_FreeCString(js, s); @@ -423,11 +423,11 @@ static SDL_AudioSpec js2audiospec(JSContext *js, JSValue obj) JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "channels"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.channels, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.channels, v); JS_FreeValue(js, v); v = JS_GetPropertyStr(js, obj, "samplerate"); - if (!JS_IsUndefined(v)) JS_ToInt32(js, &spec.freq, v); + if (!JS_IsNull(v)) JS_ToInt32(js, &spec.freq, v); JS_FreeValue(js, v); return spec; @@ -461,7 +461,7 @@ JSC_CCALL(sdl_audio_open_stream, SDL_AudioStream *st; - if (JS_IsUndefined(argv[1])) + if (JS_IsNull(argv[1])) st = SDL_OpenAudioDeviceStream(devid, NULL, NULL, NULL); else { SDL_AudioSpec want = js2audiospec(js, argv[1]); @@ -496,11 +496,11 @@ JSC_CCALL(sdl_audiostream_set_format, const SDL_AudioSpec *src_ptr=NULL,*dst_ptr=NULL; SDL_AudioSpec src={0},dst={0}; - if(argc>0&&!JS_IsUndefined(argv[0])){ + if(argc>0&&!JS_IsNull(argv[0])){ src=js2audiospec(js,argv[0]); src_ptr=&src; } - if(argc>1&&!JS_IsUndefined(argv[1])){ + if(argc>1&&!JS_IsNull(argv[1])){ dst=js2audiospec(js,argv[1]); dst_ptr=&dst; } @@ -508,7 +508,7 @@ JSC_CCALL(sdl_audiostream_set_format, if(!SDL_SetAudioStreamFormat(as,src_ptr,dst_ptr)) return JS_ThrowInternalError(js,"%s",SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_resume, @@ -516,21 +516,21 @@ JSC_CCALL(sdl_audiostream_resume, if (!SDL_ResumeAudioStreamDevice(as)) return JS_ThrowInternalError(js,"%s",SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_clear, SDL_AudioStream *as=js2SDL_AudioStream(js,self); if (!SDL_ClearAudioStream(as)) return JS_ThrowInternalError(js,"%s",SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_flush, SDL_AudioStream *as=js2SDL_AudioStream(js,self); if(!SDL_FlushAudioStream(as)) return JS_ThrowInternalError(js,"%s",SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_available, @@ -557,7 +557,7 @@ JSC_CCALL(sdl_audiostream_put, if (!SDL_PutAudioStreamData(as,buf,len)) return JS_ThrowInternalError(js, "%s", SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_get, @@ -587,7 +587,7 @@ JSC_CCALL(sdl_audiostream_set_gain, SDL_AudioStream *as=js2SDL_AudioStream(js,self); double g; JS_ToFloat64(js,&g,argv[0]); SDL_SetAudioStreamGain(as,(float)g); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(sdl_audiostream_get_freq_ratio, @@ -599,7 +599,7 @@ JSC_CCALL(sdl_audiostream_set_freq_ratio, SDL_AudioStream *as=js2SDL_AudioStream(js,self); double r; JS_ToFloat64(js,&r,argv[0]); SDL_SetAudioStreamFrequencyRatio(as,(float)r); - return JS_UNDEFINED; + return JS_NULL; ) /* ---------- JS export list -------------------------------------------- */ diff --git a/source/qjs_sdl_gpu.c b/source/qjs_sdl_gpu.c index c0c5bc9a..d8eeca23 100644 --- a/source/qjs_sdl_gpu.c +++ b/source/qjs_sdl_gpu.c @@ -70,7 +70,7 @@ SDL_GPUSampleCount js2SDL_GPUSampleCount(JSContext *js, JSValue v) #define JS2ENUM(NAME, RETS, VALS) \ int js2##NAME(JSContext *js, JSValue v) { \ - if (JS_IsUndefined(v)) return 0; \ + if (JS_IsNull(v)) return 0; \ const char *str = JS_ToCString(js, v); \ int *rets = (RETS); \ const char **vals = (VALS); \ @@ -728,19 +728,19 @@ SDL_GPUStencilOpState js2SDL_GPUStencilOpState(JSContext *js, JSValue v) memset(&state, 0, sizeof(state)); JSValue compare_val = JS_GetPropertyStr(js, v, "compare"); - if(!JS_IsUndefined(compare_val)) state.compare_op = js2SDL_GPUCompareOp(js, compare_val); + if(!JS_IsNull(compare_val)) state.compare_op = js2SDL_GPUCompareOp(js, compare_val); JS_FreeValue(js, compare_val); JSValue fail_val = JS_GetPropertyStr(js, v, "fail"); - if(!JS_IsUndefined(fail_val)) state.fail_op = js2SDL_GPUStencilOp(js, fail_val); + if(!JS_IsNull(fail_val)) state.fail_op = js2SDL_GPUStencilOp(js, fail_val); JS_FreeValue(js, fail_val); JSValue depth_fail_val = JS_GetPropertyStr(js, v, "depth_fail"); - if(!JS_IsUndefined(depth_fail_val)) state.depth_fail_op = js2SDL_GPUStencilOp(js, depth_fail_val); + if(!JS_IsNull(depth_fail_val)) state.depth_fail_op = js2SDL_GPUStencilOp(js, depth_fail_val); JS_FreeValue(js, depth_fail_val); JSValue pass_val = JS_GetPropertyStr(js, v, "pass"); - if(!JS_IsUndefined(pass_val)) state.pass_op = js2SDL_GPUStencilOp(js, pass_val); + if(!JS_IsNull(pass_val)) state.pass_op = js2SDL_GPUStencilOp(js, pass_val); JS_FreeValue(js, pass_val); return state; @@ -798,8 +798,8 @@ JSC_CCALL(cmd_acquire_swapchain, Uint32 w,h; SDL_GPUTexture *texture; SDL_AcquireGPUSwapchainTexture(cmds,global_window, &texture, &w, &h); - if (!texture) return JS_UNDEFINED; - JSValue swap = JS_UNDEFINED; + if (!texture) return JS_NULL; + JSValue swap = JS_NULL; JSValue *js_swapchains = ((cell_rt*)JS_GetContextOpaque(js))->js_swapchains; @@ -810,7 +810,7 @@ JSC_CCALL(cmd_acquire_swapchain, } } - if (JS_IsUndefined(swap)) { + if (JS_IsNull(swap)) { swap = SDL_GPUTexture2js(js,texture); arrput(js_swapchains,swap); } @@ -1580,7 +1580,7 @@ JSC_CCALL(gpu_upload, for (size_t i = 0; i < len; i++) { JSValue js_buf = JS_GetPropertyUint32(js, js_buffers, i); - if (JS_IsUndefined(js_buf)) + if (JS_IsNull(js_buf)) continue; gpu_buffer_unpack(js, gpu, js_buf, &items[i].size, &items[i].data, &items[i].gpu_buffer); @@ -1883,7 +1883,7 @@ JSC_CCALL(cmd_render_pass, // Optional depth_stencil JSValue depthval = JS_GetPropertyStr(js, passObj, "depth_stencil"); - if (!JS_IsUndefined(depthval)) { + if (!JS_IsNull(depthval)) { has_depth = 1; JS_GETPROP(js, depthtar.texture, depthval, texture, SDL_GPUTexture) JS_GETPROP(js, depthtar.load_op, depthval, load, SDL_GPULoadOp) @@ -2243,7 +2243,7 @@ SDL_GPUSampleCount js2SDL_GPUSampleCount(JSContext *js, JSValue v) // Enum conversion macro and definitions #define JS2ENUM(NAME, RETS, VALS) \ int js2##NAME(JSContext *js, JSValue v) { \ - if (JS_IsUndefined(v)) return 0; \ + if (JS_IsNull(v)) return 0; \ const char *str = JS_ToCString(js, v); \ int *rets = (RETS); \ const char **vals = (VALS); \ @@ -2431,5 +2431,5 @@ JSValue js_sdl_gpu_use(JSContext *js) { // GPU classes are registered via the main FFI loading system // This module doesn't export its own functions, it just provides class definitions - return JS_UNDEFINED; + return JS_NULL; } diff --git a/source/qjs_sdl_surface.c b/source/qjs_sdl_surface.c index a9b636bd..7081613a 100644 --- a/source/qjs_sdl_surface.c +++ b/source/qjs_sdl_surface.c @@ -16,7 +16,7 @@ JSValue pixelformat2js(JSContext *js, SDL_PixelFormat fmt) SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v) { - if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN; + if (JS_IsNull(v)) return SDL_PIXELFORMAT_UNKNOWN; const char *s = JS_ToCString(js, v); if (!s) return SDL_PIXELFORMAT_UNKNOWN; @@ -41,7 +41,7 @@ static JSValue scalemode2js(JSContext *js, SDL_ScaleMode mode){ } SDL_ScaleMode js2SDL_ScaleMode(JSContext *js, JSValue v){ - if(JS_IsUndefined(v)) return SDL_SCALEMODE_NEAREST; + if(JS_IsNull(v)) return SDL_SCALEMODE_NEAREST; const char *s = JS_ToCString(js, v); if(!s) return SDL_SCALEMODE_NEAREST; const scale_entry *it; @@ -66,14 +66,14 @@ JSC_CCALL(surface_blit, SDL_Surface *dst = js2SDL_Surface(js, self); irect dr = {0}, *pdr = NULL; - if(!JS_IsUndefined(argv[0])){ dr = js2irect(js, argv[0]); pdr = &dr; } + if(!JS_IsNull(argv[0])){ dr = js2irect(js, argv[0]); pdr = &dr; } SDL_Surface *src = js2SDL_Surface(js, argv[1]); if (!src) return JS_ThrowReferenceError(js, "Argument must be a surface."); irect sr = {0}, *psr = NULL; - if(!JS_IsUndefined(argv[2])){ sr = js2irect(js, argv[2]); psr = &sr; } + if(!JS_IsNull(argv[2])){ sr = js2irect(js, argv[2]); psr = &sr; } SDL_ScaleMode mode = js2SDL_ScaleMode(js, argv[3]); @@ -241,14 +241,14 @@ JSC_CCALL(surface_constructor, // Check for pixel format SDL_PixelFormat format = SDL_PIXELFORMAT_RGBA32; // default JSValue format_val = JS_GetPropertyStr(js, argv[0], "format"); - if (!JS_IsUndefined(format_val)) { + if (!JS_IsNull(format_val)) { format = js2pixelformat(js, format_val); } JS_FreeValue(js, format_val); // Check for pixel data JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); - if (!JS_IsUndefined(pixels_val)) { + if (!JS_IsNull(pixels_val)) { // Create surface from pixel data size_t len; void *raw = js_get_blob_data(js, &len, pixels_val); @@ -261,7 +261,7 @@ JSC_CCALL(surface_constructor, // Get pitch if provided, otherwise calculate it int pitch; JSValue pitch_val = JS_GetPropertyStr(js, argv[0], "pitch"); - if (!JS_IsUndefined(pitch_val)) { + if (!JS_IsNull(pitch_val)) { pitch = js2number(js, pitch_val); JS_FreeValue(js, pitch_val); } else { diff --git a/source/qjs_sdl_video.c b/source/qjs_sdl_video.c index 252404d1..7df95f3d 100644 --- a/source/qjs_sdl_video.c +++ b/source/qjs_sdl_video.c @@ -87,7 +87,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // Get basic properties (defaults are handled in JavaScript) const char *title = NULL; JSValue title_val = JS_GetPropertyStr(js, opts, "title"); - if (!JS_IsUndefined(title_val) && !JS_IsNull(title_val)) { + if (!JS_IsNull(title_val) && !JS_IsNull(title_val)) { title = JS_ToCString(js, title_val); } JS_FreeValue(js, title_val); @@ -98,14 +98,14 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int int width = 640; JSValue width_val = JS_GetPropertyStr(js, opts, "width"); - if (!JS_IsUndefined(width_val) && !JS_IsNull(width_val)) { + if (!JS_IsNull(width_val) && !JS_IsNull(width_val)) { width = js2number(js, width_val); } JS_FreeValue(js, width_val); int height = 480; JSValue height_val = JS_GetPropertyStr(js, opts, "height"); - if (!JS_IsUndefined(height_val) && !JS_IsNull(height_val)) { + if (!JS_IsNull(height_val) && !JS_IsNull(height_val)) { height = js2number(js, height_val); } JS_FreeValue(js, height_val); @@ -120,7 +120,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // Handle window position JSValue x_val = JS_GetPropertyStr(js, opts, "x"); - if (!JS_IsUndefined(x_val)) { + if (!JS_IsNull(x_val)) { if (JS_IsString(x_val)) { const char *pos = JS_ToCString(js, x_val); if (strcmp(pos, "centered") == 0) @@ -135,7 +135,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int JS_FreeValue(js, x_val); JSValue y_val = JS_GetPropertyStr(js, opts, "y"); - if (!JS_IsUndefined(y_val)) { + if (!JS_IsNull(y_val)) { if (JS_IsString(y_val)) { const char *pos = JS_ToCString(js, y_val); if (strcmp(pos, "centered") == 0) @@ -152,7 +152,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // Helper function to check and set boolean properties #define SET_BOOL_PROP(js_name, sdl_prop) do { \ JSValue val = JS_GetPropertyStr(js, opts, js_name); \ - if (!JS_IsUndefined(val)) { \ + if (!JS_IsNull(val)) { \ SDL_SetBooleanProperty(props, sdl_prop, JS_ToBool(js, val)); \ } \ JS_FreeValue(js, val); \ @@ -180,14 +180,14 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // Handle focusable (inverse logic) JSValue focusable_val = JS_GetPropertyStr(js, opts, "focusable"); - if (!JS_IsUndefined(focusable_val)) { + if (!JS_IsNull(focusable_val)) { SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, JS_ToBool(js, focusable_val)); } JS_FreeValue(js, focusable_val); // Handle notFocusable (for backwards compatibility) JSValue not_focusable_val = JS_GetPropertyStr(js, opts, "notFocusable"); - if (!JS_IsUndefined(not_focusable_val)) { + if (!JS_IsNull(not_focusable_val)) { SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, !JS_ToBool(js, not_focusable_val)); } JS_FreeValue(js, not_focusable_val); @@ -196,7 +196,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // Handle parent window JSValue parent_val = JS_GetPropertyStr(js, opts, "parent"); - if (!JS_IsUndefined(parent_val) && !JS_IsNull(parent_val)) { + if (!JS_IsNull(parent_val) && !JS_IsNull(parent_val)) { SDL_Window *parent = js2SDL_Window(js, parent_val); if (parent) { SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_PARENT_POINTER, parent); @@ -224,22 +224,22 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int // These will be applied through the property setters JSValue opacity_val = JS_GetPropertyStr(js, opts, "opacity"); - if (!JS_IsUndefined(opacity_val)) { + if (!JS_IsNull(opacity_val)) { JS_SetPropertyStr(js, window_obj, "opacity", opacity_val); } JSValue min_size_val = JS_GetPropertyStr(js, opts, "minimumSize"); - if (!JS_IsUndefined(min_size_val)) { + if (!JS_IsNull(min_size_val)) { JS_SetPropertyStr(js, window_obj, "minimumSize", min_size_val); } JSValue max_size_val = JS_GetPropertyStr(js, opts, "maximumSize"); - if (!JS_IsUndefined(max_size_val)) { + if (!JS_IsNull(max_size_val)) { JS_SetPropertyStr(js, window_obj, "maximumSize", max_size_val); } JSValue pos_val = JS_GetPropertyStr(js, opts, "position"); - if (!JS_IsUndefined(pos_val)) { + if (!JS_IsNull(pos_val)) { JS_SetPropertyStr(js, window_obj, "position", pos_val); } @@ -275,7 +275,7 @@ JSValue js_SDL_Window_keyboard_shown(JSContext *js, JSValue self) { JSValue js_window_theme(JSContext *js, JSValue self) { - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_safe_area(JSContext *js, JSValue self) @@ -290,7 +290,7 @@ JSValue js_window_bordered(JSContext *js, JSValue self, int argc, JSValue *argv) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowBordered(w, JS_ToBool(js,argv[0])); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_get_title(JSContext *js, JSValue self) @@ -306,7 +306,7 @@ JSValue js_window_set_title(JSContext *js, JSValue self, JSValue val) const char *title = JS_ToCString(js,val); SDL_SetWindowTitle(w,title); JS_FreeCString(js,title); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_get_size(JSContext *js, JSValue self) @@ -322,7 +322,7 @@ JSValue js_window_set_size(JSContext *js, JSValue self, JSValue val) SDL_Window *w = js2SDL_Window(js,self); HMM_Vec2 size = js2vec2(js,val); SDL_SetWindowSize(w,size.x,size.y); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_set_icon(JSContext *js, JSValue self, int argc, JSValue *argv) @@ -331,7 +331,7 @@ JSValue js_window_set_icon(JSContext *js, JSValue self, int argc, JSValue *argv) SDL_Surface *s = js2SDL_Surface(js,argv[0]); if (!SDL_SetWindowIcon(w,s)) return JS_ThrowReferenceError(js, "could not set window icon: %s", SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; } // Position getter/setter @@ -348,7 +348,7 @@ JSValue js_window_set_position(JSContext *js, JSValue self, JSValue val) SDL_Window *w = js2SDL_Window(js,self); HMM_Vec2 pos = js2vec2(js,val); SDL_SetWindowPosition(w,pos.x,pos.y); - return JS_UNDEFINED; + return JS_NULL; } // Mouse grab getter/setter @@ -362,7 +362,7 @@ JSValue js_window_set_mouseGrab(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowMouseGrab(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Keyboard grab getter/setter @@ -376,7 +376,7 @@ JSValue js_window_set_keyboardGrab(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowKeyboardGrab(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Opacity getter/setter @@ -391,7 +391,7 @@ JSValue js_window_set_opacity(JSContext *js, JSValue self, JSValue val) SDL_Window *w = js2SDL_Window(js,self); float opacity = js2number(js,val); SDL_SetWindowOpacity(w, opacity); - return JS_UNDEFINED; + return JS_NULL; } // Minimum size getter/setter @@ -408,7 +408,7 @@ JSValue js_window_set_minimumSize(JSContext *js, JSValue self, JSValue val) SDL_Window *w = js2SDL_Window(js,self); HMM_Vec2 size = js2vec2(js,val); SDL_SetWindowMinimumSize(w,size.x,size.y); - return JS_UNDEFINED; + return JS_NULL; } // Maximum size getter/setter @@ -425,7 +425,7 @@ JSValue js_window_set_maximumSize(JSContext *js, JSValue self, JSValue val) SDL_Window *w = js2SDL_Window(js,self); HMM_Vec2 size = js2vec2(js,val); SDL_SetWindowMaximumSize(w,size.x,size.y); - return JS_UNDEFINED; + return JS_NULL; } // Resizable setter (read from flags) @@ -440,7 +440,7 @@ JSValue js_window_set_resizable(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowResizable(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Bordered getter/setter @@ -455,7 +455,7 @@ JSValue js_window_set_bordered(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowBordered(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Always on top getter/setter @@ -470,7 +470,7 @@ JSValue js_window_set_alwaysOnTop(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowAlwaysOnTop(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Fullscreen getter/setter @@ -485,7 +485,7 @@ JSValue js_window_set_fullscreen(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowFullscreen(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Focusable setter @@ -500,7 +500,7 @@ JSValue js_window_set_focusable(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowFocusable(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Modal setter @@ -515,7 +515,7 @@ JSValue js_window_set_modal(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_SetWindowModal(w, JS_ToBool(js,val)); - return JS_UNDEFINED; + return JS_NULL; } // Hidden/visible state @@ -533,7 +533,7 @@ JSValue js_window_set_visible(JSContext *js, JSValue self, JSValue val) SDL_ShowWindow(w); else SDL_HideWindow(w); - return JS_UNDEFINED; + return JS_NULL; } // Minimized state @@ -551,7 +551,7 @@ JSValue js_window_set_minimized(JSContext *js, JSValue self, JSValue val) SDL_MinimizeWindow(w); else SDL_RestoreWindow(w); - return JS_UNDEFINED; + return JS_NULL; } // Maximized state @@ -569,7 +569,7 @@ JSValue js_window_set_maximized(JSContext *js, JSValue self, JSValue val) SDL_MaximizeWindow(w); else SDL_RestoreWindow(w); - return JS_UNDEFINED; + return JS_NULL; } // Other window methods @@ -577,14 +577,14 @@ JSValue js_window_raise(JSContext *js, JSValue self, int argc, JSValue *argv) { SDL_Window *w = js2SDL_Window(js,self); SDL_RaiseWindow(w); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_restore(JSContext *js, JSValue self, int argc, JSValue *argv) { SDL_Window *w = js2SDL_Window(js,self); SDL_RestoreWindow(w); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_flash(JSContext *js, JSValue self, int argc, JSValue *argv) @@ -599,14 +599,14 @@ JSValue js_window_flash(JSContext *js, JSValue self, int argc, JSValue *argv) JS_FreeCString(js,operation); } SDL_FlashWindow(w, op); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_destroy(JSContext *js, JSValue self, int argc, JSValue *argv) { SDL_Window *w = js2SDL_Window(js,self); SDL_DestroyWindow(w); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_get_id(JSContext *js, JSValue self) @@ -627,10 +627,10 @@ JSValue js_window_set_parent(JSContext *js, JSValue self, JSValue val) { SDL_Window *w = js2SDL_Window(js,self); SDL_Window *parent = NULL; - if (!JS_IsNull(val) && !JS_IsUndefined(val)) + if (!JS_IsNull(val) && !JS_IsNull(val)) parent = js2SDL_Window(js,val); SDL_SetWindowParent(w, parent); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_get_pixelDensity(JSContext *js, JSValue self) @@ -667,7 +667,7 @@ JSValue js_window_updateSurface(JSContext *js, JSValue self, int argc, JSValue * SDL_Window *w = js2SDL_Window(js,self); if (!SDL_UpdateWindowSurface(w)) return JS_ThrowReferenceError(js, "Failed to update window surface: %s", SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_updateSurfaceRects(JSContext *js, JSValue self, int argc, JSValue *argv) @@ -689,7 +689,7 @@ JSValue js_window_updateSurfaceRects(JSContext *js, JSValue self, int argc, JSVa if (!SDL_UpdateWindowSurfaceRects(w, rects, len)) return JS_ThrowReferenceError(js, "Failed to update window surface rects: %s", SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; } JSValue js_window_get_flags(JSContext *js, JSValue self) @@ -702,7 +702,7 @@ JSValue js_window_sync(JSContext *js, JSValue self, int argc, JSValue *argv) { SDL_Window *w = js2SDL_Window(js,self); SDL_SyncWindow(w); - return JS_UNDEFINED; + return JS_NULL; } static const JSCFunctionListEntry js_SDL_Window_funcs[] = { @@ -768,7 +768,7 @@ JSC_CCALL(renderer_load_texture, JSC_CCALL(renderer_get_image, SDL_Renderer *r = js2SDL_Renderer(js,self); SDL_Surface *surf = NULL; - if (!JS_IsUndefined(argv[0])) { + if (!JS_IsNull(argv[0])) { rect rect = js2rect(js,argv[0]); surf = SDL_RenderReadPixels(r,&rect); } else @@ -812,7 +812,7 @@ JSC_CCALL(renderer_point, pts[i] = (SDL_FPoint){pt.x, pt.y}; } SDL_RenderPoints(r, pts, len); - return JS_UNDEFINED; + return JS_NULL; } HMM_Vec2 pt = js2vec2(js, argv[0]); @@ -839,7 +839,7 @@ JSC_CCALL(renderer_rects, /* array-of-rectangles case */ if (JS_IsArray(js, argv[0])) { int len = JS_ArrayLength(js, argv[0]); - if (len <= 0) return JS_UNDEFINED; + if (len <= 0) return JS_NULL; SDL_FRect rects[len]; @@ -852,7 +852,7 @@ JSC_CCALL(renderer_rects, if (!SDL_RenderFillRects(r, rects, len)) return JS_ThrowReferenceError(js, "SDL_RenderFillRects: %s", SDL_GetError()); - return JS_UNDEFINED; + return JS_NULL; } /* single-rect path */ @@ -893,7 +893,7 @@ JSC_CCALL(renderer_geometry_raw, // argv[0] is texture SDL_Texture *tex = NULL; - if (argc > 0 && !JS_IsNull(argv[0]) && !JS_IsUndefined(argv[0])) + if (argc > 0 && !JS_IsNull(argv[0]) && !JS_IsNull(argv[0])) tex = js2SDL_Texture(js,argv[0]); // Get blob data @@ -1045,7 +1045,7 @@ static JSValue logicalpresentation2js(JSContext *js, static SDL_RendererLogicalPresentation js2SDL_LogicalPresentation(JSContext *js, JSValue v){ - if(JS_IsUndefined(v)) return SDL_LOGICAL_PRESENTATION_DISABLED; + if(JS_IsNull(v)) return SDL_LOGICAL_PRESENTATION_DISABLED; const char *s = JS_ToCString(js, v); if(!s) return SDL_LOGICAL_PRESENTATION_DISABLED; const pres_entry *it; @@ -1069,13 +1069,13 @@ JSValue js_renderer_get_target(JSContext *js, JSValue self) JSValue js_renderer_set_target(JSContext *js, JSValue self, JSValue val) { SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsNull(val) || JS_IsUndefined(val)) + if (JS_IsNull(val) || JS_IsNull(val)) SDL_SetRenderTarget(r, NULL); else { SDL_Texture *tex = js2SDL_Texture(js,val); SDL_SetRenderTarget(r,tex); } - return JS_UNDEFINED; + return JS_NULL; } // Logical presentation getter/setter @@ -1101,7 +1101,7 @@ JSValue js_renderer_set_logicalPresentation(JSContext *js, JSValue self, JSValue SDL_RendererLogicalPresentation mode = js2SDL_LogicalPresentation(js, mode_val); JS_FreeValue(js, mode_val); SDL_SetRenderLogicalPresentation(r, w, h, mode); - return JS_UNDEFINED; + return JS_NULL; } // Viewport getter/setter @@ -1116,13 +1116,13 @@ JSValue js_renderer_get_viewport(JSContext *js, JSValue self) JSValue js_renderer_set_viewport(JSContext *js, JSValue self, JSValue val) { SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsNull(val) || JS_IsUndefined(val)) + if (JS_IsNull(val) || JS_IsNull(val)) SDL_SetRenderViewport(r,NULL); else { rect view = js2rect(js,val); SDL_SetRenderViewport(r,&view); } - return JS_UNDEFINED; + return JS_NULL; } // Clip rect getter/setter @@ -1137,13 +1137,13 @@ JSValue js_renderer_get_clipRect(JSContext *js, JSValue self) JSValue js_renderer_set_clipRect(JSContext *js, JSValue self, JSValue val) { SDL_Renderer *r = js2SDL_Renderer(js,self); - if (JS_IsNull(val) || JS_IsUndefined(val)) + if (JS_IsNull(val) || JS_IsNull(val)) SDL_SetRenderClipRect(r,NULL); else { rect clip = js2rect(js,val); SDL_SetRenderClipRect(r,&clip); } - return JS_UNDEFINED; + return JS_NULL; } // Scale getter/setter @@ -1160,7 +1160,7 @@ JSValue js_renderer_set_scale(JSContext *js, JSValue self, JSValue val) SDL_Renderer *r = js2SDL_Renderer(js,self); HMM_Vec2 scale = js2vec2(js,val); SDL_SetRenderScale(r, scale.x, scale.y); - return JS_UNDEFINED; + return JS_NULL; } // Draw color getter/setter (float version) @@ -1182,7 +1182,7 @@ JSValue js_renderer_set_drawColor(JSContext *js, JSValue self, JSValue val) SDL_Renderer *r = js2SDL_Renderer(js,self); colorf color = js2color(js,val); SDL_SetRenderDrawColorFloat(r, color.r, color.g, color.b, color.a); - return JS_UNDEFINED; + return JS_NULL; } // Color scale getter/setter @@ -1199,7 +1199,7 @@ JSValue js_renderer_set_colorScale(JSContext *js, JSValue self, JSValue val) SDL_Renderer *r = js2SDL_Renderer(js,self); float scale = js2number(js,val); SDL_SetRenderColorScale(r, scale); - return JS_UNDEFINED; + return JS_NULL; } // Draw blend mode getter/setter @@ -1216,7 +1216,7 @@ JSValue js_renderer_set_drawBlendMode(JSContext *js, JSValue self, JSValue val) SDL_Renderer *r = js2SDL_Renderer(js,self); SDL_BlendMode mode = js2blendmode(js,val); SDL_SetRenderDrawBlendMode(r, mode); - return JS_UNDEFINED; + return JS_NULL; } // VSync getter/setter @@ -1233,7 +1233,7 @@ JSValue js_renderer_set_vsync(JSContext *js, JSValue self, JSValue val) SDL_Renderer *r = js2SDL_Renderer(js,self); int vsync = js2number(js,val); SDL_SetRenderVSync(r, vsync); - return JS_UNDEFINED; + return JS_NULL; } // Read-only properties @@ -1360,7 +1360,7 @@ JSC_CCALL(renderer_textureTiled, SDL_Texture *tex = js2SDL_Texture(js, argv[0]); rect src_rect = {0}; - if (argc > 1 && !JS_IsNull(argv[1]) && !JS_IsUndefined(argv[1])) + if (argc > 1 && !JS_IsNull(argv[1]) && !JS_IsNull(argv[1])) src_rect = js2rect(js, argv[1]); float scale = 1.0f; @@ -1368,7 +1368,7 @@ JSC_CCALL(renderer_textureTiled, scale = js2number(js, argv[2]); rect dst_rect = {0}; - if (argc > 3 && !JS_IsNull(argv[3]) && !JS_IsUndefined(argv[3])) + if (argc > 3 && !JS_IsNull(argv[3]) && !JS_IsNull(argv[3])) dst_rect = js2rect(js, argv[3]); if (!SDL_RenderTextureTiled(r, tex, @@ -1393,7 +1393,7 @@ JSC_CCALL(renderer_debugText, JSC_CCALL(renderer_readPixels, SDL_Renderer *r = js2SDL_Renderer(js,self); rect read_rect = {0}; - if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsUndefined(argv[0])) + if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsNull(argv[0])) read_rect = js2rect(js, argv[0]); SDL_Surface *surf = SDL_RenderReadPixels(r, @@ -1513,13 +1513,13 @@ static JSValue js_texture_constructor(JSContext *js, JSValueConst new_target, in JSValue format_val = JS_GetPropertyStr(js, obj, "format"); SDL_PixelFormat format = SDL_PIXELFORMAT_RGBA8888; - if (!JS_IsUndefined(format_val)) + if (!JS_IsNull(format_val)) format = js2pixelformat(js, format_val); JS_FreeValue(js, format_val); // Check for pixels data JSValue pixels_val = JS_GetPropertyStr(js, obj, "pixels"); - if (!JS_IsUndefined(pixels_val)) { + if (!JS_IsNull(pixels_val)) { // Create surface first, then texture size_t size; uint8_t *pixels = js_get_blob_data(js, &size, pixels_val); @@ -1611,7 +1611,7 @@ JSValue js_texture_set_alphaMod(JSContext *js, JSValue self, JSValue val) SDL_Texture *tex = js2SDL_Texture(js,self); float alpha = js2number(js,val); SDL_SetTextureAlphaModFloat(tex, alpha); - return JS_UNDEFINED; + return JS_NULL; } // Color mod getter/setter @@ -1632,7 +1632,7 @@ JSValue js_texture_set_colorMod(JSContext *js, JSValue self, JSValue val) SDL_Texture *tex = js2SDL_Texture(js,self); colorf color = js2color(js,val); SDL_SetTextureColorModFloat(tex, color.r, color.g, color.b); - return JS_UNDEFINED; + return JS_NULL; } // Blend mode getter/setter @@ -1649,7 +1649,7 @@ JSValue js_texture_set_blendMode(JSContext *js, JSValue self, JSValue val) SDL_Texture *tex = js2SDL_Texture(js,self); SDL_BlendMode mode = js2blendmode(js,val); SDL_SetTextureBlendMode(tex, mode); - return JS_UNDEFINED; + return JS_NULL; } // Scale mode getter/setter @@ -1668,7 +1668,7 @@ JSValue js_texture_set_scaleMode(JSContext *js, JSValue self, JSValue val) SDL_Texture *tex = js2SDL_Texture(js,self); SDL_ScaleMode mode = js2SDL_ScaleMode(js,val); SDL_SetTextureScaleMode(tex, mode); - return JS_UNDEFINED; + return JS_NULL; } // Size getter (read-only) @@ -1687,7 +1687,7 @@ JSC_CCALL(texture_update, void *pixels = NULL; int pitch = 0; - if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsUndefined(argv[0])) + if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsNull(argv[0])) update_rect = js2rect(js, argv[0]); if (argc >= 2) { @@ -1713,7 +1713,7 @@ JSC_CCALL(texture_lock, void *pixels; int pitch; - if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsUndefined(argv[0])) + if (argc >= 1 && !JS_IsNull(argv[0]) && !JS_IsNull(argv[0])) lock_rect = js2rect(js, argv[0]); if (!SDL_LockTexture(tex, diff --git a/source/qjs_socket.c b/source/qjs_socket.c index 6d4a3704..6c373b9f 100644 --- a/source/qjs_socket.c +++ b/source/qjs_socket.c @@ -35,10 +35,10 @@ JSC_CCALL(socket_getaddrinfo, hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - if (!JS_IsNull(argv[0]) && !JS_IsUndefined(argv[0])) + if (!JS_IsNull(argv[0]) && !JS_IsNull(argv[0])) node = JS_ToCString(js, argv[0]); - if (!JS_IsNull(argv[1]) && !JS_IsUndefined(argv[1])) + if (!JS_IsNull(argv[1]) && !JS_IsNull(argv[1])) service = JS_ToCString(js, argv[1]); // Parse optional hints object @@ -46,7 +46,7 @@ JSC_CCALL(socket_getaddrinfo, JSValue val; val = JS_GetPropertyStr(js, argv[2], "family"); - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { const char *family = JS_ToCString(js, val); if (strcmp(family, "AF_INET") == 0) hints.ai_family = AF_INET; else if (strcmp(family, "AF_INET6") == 0) hints.ai_family = AF_INET6; @@ -55,7 +55,7 @@ JSC_CCALL(socket_getaddrinfo, JS_FreeValue(js, val); val = JS_GetPropertyStr(js, argv[2], "socktype"); - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { const char *socktype = JS_ToCString(js, val); if (strcmp(socktype, "SOCK_STREAM") == 0) hints.ai_socktype = SOCK_STREAM; else if (strcmp(socktype, "SOCK_DGRAM") == 0) hints.ai_socktype = SOCK_DGRAM; @@ -64,7 +64,7 @@ JSC_CCALL(socket_getaddrinfo, JS_FreeValue(js, val); val = JS_GetPropertyStr(js, argv[2], "flags"); - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { hints.ai_flags = js2number(js, val); } JS_FreeValue(js, val); @@ -192,7 +192,7 @@ JSC_CCALL(socket_bind, } } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(socket_connect, @@ -220,7 +220,7 @@ JSC_CCALL(socket_connect, } } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(socket_listen, @@ -236,7 +236,7 @@ JSC_CCALL(socket_listen, return JS_ThrowReferenceError(js, "listen failed: %s", strerror(errno)); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(socket_accept, @@ -448,7 +448,7 @@ JSC_CCALL(socket_shutdown, return JS_ThrowReferenceError(js, "shutdown failed: %s", strerror(errno)); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(socket_getpeername, @@ -538,7 +538,7 @@ JSC_CCALL(socket_setsockopt, return JS_ThrowTypeError(js, "Invalid option value"); } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(socket_close, @@ -548,7 +548,7 @@ JSC_CCALL(socket_close, if (close(sockfd) != 0) return JS_ThrowReferenceError(js, "close failed: %s", strerror(errno)); - return JS_UNDEFINED; + return JS_NULL; ) static const JSCFunctionListEntry js_socket_funcs[] = { diff --git a/source/qjs_soloud.c b/source/qjs_soloud.c index 90c51f55..bab75c2d 100644 --- a/source/qjs_soloud.c +++ b/source/qjs_soloud.c @@ -147,7 +147,7 @@ static const JSCFunctionListEntry *js_Wav_funcs; static JSValue js_voice_set_##ENTRY (JSContext *js, JSValueConst self, JSValue val) { \ unsigned int voice = *js2voice(js, self); \ Soloud_set##ENTRY(soloud, voice, js2##TYPE(js, val)); \ - return JS_UNDEFINED; \ + return JS_NULL; \ } \ static JSValue js_voice_get_##ENTRY (JSContext *js, JSValueConst self) { \ unsigned int voice = *js2voice(js,self); \ @@ -158,14 +158,14 @@ static JSValue js_voice_seek(JSContext *js, JSValue self, int argc, JSValue *arg { unsigned int voice = *js2voice(js, self); Soloud_seek(soloud, voice, js2number(js, argv[0])); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_voice_stop(JSContext *js, JSValue self, int argc, JSValue *argv) { unsigned int voice = *js2voice(js, self); Soloud_stop(soloud, voice); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_voice_setInaudibleBehavior(JSContext *js, JSValueConst self, int argc, JSValue *argv) @@ -174,7 +174,7 @@ static JSValue js_voice_setInaudibleBehavior(JSContext *js, JSValueConst self, i int mustTick = js2bool(js, argv[0]); int kill = js2bool(js, argv[1]); Soloud_setInaudibleBehavior(soloud, voice, mustTick, kill); - return JS_UNDEFINED; + return JS_NULL; } SOLOUD_GETSET(Volume, number); diff --git a/source/qjs_spline.c b/source/qjs_spline.c index c094f639..b8d568b8 100644 --- a/source/qjs_spline.c +++ b/source/qjs_spline.c @@ -31,7 +31,7 @@ JSC_CCALL(spline_catmull, HMM_Vec2 *samples = catmull_rom_ma_v2(points, param); if (!samples) - ret = JS_UNDEFINED; + ret = JS_NULL; else ret = vecarr2js(js, samples, arrlen(samples)); @@ -45,7 +45,7 @@ JSC_CCALL(spline_bezier, HMM_Vec2 *samples = bezier_cb_ma_v2(points, param); if (!samples) - ret = JS_UNDEFINED; + ret = JS_NULL; else ret = vecarr2js(js, samples, arrlen(samples)); diff --git a/source/qjs_sprite.c b/source/qjs_sprite.c index 144ff24e..c443de6f 100644 --- a/source/qjs_sprite.c +++ b/source/qjs_sprite.c @@ -41,7 +41,7 @@ JSC_CCALL(sprite_set_affine, JSC_CCALL(sprite_set_image, sprite *sp = js2sprite(js,self); - if (!JS_IsUndefined(sp->image)) + if (!JS_IsNull(sp->image)) JS_FreeValue(js,sp->image); sp->image = JS_DupValue(js, argv[0]); ) @@ -75,7 +75,7 @@ static JSValue js_sprite_constructor(JSContext *js, JSValueConst new_target, int JS_GETATOM(js, sp->color, argv[0], color, color) JSValue image = JS_GetProperty(js, argv[0], JS_NewAtom(js, "image")); - if (!JS_IsUndefined(image)) { + if (!JS_IsNull(image)) { sp->image = image; // Transfer ownership, no need to dup } } diff --git a/source/qjs_steam.cpp b/source/qjs_steam.cpp index 3a4412d3..bab8875b 100644 --- a/source/qjs_steam.cpp +++ b/source/qjs_steam.cpp @@ -49,14 +49,14 @@ JSC_CCALL(steam_shutdown, SteamAPI_Shutdown(); steam_initialized = false; } - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(steam_run_callbacks, if (steam_initialized) { SteamAPI_RunCallbacks(); } - return JS_UNDEFINED; + return JS_NULL; ) // USER STATS & ACHIEVEMENTS @@ -84,7 +84,7 @@ JSC_CCALL(stats_get_int, bool success = SteamAPI_ISteamUserStats_GetStatInt32(steam_stats, name, &value); JS_FreeCString(js, name); - if (!success) return JS_UNDEFINED; + if (!success) return JS_NULL; return JS_NewInt32(js, value); ) @@ -98,7 +98,7 @@ JSC_CCALL(stats_get_float, bool success = SteamAPI_ISteamUserStats_GetStatFloat(steam_stats, name, &value); JS_FreeCString(js, name); - if (!success) return JS_UNDEFINED; + if (!success) return JS_NULL; return JS_NewFloat64(js, value); ) @@ -143,7 +143,7 @@ JSC_CCALL(achievement_get, bool success = SteamAPI_ISteamUserStats_GetAchievement(steam_stats, name, &achieved); JS_FreeCString(js, name); - if (!success) return JS_UNDEFINED; + if (!success) return JS_NULL; return JS_NewBool(js, achieved); ) @@ -185,7 +185,7 @@ JSC_CCALL(achievement_name, JS_ToUint32(js, &index, argv[0]); const char *name = SteamAPI_ISteamUserStats_GetAchievementName(steam_stats, index); - if (!name) return JS_UNDEFINED; + if (!name) return JS_NULL; return JS_NewString(js, name); ) @@ -307,7 +307,7 @@ JSC_CCALL(cloud_enable, bool enable = JS_ToBool(js, argv[0]); SteamAPI_ISteamRemoteStorage_SetCloudEnabledForApp(steam_remote, enable); - return JS_UNDEFINED; + return JS_NULL; ) JSC_CCALL(cloud_quota, @@ -316,7 +316,7 @@ JSC_CCALL(cloud_quota, uint64 total, available; bool success = SteamAPI_ISteamRemoteStorage_GetQuota(steam_remote, &total, &available); - if (!success) return JS_UNDEFINED; + if (!success) return JS_NULL; JSValue obj = JS_NewObject(js); JS_SetPropertyStr(js, obj, "total", JS_NewBigUint64(js, total)); @@ -367,7 +367,7 @@ JSC_CCALL(cloud_read, int32 size = SteamAPI_ISteamRemoteStorage_GetFileSize(steam_remote, filename); if (size <= 0) { JS_FreeCString(js, filename); - return JS_UNDEFINED; + return JS_NULL; } uint8_t *buffer = (uint8_t*)js_malloc(js, size); @@ -381,7 +381,7 @@ JSC_CCALL(cloud_read, if (read != size) { js_free(js, buffer); - return JS_UNDEFINED; + return JS_NULL; } JSValue result = js_new_blob_stoned_copy(js, buffer, size); @@ -509,6 +509,6 @@ extern "C" JSValue js_steam_use(JSContext *js) { #else // Stub when Steam is disabled extern "C" JSValue js_steam_use(JSContext *js) { - return JS_UNDEFINED; + return JS_NULL; } #endif diff --git a/source/qjs_transform.c b/source/qjs_transform.c index cdfa8371..260dbf9b 100644 --- a/source/qjs_transform.c +++ b/source/qjs_transform.c @@ -35,23 +35,23 @@ static JSValue js_transform_get_change_hook(JSContext *js, JSValueConst self) static JSValue js_transform_set_change_hook(JSContext *js, JSValueConst self, JSValue v) { transform *t = js2transform(js,self); - if (!JS_IsUndefined(v) && !JS_IsFunction(js,v)) return JS_ThrowReferenceError(js, "Hook must be a function."); + if (!JS_IsNull(v) && !JS_IsFunction(js,v)) return JS_ThrowReferenceError(js, "Hook must be a function."); JS_FreeValue(js,t->change_hook); t->change_hook = JS_DupValue(js,v); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_transform_get_parent(JSContext *js, JSValueConst self) { transform *t = js2transform(js,self); if (t->parent) return JS_DupValue(js,t->jsparent); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue v) { transform *p = js2transform(js,v); - if (!JS_IsUndefined(v) && !p) + if (!JS_IsNull(v) && !p) return JS_ThrowReferenceError(js,"Parent must be another transform."); transform *t = js2transform(js,self); @@ -62,7 +62,7 @@ static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue if (t->parent) { transform *cur_parent = t->parent; JS_FreeValue(js,t->jsparent); - t->jsparent = JS_UNDEFINED; + t->jsparent = JS_NULL; for (int i = 0; i < arrlen(cur_parent->children); i++) { if (cur_parent->children[i] == t) { @@ -91,7 +91,7 @@ static JSValue js_transform_set_parent(JSContext *js, JSValueConst self, JSValue transform_apply(t); - return JS_UNDEFINED; + return JS_NULL; } // TRANSFORM ACTION FUNCTIONS @@ -152,9 +152,9 @@ JSC_CCALL(transform_unit, JSC_CCALL(transform_trs, transform *t = js2transform(js,self); - t->pos = JS_IsUndefined(argv[0]) ? v3zero : js2vec3(js,argv[0]); - t->rotation = JS_IsUndefined(argv[1]) ? QUAT1 : js2quat(js,argv[1]); - t->scale = JS_IsUndefined(argv[2]) ? v3one : js2vec3(js,argv[2]); + t->pos = JS_IsNull(argv[0]) ? v3zero : js2vec3(js,argv[0]); + t->rotation = JS_IsNull(argv[1]) ? QUAT1 : js2quat(js,argv[1]); + t->scale = JS_IsNull(argv[2]) ? v3one : js2vec3(js,argv[2]); transform_apply(t); ) diff --git a/source/qjs_utf8.c b/source/qjs_utf8.c index 0852de50..f7fa00de 100644 --- a/source/qjs_utf8.c +++ b/source/qjs_utf8.c @@ -174,7 +174,7 @@ JSC_CCALL(utf8_char_at, if (!*ptr || count != index) { JS_FreeCString(js, str); - return JS_UNDEFINED; + return JS_NULL; } // Get the character diff --git a/source/qjs_wota.c b/source/qjs_wota.c index 5d9ef4db..bb479c56 100644 --- a/source/qjs_wota.c +++ b/source/qjs_wota.c @@ -61,8 +61,8 @@ static void wota_stack_free(WotaEncodeContext *enc) static JSValue apply_replacer(WotaEncodeContext *enc, JSValueConst holder, JSAtom key, JSValueConst val) { - if (JS_IsUndefined(enc->replacer)) return JS_DupValue(enc->ctx, val); - JSValue key_val = (key == JS_ATOM_NULL) ? JS_UNDEFINED : JS_AtomToValue(enc->ctx, key); + if (JS_IsNull(enc->replacer)) return JS_DupValue(enc->ctx, val); + JSValue key_val = (key == JS_ATOM_NULL) ? JS_NULL : JS_AtomToValue(enc->ctx, key); JSValue args[2] = { key_val, JS_DupValue(enc->ctx, val) }; JSValue result = JS_Call(enc->ctx, enc->replacer, holder, 2, args); JS_FreeValue(enc->ctx, args[0]); @@ -115,7 +115,7 @@ static void wota_encode_value(WotaEncodeContext *enc, JSValueConst val, JSValueC { JSContext *ctx = enc->ctx; JSValue replaced; - if (!JS_IsUndefined(enc->replacer) && key != JS_ATOM_NULL) + if (!JS_IsNull(enc->replacer) && key != JS_ATOM_NULL) replaced = apply_replacer(enc, holder, key, val); else replaced = JS_DupValue(enc->ctx, val); @@ -149,7 +149,6 @@ static void wota_encode_value(WotaEncodeContext *enc, JSValueConst val, JSValueC wota_write_sym(&enc->wb, JS_VALUE_GET_BOOL(replaced) ? WOTA_TRUE : WOTA_FALSE); break; case JS_TAG_NULL: - case JS_TAG_UNDEFINED: wota_write_sym(&enc->wb, WOTA_NULL); break; case JS_TAG_OBJECT: { @@ -180,7 +179,7 @@ static void wota_encode_value(WotaEncodeContext *enc, JSValueConst val, JSValueC } cell_rt *crt = JS_GetContextOpaque(ctx); JSValue adata = JS_GetProperty(ctx, replaced, crt->actor_sym); - if (!JS_IsUndefined(adata)) { + if (!JS_IsNull(adata)) { wota_write_sym(&enc->wb, WOTA_PRIVATE); wota_encode_value(enc, adata, replaced, JS_ATOM_NULL); JS_FreeValue(ctx, adata); @@ -237,16 +236,16 @@ static char *decode_wota_value(JSContext *ctx, char *data_ptr, JSValue *out_val, int scode; data_ptr = wota_read_sym(&scode, data_ptr); if (scode == WOTA_PRIVATE) { - JSValue inner = JS_UNDEFINED; + JSValue inner = JS_NULL; data_ptr = decode_wota_value(ctx, data_ptr, &inner, holder, JS_ATOM_NULL, reviver); JSValue obj = JS_NewObject(ctx); cell_rt *crt = JS_GetContextOpaque(ctx); JS_SetProperty(ctx, obj, crt->actor_sym, inner); *out_val = obj; - } else if (scode == WOTA_NULL) *out_val = JS_UNDEFINED; + } else if (scode == WOTA_NULL) *out_val = JS_NULL; else if (scode == WOTA_FALSE) *out_val = JS_NewBool(ctx, 0); else if (scode == WOTA_TRUE) *out_val = JS_NewBool(ctx, 1); - else *out_val = JS_UNDEFINED; + else *out_val = JS_NULL; break; } case WOTA_BLOB: { @@ -270,7 +269,7 @@ static char *decode_wota_value(JSContext *ctx, char *data_ptr, JSValue *out_val, JSValue arr = JS_NewArray(ctx); JS_SetLength(ctx, arr, c); for (long long i = 0; i < c; i++) { - JSValue elem_val = JS_UNDEFINED; + JSValue elem_val = JS_NULL; JSAtom idx_atom = JS_NewAtomUInt32(ctx, (uint32_t)i); data_ptr = decode_wota_value(ctx, data_ptr, &elem_val, arr, idx_atom, reviver); JS_SetPropertyUint32(ctx, arr, i, elem_val); @@ -289,7 +288,7 @@ static char *decode_wota_value(JSContext *ctx, char *data_ptr, JSValue *out_val, data_ptr = wota_read_text_len(&key_len, &tkey, data_ptr); if (!tkey) continue; // invalid key JSAtom prop_key = JS_NewAtomLen(ctx, tkey, key_len); - JSValue sub_val = JS_UNDEFINED; + JSValue sub_val = JS_NULL; data_ptr = decode_wota_value(ctx, data_ptr, &sub_val, obj, prop_key, reviver); JS_SetProperty(ctx, obj, prop_key, sub_val); JS_FreeAtom(ctx, prop_key); @@ -300,11 +299,11 @@ static char *decode_wota_value(JSContext *ctx, char *data_ptr, JSValue *out_val, } default: data_ptr += 8; - *out_val = JS_UNDEFINED; + *out_val = JS_NULL; break; } - if (!JS_IsUndefined(reviver)) { - JSValue key_val = (key == JS_ATOM_NULL) ? JS_UNDEFINED : JS_AtomToValue(ctx, key); + if (!JS_IsNull(reviver)) { + JSValue key_val = (key == JS_ATOM_NULL) ? JS_NULL : JS_AtomToValue(ctx, key); JSValue args[2] = { key_val, JS_DupValue(ctx, *out_val) }; JSValue revived = JS_Call(ctx, reviver, holder, 2, args); JS_FreeValue(ctx, args[0]); @@ -327,7 +326,7 @@ void *value2wota(JSContext *ctx, JSValue v, JSValue replacer, size_t *bytes) enc->cycle = 0; enc->replacer = replacer; wota_buffer_init(&enc->wb, 16); - wota_encode_value(enc, v, JS_UNDEFINED, JS_ATOM_NULL); + wota_encode_value(enc, v, JS_NULL, JS_ATOM_NULL); if (enc->cycle) { wota_stack_free(enc); wota_buffer_free(&enc->wb); @@ -342,9 +341,9 @@ void *value2wota(JSContext *ctx, JSValue v, JSValue replacer, size_t *bytes) JSValue wota2value(JSContext *ctx, void *wota) { - JSValue result = JS_UNDEFINED; + JSValue result = JS_NULL; JSValue holder = JS_NewObject(ctx); - decode_wota_value(ctx, wota, &result, holder, JS_ATOM_NULL, JS_UNDEFINED); + decode_wota_value(ctx, wota, &result, holder, JS_ATOM_NULL, JS_NULL); JS_FreeValue(ctx, holder); return result; } @@ -353,7 +352,7 @@ static JSValue js_wota_encode(JSContext *ctx, JSValueConst this_val, int argc, J { if (argc < 1) return JS_ThrowTypeError(ctx, "wota.encode requires at least 1 argument"); size_t total_bytes; - void *wota = value2wota(ctx, argv[0], JS_IsFunction(ctx,argv[1]) ? argv[1] : JS_UNDEFINED, &total_bytes); + void *wota = value2wota(ctx, argv[0], JS_IsFunction(ctx,argv[1]) ? argv[1] : JS_NULL, &total_bytes); JSValue ret = js_new_blob_stoned_copy(ctx, wota, total_bytes); free(wota); return ret; @@ -361,13 +360,13 @@ static JSValue js_wota_encode(JSContext *ctx, JSValueConst this_val, int argc, J static JSValue js_wota_decode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - if (argc < 1) return JS_UNDEFINED; + if (argc < 1) return JS_NULL; size_t len; uint8_t *buf = js_get_blob_data(ctx, &len, argv[0]); - if (!buf) return JS_UNDEFINED; - JSValue reviver = (argc > 1 && JS_IsFunction(ctx, argv[1])) ? argv[1] : JS_UNDEFINED; + if (!buf) return JS_NULL; + JSValue reviver = (argc > 1 && JS_IsFunction(ctx, argv[1])) ? argv[1] : JS_NULL; char *data_ptr = (char *)buf; - JSValue result = JS_UNDEFINED; + JSValue result = JS_NULL; JSValue holder = JS_NewObject(ctx); JSAtom empty_atom = JS_NewAtom(ctx, ""); decode_wota_value(ctx, data_ptr, &result, holder, empty_atom, reviver); diff --git a/source/quickjs-libc.c b/source/quickjs-libc.c index 10a7d00c..4b9d0ae5 100644 --- a/source/quickjs-libc.c +++ b/source/quickjs-libc.c @@ -653,7 +653,7 @@ int js_module_test_json(JSContext *ctx, JSValueConst attributes) size_t len; BOOL res; - if (JS_IsUndefined(attributes)) + if (JS_IsNull(attributes)) return FALSE; str = JS_GetPropertyStr(ctx, attributes, "type"); if (!JS_IsString(str)) @@ -734,7 +734,7 @@ static JSValue js_std_exit(JSContext *ctx, JSValueConst this_val, if (JS_ToInt32(ctx, &status, argv[0])) status = -1; exit(status); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_getenv(JSContext *ctx, JSValueConst this_val, @@ -747,7 +747,7 @@ static JSValue js_std_getenv(JSContext *ctx, JSValueConst this_val, str = getenv(name); JS_FreeCString(ctx, name); if (!str) - return JS_UNDEFINED; + return JS_NULL; else return JS_NewString(ctx, str); } @@ -789,7 +789,7 @@ static JSValue js_std_setenv(JSContext *ctx, JSValueConst this_val, setenv(name, value, TRUE); JS_FreeCString(ctx, name); JS_FreeCString(ctx, value); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_unsetenv(JSContext *ctx, JSValueConst this_val, @@ -801,7 +801,7 @@ static JSValue js_std_unsetenv(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; unsetenv(name); JS_FreeCString(ctx, name); - return JS_UNDEFINED; + return JS_NULL; } /* return an object containing the list of the available environment @@ -847,7 +847,7 @@ static JSValue js_std_gc(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { JS_RunGC(JS_GetRuntime(ctx)); - return JS_UNDEFINED; + return JS_NULL; } static int interrupt_handler(JSRuntime *rt, void *opaque) @@ -863,7 +863,7 @@ static int get_bool_option(JSContext *ctx, BOOL *pbool, val = JS_GetPropertyStr(ctx, obj, option); if (JS_IsException(val)) return -1; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { *pbool = JS_ToBool(ctx, val); } JS_FreeValue(ctx, val); @@ -995,7 +995,7 @@ static JSValue js_new_std_file(JSContext *ctx, FILE *f, static void js_set_error_object(JSContext *ctx, JSValue obj, int err) { - if (!JS_IsUndefined(obj)) { + if (!JS_IsNull(obj)) { JS_SetPropertyStr(ctx, obj, "errno", JS_NewInt32(ctx, err)); } } @@ -1164,7 +1164,7 @@ static JSValue js_std_file_puts(JSContext *ctx, JSValueConst this_val, fwrite(str, 1, len, f); JS_FreeCString(ctx, str); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_file_close(JSContext *ctx, JSValueConst this_val, @@ -1203,7 +1203,7 @@ static JSValue js_std_file_printObject(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { JS_PrintValue(ctx, js_print_value_write, stdout, argv[0], NULL); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_file_flush(JSContext *ctx, JSValueConst this_val, @@ -1213,7 +1213,7 @@ static JSValue js_std_file_flush(JSContext *ctx, JSValueConst this_val, if (!f) return JS_EXCEPTION; fflush(f); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_file_tell(JSContext *ctx, JSValueConst this_val, @@ -1281,7 +1281,7 @@ static JSValue js_std_file_clearerr(JSContext *ctx, JSValueConst this_val, if (!f) return JS_EXCEPTION; clearerr(f); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_std_file_fileno(JSContext *ctx, JSValueConst this_val, @@ -1373,9 +1373,9 @@ static JSValue js_std_file_readAsString(JSContext *ctx, JSValueConst this_val, if (argc >= 1) max_size_val = argv[0]; else - max_size_val = JS_UNDEFINED; + max_size_val = JS_NULL; max_size = (size_t)-1; - if (!JS_IsUndefined(max_size_val)) { + if (!JS_IsNull(max_size_val)) { if (JS_ToIndex(ctx, &max_size64, max_size_val)) return JS_EXCEPTION; if (max_size64 < max_size) @@ -1469,7 +1469,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val, char *buf; size_t i, len; int status; - JSValue response = JS_UNDEFINED, ret_obj; + JSValue response = JS_NULL, ret_obj; JSValueConst options_obj; FILE *f; BOOL binary_flag, full_flag; @@ -1736,7 +1736,7 @@ static JSValue js_os_open(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; if (JS_ToInt32(ctx, &flags, argv[1])) goto fail; - if (argc >= 3 && !JS_IsUndefined(argv[2])) { + if (argc >= 3 && !JS_IsNull(argv[2])) { if (JS_ToInt32(ctx, &mode, argv[2])) { fail: JS_FreeCString(ctx, filename); @@ -1866,7 +1866,7 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val, handle = (HANDLE)_get_osfhandle(1); /* corresponding output */ SetConsoleMode(handle, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | __ENABLE_VIRTUAL_TERMINAL_PROCESSING); } - return JS_UNDEFINED; + return JS_NULL; } #else static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val, @@ -1924,7 +1924,7 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val, tcsetattr(fd, TCSANOW, &tty); atexit(term_exit); - return JS_UNDEFINED; + return JS_NULL; } #endif /* !_WIN32 */ @@ -2043,7 +2043,7 @@ static JSValue js_os_setReadHandler(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, rh->rw_func[magic]); rh->rw_func[magic] = JS_DupValue(ctx, func); } - return JS_UNDEFINED; + return JS_NULL; } static JSOSSignalHandler *find_sh(JSThreadState *ts, int sig_num) @@ -2093,7 +2093,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValueConst this_val, return JS_ThrowRangeError(ctx, "invalid signal number"); func = argv[1]; /* func = null: SIG_DFL, func = undefined, SIG_IGN */ - if (JS_IsNull(func) || JS_IsUndefined(func)) { + if (JS_IsNull(func) || JS_IsNull(func)) { sh = find_sh(ts, sig_num); if (sh) { free_sh(JS_GetRuntime(ctx), sh); @@ -2118,7 +2118,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValueConst this_val, sh->func = JS_DupValue(ctx, func); signal(sig_num, os_signal_handler); } - return JS_UNDEFINED; + return JS_NULL; } #if defined(__linux__) || defined(__APPLE__) @@ -2218,9 +2218,9 @@ static JSValue js_os_clearTimeout(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; th = find_timer_by_id(ts, timer_id); if (!th) - return JS_UNDEFINED; + return JS_NULL; free_timer(rt, th); - return JS_UNDEFINED; + return JS_NULL; } /* return a promise */ @@ -2261,7 +2261,7 @@ static void call_handler(JSContext *ctx, JSValueConst func) /* 'func' might be destroyed when calling itself (if it frees the handler), so must take extra care */ func1 = JS_DupValue(ctx, func); - ret = JS_Call(ctx, func1, JS_UNDEFINED, 0, NULL); + ret = JS_Call(ctx, func1, JS_NULL, 0, NULL); JS_FreeValue(ctx, func1); if (JS_IsException(ret)) js_std_dump_error(ctx); @@ -2386,7 +2386,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx, /* 'func' might be destroyed when calling itself (if it frees the handler), so must take extra care */ func = JS_DupValue(ctx, port->on_message_func); - retval = JS_Call(ctx, func, JS_UNDEFINED, 1, (JSValueConst *)&obj); + retval = JS_Call(ctx, func, JS_NULL, 1, (JSValueConst *)&obj); JS_FreeValue(ctx, obj); JS_FreeValue(ctx, func); if (JS_IsException(retval)) { @@ -2439,7 +2439,7 @@ static int js_os_poll(JSContext *ctx) JSValue func; /* the timer expired */ func = th->func; - th->func = JS_UNDEFINED; + th->func = JS_NULL; free_timer(rt, th); call_handler(ctx, func); JS_FreeValue(ctx, func); @@ -2549,7 +2549,7 @@ static int js_os_poll(JSContext *ctx) JSValue func; /* the timer expired */ func = th->func; - th->func = JS_UNDEFINED; + th->func = JS_NULL; free_timer(rt, th); call_handler(ctx, func); JS_FreeValue(ctx, func); @@ -3164,7 +3164,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, "file"); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { file = JS_ToCString(ctx, val); JS_FreeValue(ctx, val); if (!file) @@ -3174,7 +3174,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, "cwd"); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { cwd = JS_ToCString(ctx, val); JS_FreeValue(ctx, val); if (!cwd) @@ -3186,7 +3186,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, std_name[i]); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { int fd; ret = JS_ToInt32(ctx, &fd, val); JS_FreeValue(ctx, val); @@ -3199,7 +3199,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, "env"); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { envp = build_envp(ctx, val); JS_FreeValue(ctx, val); if (!envp) @@ -3209,7 +3209,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, "uid"); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { ret = JS_ToUint32(ctx, &uid, val); JS_FreeValue(ctx, val); if (ret) @@ -3219,7 +3219,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val, val = JS_GetPropertyStr(ctx, options, "gid"); if (JS_IsException(val)) goto exception; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { ret = JS_ToUint32(ctx, &gid, val); JS_FreeValue(ctx, val); if (ret) @@ -3619,11 +3619,11 @@ static JSValue js_worker_ctor_internal(JSContext *ctx, JSValueConst new_target, JSWorkerMessagePipe *recv_pipe, JSWorkerMessagePipe *send_pipe) { - JSValue obj = JS_UNDEFINED, proto; + JSValue obj = JS_NULL, proto; JSWorkerData *s; /* create the object */ - if (JS_IsUndefined(new_target)) { + if (JS_IsNull(new_target)) { proto = JS_GetClassProto(ctx, js_worker_class_id); } else { proto = JS_GetPropertyStr(ctx, new_target, "prototype"); @@ -3654,7 +3654,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target, WorkerFuncArgs *args = NULL; pthread_t tid; pthread_attr_t attr; - JSValue obj = JS_UNDEFINED; + JSValue obj = JS_NULL; int ret; const char *filename = NULL, *basename; JSAtom basename_atom; @@ -3785,7 +3785,7 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val, js_waker_signal(&ps->waker); list_add_tail(&msg->link, &ps->msg_queue); pthread_mutex_unlock(&ps->mutex); - return JS_UNDEFINED; + return JS_NULL; fail: if (msg) { free(msg->data); @@ -3830,7 +3830,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, port->on_message_func); port->on_message_func = JS_DupValue(ctx, func); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_worker_get_onmessage(JSContext *ctx, JSValueConst this_val) @@ -3982,7 +3982,7 @@ static int js_os_init(JSContext *ctx, JSModuleDef *m) /* set 'Worker.parent' if necessary */ if (ts->recv_pipe && ts->send_pipe) { JS_DefinePropertyValueStr(ctx, obj, "parent", - js_worker_ctor_internal(ctx, JS_UNDEFINED, ts->recv_pipe, ts->send_pipe), + js_worker_ctor_internal(ctx, JS_NULL, ts->recv_pipe, ts->send_pipe), JS_PROP_C_W_E); } @@ -4032,7 +4032,7 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val, } } putchar('\n'); - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_console_log(JSContext *ctx, JSValueConst this_val, diff --git a/source/quickjs-opcode.h b/source/quickjs-opcode.h index cf25201d..cc789d27 100644 --- a/source/quickjs-opcode.h +++ b/source/quickjs-opcode.h @@ -69,7 +69,6 @@ DEF( push_i32, 5, 0, 1, i32) DEF( push_const, 5, 0, 1, const) DEF( fclosure, 5, 0, 1, const) /* must follow push_const */ DEF(push_atom_value, 5, 0, 1, atom) -DEF( undefined, 1, 0, 1, none) DEF( null, 1, 0, 1, none) DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */ DEF( push_false, 1, 0, 1, none) @@ -232,7 +231,6 @@ DEF( strict_neq, 1, 2, 1, none) DEF( and, 1, 2, 1, none) DEF( xor, 1, 2, 1, none) DEF( or, 1, 2, 1, none) -DEF(is_undefined_or_null, 1, 1, 1, none) DEF(push_bigint_i32, 5, 0, 1, i32) /* must be the last non short and non temporary opcode */ DEF( nop, 1, 0, 0, none) @@ -333,9 +331,7 @@ DEF( call1, 1, 1, 1, npopx) DEF( call2, 1, 1, 1, npopx) DEF( call3, 1, 1, 1, npopx) -DEF( is_undefined, 1, 1, 1, none) DEF( is_null, 1, 1, 1, none) -DEF(typeof_is_undefined, 1, 1, 1, none) DEF( typeof_is_function, 1, 1, 1, none) #endif diff --git a/source/quickjs.c b/source/quickjs.c index bfb79c78..2394c03a 100644 --- a/source/quickjs.c +++ b/source/quickjs.c @@ -261,7 +261,7 @@ struct JSClass { typedef struct JSStackFrame { struct JSStackFrame *prev_frame; /* NULL if first stack frame */ - JSValue cur_func; /* current function, JS_UNDEFINED if the frame is detached */ + JSValue cur_func; /* current function, JS_NULL if the frame is detached */ JSValue *arg_buf; /* arguments */ JSValue *var_buf; /* variables */ struct list_head var_ref_list; /* list of JSVarRef.var_ref_link */ @@ -2651,7 +2651,7 @@ static BOOL JS_AtomIsArrayIndex(JSContext *ctx, uint32_t *pval, JSAtom atom) } /* This test must be fast if atom is not a numeric index (e.g. a - method name). Return JS_UNDEFINED if not a numeric + method name). Return JS_NULL if not a numeric index. JS_EXCEPTION can also be returned. */ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) { @@ -2666,7 +2666,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) assert(atom < rt->atom_size); p1 = rt->atom_array[atom]; if (p1->atom_type != JS_ATOM_TYPE_STRING) - return JS_UNDEFINED; + return JS_NULL; switch(atom) { case JS_ATOM_minus_zero: return __JS_NewFloat64(ctx, -0.0); @@ -2681,10 +2681,10 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) } p = p1; if (p->len == 0) - return JS_UNDEFINED; + return JS_NULL; c = string_get(p, 0); if (!is_num(c) && c != '-') - return JS_UNDEFINED; + return JS_NULL; /* this is ECMA CanonicalNumericIndexString primitive */ num = JS_ToNumber(ctx, JS_MKPTR(JS_TAG_STRING, p)); if (JS_IsException(num)) @@ -2700,7 +2700,7 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) return num; } else { JS_FreeValue(ctx, num); - return JS_UNDEFINED; + return JS_NULL; } } @@ -2709,7 +2709,7 @@ int JS_AtomIsNumericIndex(JSContext *ctx, JSAtom atom) { JSValue num; num = JS_AtomIsNumericIndex1(ctx, atom); - if (likely(JS_IsUndefined(num))) + if (likely(JS_IsNull(num))) return FALSE; if (JS_IsException(num)) return -1; @@ -4582,7 +4582,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas } break; case JS_CLASS_C_FUNCTION: - p->prop[0].u.value = JS_UNDEFINED; + p->prop[0].u.value = JS_NULL; break; case JS_CLASS_ARGUMENTS: p->is_exotic = 1; @@ -4594,7 +4594,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas case JS_CLASS_BOOLEAN: case JS_CLASS_SYMBOL: case JS_CLASS_BIG_INT: - p->u.object_data = JS_UNDEFINED; + p->u.object_data = JS_NULL; goto set_exotic; case JS_CLASS_REGEXP: p->u.regexp.pattern = NULL; @@ -4655,7 +4655,7 @@ static JSValue JS_GetObjectData(JSContext *ctx, JSValueConst obj) return JS_DupValue(ctx, p->u.object_data); } } - return JS_UNDEFINED; + return JS_NULL; } #endif @@ -4859,7 +4859,7 @@ static JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj, for(i = 0; i < argc; i++) arg_buf[i] = argv[i]; for(i = argc; i < s->length; i++) - arg_buf[i] = JS_UNDEFINED; + arg_buf[i] = JS_NULL; } else { arg_buf = argv; } @@ -5026,7 +5026,7 @@ static void js_object_data_finalizer(JSRuntime *rt, JSValue val) { JSObject *p = JS_VALUE_GET_OBJ(val); JS_FreeValueRT(rt, p->u.object_data); - p->u.object_data = JS_UNDEFINED; + p->u.object_data = JS_NULL; } static void js_object_data_mark(JSRuntime *rt, JSValueConst val, @@ -6500,8 +6500,7 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj, JSShape *sh; if (throw_flag) { - if (JS_VALUE_GET_TAG(obj) == JS_TAG_NULL || - JS_VALUE_GET_TAG(obj) == JS_TAG_UNDEFINED) + if (JS_VALUE_GET_TAG(obj) == JS_TAG_NULL) goto not_obj; } else { if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) @@ -6612,7 +6611,6 @@ static JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueConst val) break; case JS_TAG_OBJECT: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: default: val = JS_NULL; break; @@ -6736,7 +6734,7 @@ int JS_IsInstanceOf(JSContext *ctx, JSValueConst val, JSValueConst obj) method = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_hasInstance); if (JS_IsException(method)) return -1; - if (!JS_IsNull(method) && !JS_IsUndefined(method)) { + if (!JS_IsNull(method) && !JS_IsNull(method)) { JSValue ret; ret = JS_CallFree(ctx, method, obj, 1, &val); return JS_ToBoolFree(ctx, ret); @@ -6778,7 +6776,7 @@ static int JS_AutoInitProperty(JSContext *ctx, JSObject *p, JSAtom prop, val = func(realm, p, prop, pr->u.init.opaque); js_autoinit_free(ctx->rt, pr); prs->flags &= ~JS_PROP_TMASK; - pr->u.value = JS_UNDEFINED; + pr->u.value = JS_NULL; if (JS_IsException(val)) return -1; pr->u.value = val; @@ -6799,8 +6797,6 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, switch(tag) { case JS_TAG_NULL: return JS_ThrowTypeErrorAtom(ctx, "cannot read property '%s' of null", prop); - case JS_TAG_UNDEFINED: - return JS_ThrowTypeErrorAtom(ctx, "cannot read property '%s' of undefined", prop); case JS_TAG_EXCEPTION: return JS_EXCEPTION; case JS_TAG_STRING: @@ -6837,7 +6833,7 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, /* cannot raise an exception */ p = JS_VALUE_GET_OBJ(JS_GetPrototypePrimitive(ctx, obj)); if (!p) - return JS_UNDEFINED; + return JS_NULL; } else { p = JS_VALUE_GET_OBJ(obj); } @@ -6849,7 +6845,7 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, if (unlikely(prs->flags & JS_PROP_TMASK)) { if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) { if (unlikely(!pr->u.getset.getter)) { - return JS_UNDEFINED; + return JS_NULL; } else { JSValue func = JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.getter); /* Note: the field could be removed in the getter */ @@ -6925,7 +6921,7 @@ JSValue JS_GetPropertyInternal(JSContext *ctx, JSValueConst obj, if (unlikely(throw_ref_error)) { return JS_ThrowReferenceErrorNotDefined(ctx, prop); } else { - return JS_UNDEFINED; + return JS_NULL; } } @@ -7301,9 +7297,9 @@ retry: if (prs) { if (desc) { desc->flags = prs->flags & JS_PROP_C_W_E; - desc->getter = JS_UNDEFINED; - desc->setter = JS_UNDEFINED; - desc->value = JS_UNDEFINED; + desc->getter = JS_NULL; + desc->setter = JS_NULL; + desc->value = JS_NULL; if (unlikely(prs->flags & JS_PROP_TMASK)) { if ((prs->flags & JS_PROP_TMASK) == JS_PROP_GETSET) { desc->flags |= JS_PROP_GETSET; @@ -7350,8 +7346,8 @@ retry: if (desc) { desc->flags = JS_PROP_WRITABLE | JS_PROP_ENUMERABLE | JS_PROP_CONFIGURABLE; - desc->getter = JS_UNDEFINED; - desc->setter = JS_UNDEFINED; + desc->getter = JS_NULL; + desc->setter = JS_NULL; desc->value = JS_GetPropertyUint32(ctx, JS_MKPTR(JS_TAG_OBJECT, p), idx); } return TRUE; @@ -7505,9 +7501,9 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj, } else { slow_path: /* ToObject() must be done before ToPropertyKey() */ - if (JS_IsNull(this_obj) || JS_IsUndefined(this_obj)) { + if (JS_IsNull(this_obj)) { JS_FreeValue(ctx, prop); - return JS_ThrowTypeError(ctx, "cannot read property of %s", JS_IsNull(this_obj) ? "null" : "undefined"); + return JS_ThrowTypeError(ctx, "cannot read property of null"); } atom = JS_ValueToAtom(ctx, prop); JS_FreeValue(ctx, prop); @@ -7532,7 +7528,7 @@ JSValue JS_GetPropertyUint32(JSContext *ctx, JSValueConst this_obj, */ static int JS_TryGetPropertyInt64(JSContext *ctx, JSValueConst obj, int64_t idx, JSValue *pval) { - JSValue val = JS_UNDEFINED; + JSValue val = JS_NULL; JSAtom prop; int present; @@ -7713,7 +7709,7 @@ static int delete_property(JSContext *ctx, JSObject *p, JSAtom atom) /* put default values */ pr->flags = 0; pr->atom = JS_ATOM_NULL; - pr1->u.value = JS_UNDEFINED; + pr1->u.value = JS_NULL; /* compact the properties if too many deleted properties */ if (sh->deleted_prop_count >= 8 && @@ -7983,10 +7979,6 @@ int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, JS_FreeValue(ctx, val); JS_ThrowTypeErrorAtom(ctx, "cannot set property '%s' of null", prop); return -1; - case JS_TAG_UNDEFINED: - JS_FreeValue(ctx, val); - JS_ThrowTypeErrorAtom(ctx, "cannot set property '%s' of undefined", prop); - return -1; default: /* even on a primitive type we can have setters on the prototype */ p = NULL; @@ -8069,7 +8061,7 @@ int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, if (ret) { if (desc.flags & JS_PROP_GETSET) { JSObject *setter; - if (JS_IsUndefined(desc.setter)) + if (JS_IsNull(desc.setter)) setter = NULL; else setter = JS_VALUE_GET_OBJ(desc.setter); @@ -8083,7 +8075,7 @@ int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, goto read_only_prop; if (likely(p == p1)) { ret = JS_DefineProperty(ctx, this_obj, prop, val, - JS_UNDEFINED, JS_UNDEFINED, + JS_NULL, JS_NULL, JS_PROP_HAS_VALUE); JS_FreeValue(ctx, val); return ret; @@ -8180,13 +8172,13 @@ int JS_SetPropertyInternal(JSContext *ctx, JSValueConst obj, } } ret = JS_DefineProperty(ctx, this_obj, prop, val, - JS_UNDEFINED, JS_UNDEFINED, + JS_NULL, JS_NULL, JS_PROP_HAS_VALUE); JS_FreeValue(ctx, val); return ret; } else { generic_create_prop: - ret = JS_CreateProperty(ctx, p, prop, val, JS_UNDEFINED, JS_UNDEFINED, + ret = JS_CreateProperty(ctx, p, prop, val, JS_NULL, JS_NULL, flags | JS_PROP_HAS_VALUE | JS_PROP_HAS_ENUMERABLE | @@ -8418,7 +8410,7 @@ static int JS_CreateProperty(JSContext *ctx, JSObject *p, if (flags & JS_PROP_HAS_VALUE) { pr->u.value = JS_DupValue(ctx, val); } else { - pr->u.value = JS_UNDEFINED; + pr->u.value = JS_NULL; } } return TRUE; @@ -8613,7 +8605,7 @@ int JS_DefineProperty(JSContext *ctx, JSValueConst this_obj, if (pr->u.getset.setter) JS_FreeValue(ctx, JS_MKPTR(JS_TAG_OBJECT, pr->u.getset.setter)); prs->flags &= ~(JS_PROP_TMASK | JS_PROP_WRITABLE); - pr->u.value = JS_UNDEFINED; + pr->u.value = JS_NULL; } else if ((prs->flags & JS_PROP_TMASK) == JS_PROP_VARREF) { /* Note: JS_PROP_VARREF is always writable */ } else { @@ -8754,7 +8746,7 @@ int JS_DefinePropertyValue(JSContext *ctx, JSValueConst this_obj, JSAtom prop, JSValue val, int flags) { int ret; - ret = JS_DefineProperty(ctx, this_obj, prop, val, JS_UNDEFINED, JS_UNDEFINED, + ret = JS_DefineProperty(ctx, this_obj, prop, val, JS_NULL, JS_NULL, flags | JS_PROP_HAS_VALUE | JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_WRITABLE | JS_PROP_HAS_ENUMERABLE); JS_FreeValue(ctx, val); return ret; @@ -8811,7 +8803,7 @@ int JS_DefinePropertyGetSet(JSContext *ctx, JSValueConst this_obj, int flags) { int ret; - ret = JS_DefineProperty(ctx, this_obj, prop, JS_UNDEFINED, getter, setter, + ret = JS_DefineProperty(ctx, this_obj, prop, JS_NULL, getter, setter, flags | JS_PROP_HAS_GET | JS_PROP_HAS_SET | JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_ENUMERABLE); JS_FreeValue(ctx, getter); @@ -8949,7 +8941,7 @@ static int JS_DefineGlobalVar(JSContext *ctx, JSAtom prop, int def_flags) p = JS_VALUE_GET_OBJ(ctx->global_obj); flags = JS_PROP_ENUMERABLE | JS_PROP_WRITABLE | (def_flags & JS_PROP_CONFIGURABLE); - val = JS_UNDEFINED; + val = JS_NULL; } prs = find_own_property1(p, prop); if (prs) @@ -8981,7 +8973,7 @@ static int JS_DefineGlobalFunction(JSContext *ctx, JSAtom prop, JS_PROP_HAS_CONFIGURABLE | JS_PROP_HAS_WRITABLE | JS_PROP_HAS_ENUMERABLE; } if (JS_DefineProperty(ctx, ctx->global_obj, prop, func, - JS_UNDEFINED, JS_UNDEFINED, flags) < 0) + JS_NULL, JS_NULL, flags) < 0) return -1; return 0; } @@ -9036,7 +9028,7 @@ static int JS_GetGlobalVarRef(JSContext *ctx, JSAtom prop, JSValue *sp) if (ret) { sp[0] = JS_DupValue(ctx, ctx->global_obj); } else { - sp[0] = JS_UNDEFINED; + sp[0] = JS_NULL; } } sp[1] = JS_AtomToValue(ctx, prop); @@ -9289,7 +9281,7 @@ static JSValue JS_ToPrimitiveFree(JSContext *ctx, JSValue val, int hint) goto exception; /* ECMA says *If exoticToPrim is not undefined* but tests in test262 use null as a non callable converter */ - if (!JS_IsUndefined(method) && !JS_IsNull(method)) { + if (!JS_IsNull(method) && !JS_IsNull(method)) { JSAtom atom; JSValue arg; switch(hint) { @@ -9359,7 +9351,6 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val) return JS_VALUE_GET_INT(val) != 0; case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: return JS_VALUE_GET_INT(val); case JS_TAG_EXCEPTION: return -1; @@ -11159,9 +11150,6 @@ static JSValue JS_ToNumberHintFree(JSContext *ctx, JSValue val, case JS_TAG_NULL: ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val)); break; - case JS_TAG_UNDEFINED: - ret = JS_NAN; - break; case JS_TAG_OBJECT: val = JS_ToPrimitiveFree(ctx, val, HINT_NUMBER); if (JS_IsException(val)) @@ -11287,7 +11275,6 @@ static __maybe_unused JSValue JS_ToIntegerFree(JSContext *ctx, JSValue val) case JS_TAG_INT: case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: ret = JS_NewInt32(ctx, JS_VALUE_GET_INT(val)); break; case JS_TAG_FLOAT64: @@ -11323,7 +11310,6 @@ static int JS_ToInt32SatFree(JSContext *ctx, int *pres, JSValue val) case JS_TAG_INT: case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: ret = JS_VALUE_GET_INT(val); break; case JS_TAG_EXCEPTION: @@ -11388,7 +11374,6 @@ static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val) case JS_TAG_INT: case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: *pres = JS_VALUE_GET_INT(val); return 0; case JS_TAG_EXCEPTION: @@ -11452,7 +11437,6 @@ static int JS_ToInt64Free(JSContext *ctx, int64_t *pres, JSValue val) case JS_TAG_INT: case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: ret = JS_VALUE_GET_INT(val); break; case JS_TAG_FLOAT64: @@ -11517,7 +11501,6 @@ static int JS_ToInt32Free(JSContext *ctx, int32_t *pres, JSValue val) case JS_TAG_INT: case JS_TAG_BOOL: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: ret = JS_VALUE_GET_INT(val); break; case JS_TAG_FLOAT64: @@ -11726,8 +11709,6 @@ static JSValue JS_ToStringInternal(JSContext *ctx, JSValueConst val, BOOL is_ToP JS_ATOM_true : JS_ATOM_false); case JS_TAG_NULL: return JS_AtomToString(ctx, JS_ATOM_null); - case JS_TAG_UNDEFINED: - return JS_AtomToString(ctx, JS_ATOM_undefined); case JS_TAG_EXCEPTION: return JS_EXCEPTION; case JS_TAG_OBJECT: @@ -11775,7 +11756,7 @@ static JSValue JS_ToStringFree(JSContext *ctx, JSValue val) static JSValue JS_ToLocaleStringFree(JSContext *ctx, JSValue val) { - if (JS_IsUndefined(val) || JS_IsNull(val)) + if (JS_IsNull(val) || JS_IsNull(val)) return JS_ToStringFree(ctx, val); return JS_InvokeFree(ctx, val, JS_ATOM_toLocaleString, 0, NULL); } @@ -11788,8 +11769,8 @@ JSValue JS_ToPropertyKey(JSContext *ctx, JSValueConst val) static JSValue JS_ToStringCheckObject(JSContext *ctx, JSValueConst val) { uint32_t tag = JS_VALUE_GET_TAG(val); - if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED) - return JS_ThrowTypeError(ctx, "null or undefined are forbidden"); + if (tag == JS_TAG_NULL) + return JS_ThrowTypeError(ctx, "null is forbidden"); return JS_ToString(ctx, val); } @@ -12299,8 +12280,6 @@ static void js_print_value(JSPrintValueState *s, JSValueConst val) case JS_TAG_UNINITIALIZED: str = "uninitialized"; goto print_str; - case JS_TAG_UNDEFINED: - str = "undefined"; print_str: js_puts(s, str); break; @@ -12640,7 +12619,6 @@ static JSValue JS_ToBigIntFree(JSContext *ctx, JSValue val) break; case JS_TAG_INT: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: case JS_TAG_FLOAT64: goto fail; case JS_TAG_BOOL: @@ -12837,7 +12815,7 @@ static no_inline __exception int js_unary_arith_slow(JSContext *ctx, } return 0; exception: - sp[-1] = JS_UNDEFINED; + sp[-1] = JS_NULL; return -1; } @@ -12850,7 +12828,7 @@ static __exception int js_post_inc_slow(JSContext *ctx, op1 = sp[-1]; op1 = JS_ToNumericFree(ctx, op1); if (JS_IsException(op1)) { - sp[-1] = JS_UNDEFINED; + sp[-1] = JS_NULL; return -1; } sp[-1] = op1; @@ -12883,7 +12861,7 @@ static no_inline int js_not_slow(JSContext *ctx, JSValue *sp) } return 0; exception: - sp[-1] = JS_UNDEFINED; + sp[-1] = JS_NULL; return -1; } @@ -13085,8 +13063,8 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s } return 0; exception: - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -13206,8 +13184,8 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp) } return 0; exception: - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -13361,8 +13339,8 @@ static no_inline int js_relational_slow(JSContext *ctx, JSValue *sp, return 0; exception: - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -13409,8 +13387,7 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp, } } else if (tag1 == tag2) { res = js_strict_eq2(ctx, op1, op2, JS_EQ_STRICT); - } else if ((tag1 == JS_TAG_NULL && tag2 == JS_TAG_UNDEFINED) || - (tag2 == JS_TAG_NULL && tag1 == JS_TAG_UNDEFINED)) { + } else if (tag1 == JS_TAG_NULL && tag2 == JS_TAG_NULL) { res = TRUE; } else if (tag_is_string(tag1) && tag_is_string(tag2)) { /* needed when comparing strings and ropes */ @@ -13480,8 +13457,8 @@ static no_inline __exception int js_eq_slow(JSContext *ctx, JSValue *sp, sp[-2] = JS_NewBool(ctx, res ^ is_neq); return 0; exception: - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -13518,8 +13495,8 @@ static no_inline int js_shr_slow(JSContext *ctx, JSValue *sp) sp[-2] = JS_NewUint32(ctx, r); return 0; exception: - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -13544,7 +13521,6 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, } break; case JS_TAG_NULL: - case JS_TAG_UNDEFINED: res = (tag1 == tag2); break; case JS_TAG_STRING: @@ -13752,9 +13728,6 @@ static __exception int js_operator_typeof(JSContext *ctx, JSValueConst op1) case JS_TAG_FLOAT64: atom = JS_ATOM_number; break; - case JS_TAG_UNDEFINED: - atom = JS_ATOM_undefined; - break; case JS_TAG_BOOL: atom = JS_ATOM_boolean; break; @@ -13771,6 +13744,8 @@ static __exception int js_operator_typeof(JSContext *ctx, JSValueConst op1) } break; case JS_TAG_NULL: + atom = JS_ATOM_null; + break; obj_type: atom = JS_ATOM_object; break; @@ -13815,7 +13790,7 @@ static JSValue js_throw_type_error(JSContext *ctx, JSValueConst this_val, if (!b || (b->js_mode & JS_MODE_STRICT) || !b->has_prototype || argc >= 1) { return JS_ThrowTypeError(ctx, "invalid property access"); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_function_proto_fileName(JSContext *ctx, @@ -13825,7 +13800,7 @@ static JSValue js_function_proto_fileName(JSContext *ctx, if (b && b->has_debug) { return JS_AtomToString(ctx, b->debug.filename); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_function_proto_lineNumber(JSContext *ctx, @@ -13840,7 +13815,7 @@ static JSValue js_function_proto_lineNumber(JSContext *ctx, else return JS_NewInt32(ctx, line_num); } - return JS_UNDEFINED; + return JS_NULL; } static int js_arguments_define_own_property(JSContext *ctx, @@ -13903,7 +13878,7 @@ static JSValue js_build_arguments(JSContext *ctx, int argc, JSValueConst *argv) JS_DupValue(ctx, ctx->array_proto_values), JS_PROP_CONFIGURABLE | JS_PROP_WRITABLE); /* add callee property to throw a TypeError in strict mode */ - JS_DefineProperty(ctx, val, JS_ATOM_callee, JS_UNDEFINED, + JS_DefineProperty(ctx, val, JS_ATOM_callee, JS_NULL, ctx->throw_type_error, ctx->throw_type_error, JS_PROP_HAS_GET | JS_PROP_HAS_SET); return val; @@ -14003,7 +13978,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj) uint32_t tag, tab_atom_count; tag = JS_VALUE_GET_TAG(obj); - if (tag != JS_TAG_OBJECT && tag != JS_TAG_NULL && tag != JS_TAG_UNDEFINED) { + if (tag != JS_TAG_OBJECT && tag != JS_TAG_NULL) { obj = JS_ToObjectFree(ctx, obj); } @@ -14027,7 +14002,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj) p1 = JS_VALUE_GET_OBJ(enum_obj); p1->u.for_in_iterator = it; - if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED) + if (tag == JS_TAG_NULL) return enum_obj; p = JS_VALUE_GET_OBJ(obj); @@ -14150,7 +14125,7 @@ static __exception int js_for_in_next(JSContext *ctx, JSValue *sp) for(;;) { if (it->idx >= it->atom_count) { - if (JS_IsNull(it->obj) || JS_IsUndefined(it->obj)) + if (JS_IsNull(it->obj) || JS_IsNull(it->obj)) goto done; /* not an object */ /* no more property in the current object: look in the prototype */ if (!it->in_prototype_chain) { @@ -14218,7 +14193,7 @@ static __exception int js_for_in_next(JSContext *ctx, JSValue *sp) return 0; done: /* return the end */ - sp[0] = JS_UNDEFINED; + sp[0] = JS_NULL; sp[1] = JS_TRUE; return 0; } @@ -14273,7 +14248,7 @@ static JSValue JS_IteratorNext2(JSContext *ctx, JSValueConst enum_obj, /* in case the function expects one argument */ if (argc == 0) { - args[0] = JS_UNDEFINED; + args[0] = JS_NULL; argv = args; } func = p->u.cfunc.c_function; @@ -14296,7 +14271,7 @@ static JSValue JS_IteratorNext2(JSContext *ctx, JSValueConst enum_obj, return JS_EXCEPTION; } -/* Note: always return JS_UNDEFINED when *pdone = TRUE. */ +/* Note: always return JS_NULL when *pdone = TRUE. */ static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj, JSValueConst method, int argc, JSValueConst *argv, BOOL *pdone) @@ -14313,13 +14288,13 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj, } else if (done != 2) { JS_FreeValue(ctx, obj); *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } else { done_val = JS_GetProperty(ctx, obj, JS_ATOM_done); if (JS_IsException(done_val)) goto fail; *pdone = JS_ToBoolFree(ctx, done_val); - value = JS_UNDEFINED; + value = JS_NULL; if (!*pdone) { value = JS_GetProperty(ctx, obj, JS_ATOM_value); } @@ -14344,7 +14319,7 @@ static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj, ctx->rt->current_exception = JS_UNINITIALIZED; res = -1; } else { - ex_obj = JS_UNDEFINED; + ex_obj = JS_NULL; res = 0; } method = JS_GetProperty(ctx, enum_obj, JS_ATOM_return); @@ -14352,7 +14327,7 @@ static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj, res = -1; goto done; } - if (JS_IsUndefined(method) || JS_IsNull(method)) { + if (JS_IsNull(method) || JS_IsNull(method)) { goto done; } ret = JS_CallFree(ctx, method, enum_obj, 0, NULL); @@ -14395,23 +14370,23 @@ static __exception int js_for_of_start(JSContext *ctx, JSValue *sp) undefined. */ static __exception int js_for_of_next(JSContext *ctx, JSValue *sp, int offset) { - JSValue value = JS_UNDEFINED; + JSValue value = JS_NULL; int done = 1; - if (likely(!JS_IsUndefined(sp[offset]))) { + if (likely(!JS_IsNull(sp[offset]))) { value = JS_IteratorNext(ctx, sp[offset], sp[offset + 1], 0, NULL, &done); if (JS_IsException(value)) done = -1; if (done) { - /* value is JS_UNDEFINED or JS_EXCEPTION */ + /* value is JS_NULL or JS_EXCEPTION */ /* replace the iteration object with undefined */ JS_FreeValue(ctx, sp[offset]); - sp[offset] = JS_UNDEFINED; + sp[offset] = JS_NULL; if (done < 0) { return -1; } else { JS_FreeValue(ctx, value); - value = JS_UNDEFINED; + value = JS_NULL; } } } @@ -14578,7 +14553,7 @@ static __exception int js_append_enumerate(JSContext *ctx, JSValue *sp) if (JS_IsException(value)) goto exception; if (done) { - /* value is JS_UNDEFINED */ + /* value is JS_NULL */ break; } if (JS_DefinePropertyValueUint32(ctx, sp[-3], pos++, value, JS_PROP_C_W_E) < 0) @@ -14818,8 +14793,8 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, JSVarRef **cur_var_refs, JSStackFrame *sf, BOOL is_computed_name) { - JSValue bfunc, parent_class, proto = JS_UNDEFINED; - JSValue ctor = JS_UNDEFINED, parent_proto = JS_UNDEFINED; + JSValue bfunc, parent_class, proto = JS_NULL; + JSValue ctor = JS_NULL, parent_proto = JS_NULL; JSFunctionBytecode *b; parent_class = sp[-2]; @@ -14843,7 +14818,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, } } } else { - /* parent_class is JS_UNDEFINED in this case */ + /* parent_class is JS_NULL in this case */ parent_proto = JS_DupValue(ctx, ctx->class_proto[JS_CLASS_OBJECT]); parent_class = JS_DupValue(ctx, ctx->function_proto); } @@ -14857,7 +14832,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, if (JS_IsException(ctor)) goto fail; ctor = js_closure2(ctx, ctor, b, cur_var_refs, sf); - bfunc = JS_UNDEFINED; + bfunc = JS_NULL; if (JS_IsException(ctor)) goto fail; @@ -14902,8 +14877,8 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, JS_FreeValue(ctx, bfunc); JS_FreeValue(ctx, proto); JS_FreeValue(ctx, ctor); - sp[-2] = JS_UNDEFINED; - sp[-1] = JS_UNDEFINED; + sp[-2] = JS_NULL; + sp[-1] = JS_NULL; return -1; } @@ -14979,7 +14954,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, for(i = 0; i < argc; i++) arg_buf[i] = argv[i]; for(i = argc; i < arg_count; i++) - arg_buf[i] = JS_UNDEFINED; + arg_buf[i] = JS_NULL; sf->arg_count = arg_count; } sf->arg_buf = (JSValue*)arg_buf; @@ -15001,7 +14976,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, ret_val = JS_ThrowTypeError(ctx, "must be called with new"); break; } else { - this_obj = JS_UNDEFINED; + this_obj = JS_NULL; } } /* here this_obj is new_target */ @@ -15015,7 +14990,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, if (cproto == JS_CFUNC_constructor_magic) { goto not_a_constructor; } else { - this_obj = JS_UNDEFINED; + this_obj = JS_NULL; } } /* fall thru */ @@ -15215,7 +15190,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, for(i = 0; i < n; i++) arg_buf[i] = JS_DupValue(caller_ctx, argv[i]); for(; i < b->arg_count; i++) - arg_buf[i] = JS_UNDEFINED; + arg_buf[i] = JS_NULL; sf->arg_count = b->arg_count; } var_buf = local_buf + arg_allocated_size; @@ -15223,7 +15198,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sf->arg_buf = arg_buf; for(i = 0; i < b->var_count; i++) - var_buf[i] = JS_UNDEFINED; + var_buf[i] = JS_NULL; stack_buf = var_buf + b->var_count; sp = stack_buf; @@ -15298,9 +15273,6 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, *sp++ = JS_AtomToValue(ctx, get_u32(pc)); pc += 4; BREAK; - CASE(OP_undefined): - *sp++ = JS_UNDEFINED; - BREAK; CASE(OP_null): *sp++ = JS_NULL; BREAK; @@ -15312,7 +15284,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, uint32_t tag = JS_VALUE_GET_TAG(this_obj); if (likely(tag == JS_TAG_OBJECT)) goto normal_this; - if (tag == JS_TAG_NULL || tag == JS_TAG_UNDEFINED) { + if (tag == JS_TAG_NULL) { val = JS_DupValue(ctx, ctx->global_obj); } else { val = JS_ToObject(ctx, this_obj); @@ -15546,8 +15518,8 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, has_call_argc: call_argv = sp - call_argc; sf->cur_pc = pc; - ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED, - JS_UNDEFINED, call_argc, call_argv, 0); + ret_val = JS_CallInternal(ctx, call_argv[-1], JS_NULL, + JS_NULL, call_argc, call_argv, 0); if (unlikely(JS_IsException(ret_val))) goto exception; if (opcode == OP_tail_call) @@ -15583,7 +15555,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, call_argv = sp - call_argc; sf->cur_pc = pc; ret_val = JS_CallInternal(ctx, call_argv[-1], call_argv[-2], - JS_UNDEFINED, call_argc, call_argv, 0); + JS_NULL, call_argc, call_argv, 0); if (unlikely(JS_IsException(ret_val))) goto exception; if (opcode == OP_tail_call_method) @@ -15607,7 +15579,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, for(i = 0; i < call_argc; i++) { ret = JS_DefinePropertyValue(ctx, ret_val, __JS_AtomFromUInt32(i), call_argv[i], JS_PROP_C_W_E | JS_PROP_THROW); - call_argv[i] = JS_UNDEFINED; + call_argv[i] = JS_NULL; if (ret < 0) { JS_FreeValue(ctx, ret_val); goto exception; @@ -15639,7 +15611,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, ret_val = *--sp; goto done; CASE(OP_return_undef): - ret_val = JS_UNDEFINED; + ret_val = JS_NULL; goto done; CASE(OP_throw): @@ -15686,12 +15658,12 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (call_argc >= 1) obj = call_argv[0]; else - obj = JS_UNDEFINED; - ret_val = JS_EvalObject(ctx, JS_UNDEFINED, obj, + obj = JS_NULL; + ret_val = JS_EvalObject(ctx, JS_NULL, obj, JS_EVAL_TYPE_DIRECT, scope_idx); } else { - ret_val = JS_CallInternal(ctx, call_argv[-1], JS_UNDEFINED, - JS_UNDEFINED, call_argc, call_argv, 0); + ret_val = JS_CallInternal(ctx, call_argv[-1], JS_NULL, + JS_NULL, call_argc, call_argv, 0); } if (unlikely(JS_IsException(ret_val))) goto exception; @@ -15719,11 +15691,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (len >= 1) obj = tab[0]; else - obj = JS_UNDEFINED; - ret_val = JS_EvalObject(ctx, JS_UNDEFINED, obj, + obj = JS_NULL; + ret_val = JS_EvalObject(ctx, JS_NULL, obj, JS_EVAL_TYPE_DIRECT, scope_idx); } else { - ret_val = JS_Call(ctx, sp[-2], JS_UNDEFINED, len, + ret_val = JS_Call(ctx, sp[-2], JS_NULL, len, (JSValueConst *)tab); } free_arg_list(ctx, tab, len); @@ -15738,7 +15710,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_regexp): { - sp[-2] = js_regexp_constructor_internal(ctx, JS_UNDEFINED, + sp[-2] = js_regexp_constructor_internal(ctx, JS_NULL, sp[-2], sp[-1]); sp--; } @@ -16153,7 +16125,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-1]; pc += 4; - if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) { + if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_NULL) { res = JS_VALUE_GET_INT(op1); } else { res = JS_ToBoolFree(ctx, op1); @@ -16174,7 +16146,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-1]; pc += 4; /* quick and dirty test for JS_TAG_INT, JS_TAG_BOOL, JS_TAG_NULL and JS_TAG_UNDEFINED */ - if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) { + if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_NULL) { res = JS_VALUE_GET_INT(op1); } else { res = JS_ToBoolFree(ctx, op1); @@ -16195,7 +16167,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-1]; pc += 1; - if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) { + if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_NULL) { res = JS_VALUE_GET_INT(op1); } else { res = JS_ToBoolFree(ctx, op1); @@ -16215,7 +16187,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, op1 = sp[-1]; pc += 1; - if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) { + if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_NULL) { res = JS_VALUE_GET_INT(op1); } else { res = JS_ToBoolFree(ctx, op1); @@ -16312,7 +16284,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp--; /* drop the catch offset to avoid getting caught by exception */ JS_FreeValue(ctx, sp[-1]); /* drop the next method */ sp--; - if (!JS_IsUndefined(sp[-1])) { + if (!JS_IsNull(sp[-1])) { sf->cur_pc = pc; if (JS_IteratorClose(ctx, sp[-1], FALSE)) goto exception; @@ -16364,7 +16336,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_ATOM_throw : JS_ATOM_return); if (JS_IsException(method)) goto exception; - if (JS_IsUndefined(method) || JS_IsNull(method)) { + if (JS_IsNull(method) || JS_IsNull(method)) { ret_flag = TRUE; } else { if (flags & 2) { @@ -16392,7 +16364,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValue op1; op1 = sp[-1]; - if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_UNDEFINED) { + if ((uint32_t)JS_VALUE_GET_TAG(op1) <= JS_TAG_NULL) { res = JS_VALUE_GET_INT(op1) != 0; } else { res = JS_ToBoolFree(ctx, op1); @@ -16565,9 +16537,9 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (op_flags & OP_DEFINE_METHOD_ENUMERABLE) flags |= JS_PROP_ENUMERABLE; op_flags &= 3; - value = JS_UNDEFINED; - getter = JS_UNDEFINED; - setter = JS_UNDEFINED; + value = JS_NULL; + getter = JS_NULL; + setter = JS_NULL; if (op_flags == OP_DEFINE_METHOD_METHOD) { value = sp[-1]; flags |= JS_PROP_HAS_VALUE | JS_PROP_HAS_WRITABLE | JS_PROP_WRITABLE; @@ -16648,7 +16620,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, break; default: /* must be tested nefore JS_ToPropertyKey */ - if (unlikely(JS_IsUndefined(sp[-2]) || JS_IsNull(sp[-2]))) { + if (unlikely(JS_IsNull(sp[-2]) || JS_IsNull(sp[-2]))) { JS_ThrowTypeError(ctx, "value has no property"); goto exception; } @@ -16678,7 +16650,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = JS_ValueToAtom(ctx, sp[-1]); if (atom == JS_ATOM_NULL) goto exception; - if (unlikely(JS_IsUndefined(sp[-2]))) { + if (unlikely(JS_IsNull(sp[-2]))) { JS_ThrowReferenceErrorNotDefined(ctx, atom); JS_FreeAtom(ctx, atom); goto exception; @@ -16694,7 +16666,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_FreeAtom(ctx, atom); goto exception; } - val = JS_UNDEFINED; + val = JS_NULL; } else { val = JS_GetProperty(ctx, sp[-2], atom); } @@ -16727,7 +16699,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = JS_ValueToAtom(ctx, sp[-2]); if (unlikely(atom == JS_ATOM_NULL)) goto exception; - if (unlikely(JS_IsUndefined(sp[-3]))) { + if (unlikely(JS_IsNull(sp[-3]))) { if (is_strict_mode(ctx)) { JS_ThrowReferenceErrorNotDefined(ctx, atom); JS_FreeAtom(ctx, atom); @@ -17369,35 +17341,13 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, #endif CASE(OP_nop): BREAK; - CASE(OP_is_undefined_or_null): - if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_UNDEFINED || - JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_NULL) { - goto set_true; - } else { - goto free_and_set_false; - } -#if SHORT_OPCODES - CASE(OP_is_undefined): - if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_UNDEFINED) { - goto set_true; - } else { - goto free_and_set_false; - } CASE(OP_is_null): if (JS_VALUE_GET_TAG(sp[-1]) == JS_TAG_NULL) { goto set_true; } else { goto free_and_set_false; } - /* XXX: could merge to a single opcode */ - CASE(OP_typeof_is_undefined): - /* different from OP_is_undefined because of isHTMLDDA */ - /* HTMLDDA removed, so can merge */ - if (js_operator_typeof(ctx, sp[-1]) == JS_ATOM_undefined) { - goto free_and_set_true; - } else { - goto free_and_set_false; - } +#if SHORT_OPCODES CASE(OP_typeof_is_function): if (js_operator_typeof(ctx, sp[-1]) == JS_ATOM_function) { goto free_and_set_true; @@ -17473,14 +17423,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj, int argc, JSValueConst *argv) { - return JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED, + return JS_CallInternal(ctx, func_obj, this_obj, JS_NULL, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); } static JSValue JS_CallFree(JSContext *ctx, JSValue func_obj, JSValueConst this_obj, int argc, JSValueConst *argv) { - JSValue res = JS_CallInternal(ctx, func_obj, this_obj, JS_UNDEFINED, + JSValue res = JS_CallInternal(ctx, func_obj, this_obj, JS_NULL, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); JS_FreeValue(ctx, func_obj); return res; @@ -17539,7 +17489,7 @@ static JSValue js_create_from_ctor(JSContext *ctx, JSValueConst ctor, JSValue proto, obj; JSContext *realm; - if (JS_IsUndefined(ctor)) { + if (JS_IsNull(ctor)) { proto = JS_DupValue(ctx, ctx->class_proto[class_id]); } else { proto = JS_GetProperty(ctx, ctor, JS_ATOM_prototype); @@ -17588,7 +17538,7 @@ static JSValue JS_CallConstructorInternal(JSContext *ctx, b = p->u.func.function_bytecode; if (b->is_derived_class_constructor) { - return JS_CallInternal(ctx, func_obj, JS_UNDEFINED, new_target, argc, argv, flags); + return JS_CallInternal(ctx, func_obj, JS_NULL, new_target, argc, argv, flags); } else { JSValue obj, ret; /* legacy constructor behavior */ @@ -20192,8 +20142,8 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc) JSToken cooked; int depth, ret; - raw_array = JS_UNDEFINED; /* avoid warning */ - template_object = JS_UNDEFINED; /* avoid warning */ + raw_array = JS_NULL; /* avoid warning */ + template_object = JS_NULL; /* avoid warning */ if (call) { /* Create a template object: an array of cooked strings */ /* Create an array of raw strings and store it to the raw property */ @@ -20228,7 +20178,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc) syntax error if it contains invalid sequences */ if (js_parse_string(s, '`', FALSE, p, &cooked, &p)) { - cooked.u.str.str = JS_UNDEFINED; + cooked.u.str.str = JS_NULL; } if (JS_DefinePropertyValueUint32(ctx, template_object, depth, cooked.u.str.str, @@ -20241,7 +20191,7 @@ static __exception int js_parse_template(JSParseState *s, int call, int *argc) syntax error if it contains invalid sequences */ JS_FreeValue(ctx, s->token.u.str.str); - s->token.u.str.str = JS_UNDEFINED; + s->token.u.str.str = JS_NULL; if (js_parse_string(s, '`', TRUE, p, &cooked, &p)) return -1; str = JS_VALUE_GET_STRING(cooked.u.str.str); @@ -21264,7 +21214,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, if (hasval) { /* consume value from the stack */ emit_op(s, OP_dup); - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_strict_eq); emit_goto(s, OP_if_true, label_parse); emit_label(s, label_assign); @@ -21514,7 +21464,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, if (s->token.val == '=') { /* handle optional default value */ int label_hasval; emit_op(s, OP_dup); - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_strict_eq); label_hasval = emit_goto(s, OP_if_false, -1); if (next_token(s)) @@ -21628,7 +21578,7 @@ static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg, /* handle optional default value */ int label_hasval; emit_op(s, OP_dup); - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_strict_eq); label_hasval = emit_goto(s, OP_if_false, -1); if (next_token(s)) @@ -21711,11 +21661,11 @@ static void optional_chain_test(JSParseState *s, int *poptional_chaining_label, *poptional_chaining_label = new_label(s); /* XXX: could be more efficient with a specific opcode */ emit_op(s, OP_dup); - emit_op(s, OP_is_undefined_or_null); + emit_op(s, OP_is_null); label_next = emit_goto(s, OP_if_false, -1); for(i = 0; i < drop_count; i++) emit_op(s, OP_drop); - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_goto(s, OP_goto, *poptional_chaining_label); emit_label(s, label_next); } @@ -21963,7 +21913,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) /* need an additional undefined value for the case where the optional field does not exists */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_label(s, next_label); drop_count = 2; opcode = OP_get_field; @@ -21987,7 +21937,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) /* need an additional undefined value for the case where the optional field does not exists */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_label(s, next_label); drop_count = 2; opcode = OP_get_array_el; @@ -22140,7 +22090,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) emit_u16(s, 1); } else { /* func array -> func undef array */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_swap); emit_op(s, OP_apply); emit_u16(s, 0); @@ -22350,7 +22300,7 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) break; case TOK_VOID: emit_op(s, OP_drop); - emit_op(s, OP_undefined); + emit_op(s, OP_null); break; default: abort(); @@ -22636,7 +22586,7 @@ static __exception int js_parse_coalesce_expr(JSParseState *s, int parse_flags) return -1; emit_op(s, OP_dup); - emit_op(s, OP_is_undefined_or_null); + emit_op(s, OP_is_null); emit_goto(s, OP_if_false, label1); emit_op(s, OP_drop); @@ -22751,7 +22701,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) emit_op(s, OP_dup); if (op == TOK_DOUBLE_QUESTION_MARK_ASSIGN) - emit_op(s, OP_is_undefined_or_null); + emit_op(s, OP_is_null); label1 = emit_goto(s, op == TOK_LOR_ASSIGN ? OP_if_true : OP_if_false, -1); emit_op(s, OP_drop); @@ -22890,7 +22840,7 @@ static __exception int emit_break(JSParseState *s, JSAtom name, int is_cont) emit_op(s, OP_drop); if (top->label_finally != -1) { /* must push dummy value to keep same stack depth */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_goto(s, OP_gosub, top->label_finally); emit_op(s, OP_drop); } @@ -22915,7 +22865,7 @@ static void emit_return(JSParseState *s, BOOL hasval) while (top != NULL) { if (top->has_iterator || top->label_finally != -1) { if (!hasval) { - emit_op(s, OP_undefined); + emit_op(s, OP_null); hasval = TRUE; } /* Remove the stack elements up to and including the catch @@ -22926,7 +22876,7 @@ static void emit_return(JSParseState *s, BOOL hasval) /* stack: iter_obj next ret_val */ if (top->has_iterator) { emit_op(s, OP_rot3r); - emit_op(s, OP_undefined); /* dummy catch offset */ + emit_op(s, OP_null); /* dummy catch offset */ emit_op(s, OP_iterator_close); } else { /* execute the "finally" block */ @@ -23032,7 +22982,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok, } if (tok == TOK_LET) { /* initialize lexical variable upon entering its scope */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_scope_put_var_init); emit_atom(s, name); emit_u16(s, fd->scope_level); @@ -23043,7 +22993,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok, int skip_bits; if ((s->token.val == '[' || s->token.val == '{') && js_parse_skip_parens_token(s, &skip_bits, FALSE) == '=') { - emit_op(s, OP_undefined); + emit_op(s, OP_null); if (js_parse_destructuring_element(s, tok, 0, TRUE, skip_bits & SKIP_HAS_ELLIPSIS, TRUE, export_flag) < 0) return -1; } else { @@ -23322,7 +23272,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name) static void set_eval_ret_undefined(JSParseState *s) { if (s->cur_func->eval_ret_idx >= 0) { - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_put_loc); emit_u16(s, s->cur_func->eval_ret_idx); } @@ -23827,7 +23777,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, /* drop the catch offset */ emit_op(s, OP_drop); /* must push dummy value to keep same stack size */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_goto(s, OP_gosub, label_finally); emit_op(s, OP_drop); @@ -23891,7 +23841,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, emit_op(s, OP_drop); /* XXX: should keep the address to nop it out if there is no finally block */ /* must push dummy value to keep same stack size */ - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_goto(s, OP_gosub, label_finally); emit_op(s, OP_drop); emit_goto(s, OP_goto, label_end); @@ -25025,7 +24975,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s, } break; case OP_scope_get_ref: - dbuf_putc(bc, OP_undefined); + dbuf_putc(bc, OP_null); /* fall thru */ case OP_scope_get_var_checkthis: case OP_scope_get_var_undef: @@ -25252,7 +25202,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s, case OP_scope_get_ref: /* XXX: should create a dummy object with a named slot that is a reference to the closure variable */ - dbuf_putc(bc, OP_undefined); + dbuf_putc(bc, OP_null); /* fall thru */ case OP_scope_get_var_undef: case OP_scope_get_var: @@ -25306,7 +25256,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s, case OP_scope_get_ref: /* XXX: should create a dummy object with a named slot that is a reference to the global variable */ - dbuf_putc(bc, OP_undefined); + dbuf_putc(bc, OP_null); dbuf_putc(bc, OP_get_var); dbuf_put_u32(bc, JS_DupAtom(ctx, var_name)); break; @@ -25800,7 +25750,7 @@ static void instantiate_hoisted_definitions(JSContext *ctx, JSFunctionDef *s, Dy dbuf_put_u32(bc, JS_DupAtom(ctx, JS_ATOM_default)); } } else { - dbuf_putc(bc, OP_undefined); + dbuf_putc(bc, OP_null); } if (has_closure == 2) { dbuf_putc(bc, OP_put_var_ref); @@ -26799,56 +26749,75 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) } goto no_change; - case OP_null: -#if SHORT_OPCODES - if (OPTIMIZE) { - /* transform null strict_eq into is_null */ - if (code_match(&cc, pos_next, OP_strict_eq, -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - add_pc2line_info(s, bc_out.size, line_num); - dbuf_putc(&bc_out, OP_is_null); - pos_next = cc.pos; - break; - } - /* transform null strict_neq if_false/if_true -> is_null if_true/if_false */ - if (code_match(&cc, pos_next, OP_strict_neq, M2(OP_if_false, OP_if_true), -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - add_pc2line_info(s, bc_out.size, line_num); - dbuf_putc(&bc_out, OP_is_null); - pos_next = cc.pos; - label = cc.label; - op = cc.op ^ OP_if_false ^ OP_if_true; - goto has_label; - } - } -#endif - /* fall thru */ - case OP_push_false: - case OP_push_true: - if (OPTIMIZE) { - val = (op == OP_push_true); - if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) { - has_constant_test: - if (cc.line_num >= 0) line_num = cc.line_num; - if (val == cc.op - OP_if_false) { - /* transform null if_false(l1) -> goto l1 */ - /* transform false if_false(l1) -> goto l1 */ - /* transform true if_true(l1) -> goto l1 */ + case OP_null: + if (OPTIMIZE) { + /* 1) remove null; drop → (nothing) */ + if (code_match(&cc, pos_next, OP_drop, -1)) { + if (cc.line_num >= 0) line_num = cc.line_num; pos_next = cc.pos; - op = OP_goto; - label = cc.label; - goto has_goto; - } else { - /* transform null if_true(l1) -> nop */ - /* transform false if_true(l1) -> nop */ - /* transform true if_false(l1) -> nop */ - pos_next = cc.pos; - update_label(s, cc.label, -1); break; } + /* 2) null; return → return_undef */ + if (code_match(&cc, pos_next, OP_return, -1)) { + if (cc.line_num >= 0) line_num = cc.line_num; + add_pc2line_info(s, bc_out.size, line_num); + dbuf_putc(&bc_out, OP_return_undef); + pos_next = cc.pos; + break; + } + /* 3) null; if_false/if_true → goto or nop */ + if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) { + val = 0; + goto has_constant_test; + } + #if SHORT_OPCODES + /* 4a) null strict_eq → is_null */ + if (code_match(&cc, pos_next, OP_strict_eq, -1)) { + if (cc.line_num >= 0) line_num = cc.line_num; + add_pc2line_info(s, bc_out.size, line_num); + dbuf_putc(&bc_out, OP_is_null); + pos_next = cc.pos; + break; + } + /* 4b) null strict_neq; if_false/if_true → is_null + flipped branch */ + if (code_match(&cc, pos_next, + OP_strict_neq, M2(OP_if_false, OP_if_true), + -1)) { + if (cc.line_num >= 0) line_num = cc.line_num; + add_pc2line_info(s, bc_out.size, line_num); + dbuf_putc(&bc_out, OP_is_null); + pos_next = cc.pos; + label = cc.label; + op = cc.op ^ OP_if_false ^ OP_if_true; + goto has_label; + } + #endif } - } - goto no_change; + /* didn’t match any of the above? fall straight into the + OP_push_false / OP_push_true constant‐test code: */ + case OP_push_false: + case OP_push_true: + if (OPTIMIZE) { + val = (op == OP_push_true); + if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) { + has_constant_test: + if (cc.line_num >= 0) line_num = cc.line_num; + if (val == (cc.op - OP_if_false)) { + /* e.g. null if_false(L) → goto L */ + pos_next = cc.pos; + op = OP_goto; + label = cc.label; + goto has_goto; + } else { + /* e.g. null if_true(L) → nop */ + pos_next = cc.pos; + update_label(s, cc.label, -1); + break; + } + } + } + goto no_change; + case OP_push_i32: if (OPTIMIZE) { @@ -26955,56 +26924,11 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) /* remove redundant to_propkey opcodes when storing simple data */ if (code_match(&cc, pos_next, M3(OP_get_loc, OP_get_arg, OP_get_var_ref), -1, OP_put_array_el, -1) || code_match(&cc, pos_next, M3(OP_push_i32, OP_push_const, OP_push_atom_value), OP_put_array_el, -1) - || code_match(&cc, pos_next, M4(OP_undefined, OP_null, OP_push_true, OP_push_false), OP_put_array_el, -1)) { + || code_match(&cc, pos_next, M4(OP_null, OP_null, OP_push_true, OP_push_false), OP_put_array_el, -1)) { break; } } goto no_change; - - case OP_undefined: - if (OPTIMIZE) { - /* remove push/drop pairs generated by the parser */ - if (code_match(&cc, pos_next, OP_drop, -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - pos_next = cc.pos; - break; - } - /* transform undefined return -> return_undefined */ - if (code_match(&cc, pos_next, OP_return, -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - add_pc2line_info(s, bc_out.size, line_num); - dbuf_putc(&bc_out, OP_return_undef); - pos_next = cc.pos; - break; - } - /* transform undefined if_true(l1)/if_false(l1) -> nop/goto(l1) */ - if (code_match(&cc, pos_next, M2(OP_if_false, OP_if_true), -1)) { - val = 0; - goto has_constant_test; - } -#if SHORT_OPCODES - /* transform undefined strict_eq -> is_undefined */ - if (code_match(&cc, pos_next, OP_strict_eq, -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - add_pc2line_info(s, bc_out.size, line_num); - dbuf_putc(&bc_out, OP_is_undefined); - pos_next = cc.pos; - break; - } - /* transform undefined strict_neq if_false/if_true -> is_undefined if_true/if_false */ - if (code_match(&cc, pos_next, OP_strict_neq, M2(OP_if_false, OP_if_true), -1)) { - if (cc.line_num >= 0) line_num = cc.line_num; - add_pc2line_info(s, bc_out.size, line_num); - dbuf_putc(&bc_out, OP_is_undefined); - pos_next = cc.pos; - label = cc.label; - op = cc.op ^ OP_if_false ^ OP_if_true; - goto has_label; - } -#endif - } - goto no_change; - case OP_insert2: if (OPTIMIZE) { /* Transformation: @@ -27208,8 +27132,8 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) int op1 = (cc.op == OP_strict_eq || cc.op == OP_eq) ? OP_strict_eq : OP_strict_neq; int op2 = -1; switch (cc.atom) { - case JS_ATOM_undefined: - op2 = OP_typeof_is_undefined; + case JS_ATOM_null: + op2 = OP_is_null; break; case JS_ATOM_function: op2 = OP_typeof_is_function; @@ -28223,7 +28147,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, emit_op(s, OP_get_arg); emit_u16(s, idx); emit_op(s, OP_dup); - emit_op(s, OP_undefined); + emit_op(s, OP_null); emit_op(s, OP_strict_eq); emit_goto(s, OP_if_false, label); emit_op(s, OP_drop); @@ -28824,7 +28748,6 @@ static void js_object_list_end(JSContext *ctx, JSObjectList *s) typedef enum BCTagEnum { BC_TAG_NULL = 1, - BC_TAG_UNDEFINED, BC_TAG_BOOL_FALSE, BC_TAG_BOOL_TRUE, BC_TAG_INT32, @@ -28865,7 +28788,6 @@ typedef struct BCWriterState { static const char * const bc_tag_str[] = { "invalid", "null", - "undefined", "false", "true", "int32", @@ -29339,9 +29261,6 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValueConst obj) case JS_TAG_NULL: bc_put_u8(s, BC_TAG_NULL); break; - case JS_TAG_UNDEFINED: - bc_put_u8(s, BC_TAG_UNDEFINED); - break; case JS_TAG_BOOL: bc_put_u8(s, BC_TAG_BOOL_FALSE + JS_VALUE_GET_INT(obj)); break; @@ -29842,7 +29761,7 @@ static int JS_ReadFunctionBytecode(BCReaderState *s, JSFunctionBytecode *b, static JSValue JS_ReadBigInt(BCReaderState *s) { - JSValue obj = JS_UNDEFINED; + JSValue obj = JS_NULL; uint32_t len, i, n; JSBigInt *p; js_limb_t v; @@ -29915,7 +29834,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) { JSContext *ctx = s->ctx; JSFunctionBytecode bc, *b; - JSValue obj = JS_UNDEFINED; + JSValue obj = JS_NULL; uint16_t v16; uint8_t v8; int idx, i, local_count; @@ -30174,7 +30093,7 @@ static JSValue JS_ReadArray(BCReaderState *s, int tag) val = JS_ReadObjectRec(s); if (JS_IsException(val)) goto fail; - if (!JS_IsUndefined(val)) { + if (!JS_IsNull(val)) { ret = JS_DefinePropertyValue(ctx, obj, JS_ATOM_raw, val, 0); if (ret < 0) goto fail; @@ -30190,7 +30109,7 @@ static JSValue JS_ReadArray(BCReaderState *s, int tag) static JSValue JS_ReadObjectValue(BCReaderState *s) { JSContext *ctx = s->ctx; - JSValue val, obj = JS_UNDEFINED; + JSValue val, obj = JS_NULL; val = JS_ReadObjectRec(s); if (JS_IsException(val)) @@ -30212,7 +30131,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) { JSContext *ctx = s->ctx; uint8_t tag; - JSValue obj = JS_UNDEFINED; + JSValue obj = JS_NULL; if (js_check_stack_overflow(ctx->rt, 0)) return JS_ThrowStackOverflow(ctx); @@ -30226,9 +30145,6 @@ static JSValue JS_ReadObjectRec(BCReaderState *s) case BC_TAG_NULL: obj = JS_NULL; break; - case BC_TAG_UNDEFINED: - obj = JS_UNDEFINED; - break; case BC_TAG_BOOL_FALSE: case BC_TAG_BOOL_TRUE: obj = JS_NewBool(ctx, tag - BC_TAG_BOOL_FALSE); @@ -30507,14 +30423,14 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj, JSValue getter, setter; char buf[64]; - getter = JS_UNDEFINED; + getter = JS_NULL; if (e->u.getset.get.generic) { snprintf(buf, sizeof(buf), "get %s", e->name); getter = JS_NewCFunction2(ctx, e->u.getset.get.generic, buf, 0, e->def_type == JS_DEF_CGETSET_MAGIC ? JS_CFUNC_getter_magic : JS_CFUNC_getter, e->magic); } - setter = JS_UNDEFINED; + setter = JS_NULL; if (e->u.getset.set.generic) { snprintf(buf, sizeof(buf), "set %s", e->name); setter = JS_NewCFunction2(ctx, e->u.getset.set.generic, @@ -30535,7 +30451,7 @@ static int JS_InstantiateFunctionListItem(JSContext *ctx, JSValueConst obj, val = __JS_NewFloat64(ctx, e->u.f64); break; case JS_DEF_PROP_UNDEFINED: - val = JS_UNDEFINED; + val = JS_NULL; break; case JS_DEF_PROP_STRING: case JS_DEF_OBJECT: @@ -30646,7 +30562,6 @@ static JSValue JS_ToObject(JSContext *ctx, JSValueConst val) switch(tag) { default: case JS_TAG_NULL: - case JS_TAG_UNDEFINED: return JS_ThrowTypeError(ctx, "cannot convert to object"); case JS_TAG_OBJECT: case JS_TAG_EXCEPTION: @@ -30706,9 +30621,9 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d, return -1; } flags = 0; - val = JS_UNDEFINED; - getter = JS_UNDEFINED; - setter = JS_UNDEFINED; + val = JS_NULL; + getter = JS_NULL; + setter = JS_NULL; if (JS_HasProperty(ctx, desc, JS_ATOM_enumerable)) { JSValue prop = JS_GetProperty(ctx, desc, JS_ATOM_enumerable); if (JS_IsException(prop)) @@ -30743,7 +30658,7 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d, flags |= JS_PROP_HAS_GET; getter = JS_GetProperty(ctx, desc, JS_ATOM_get); if (JS_IsException(getter) || - !(JS_IsUndefined(getter) || JS_IsFunction(ctx, getter))) { + !(JS_IsNull(getter) || JS_IsFunction(ctx, getter))) { JS_ThrowTypeError(ctx, "invalid getter"); goto fail; } @@ -30752,7 +30667,7 @@ static int js_obj_to_desc(JSContext *ctx, JSPropertyDescriptor *d, flags |= JS_PROP_HAS_SET; setter = JS_GetProperty(ctx, desc, JS_ATOM_set); if (JS_IsException(setter) || - !(JS_IsUndefined(setter) || JS_IsFunction(ctx, setter))) { + !(JS_IsNull(setter) || JS_IsFunction(ctx, setter))) { JS_ThrowTypeError(ctx, "invalid setter"); goto fail; } @@ -30804,7 +30719,7 @@ static __exception int JS_ObjectDefineProperties(JSContext *ctx, JS_ThrowTypeErrorNotAnObject(ctx); return -1; } - desc = JS_UNDEFINED; + desc = JS_NULL; props = JS_ToObject(ctx, properties); if (JS_IsException(props)) return -1; @@ -30833,7 +30748,7 @@ static JSValue js_object_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv) { JSValue ret; - if (!JS_IsUndefined(new_target) && + if (!JS_IsNull(new_target) && JS_VALUE_GET_OBJ(new_target) != JS_VALUE_GET_OBJ(JS_GetActiveFunction(ctx))) { ret = js_create_from_ctor(ctx, new_target, JS_CLASS_OBJECT); @@ -30841,7 +30756,6 @@ static JSValue js_object_constructor(JSContext *ctx, JSValueConst new_target, int tag = JS_VALUE_GET_NORM_TAG(argv[0]); switch(tag) { case JS_TAG_NULL: - case JS_TAG_UNDEFINED: ret = JS_NewObject(ctx); break; default: @@ -30865,7 +30779,7 @@ static JSValue js_object_create(JSContext *ctx, JSValueConst this_val, if (JS_IsException(obj)) return JS_EXCEPTION; props = argv[1]; - if (!JS_IsUndefined(props)) { + if (!JS_IsNull(props)) { if (JS_ObjectDefineProperties(ctx, obj, props)) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -30883,8 +30797,7 @@ static JSValue js_object_getPrototypeOf(JSContext *ctx, JSValueConst this_val, if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT) { /* ES6 feature non compatible with ES5.1: primitive types are accepted */ - if (magic || JS_VALUE_GET_TAG(val) == JS_TAG_NULL || - JS_VALUE_GET_TAG(val) == JS_TAG_UNDEFINED) + if (magic || JS_VALUE_GET_TAG(val) == JS_TAG_NULL) return JS_ThrowTypeErrorNotAnObject(ctx); } return JS_GetPrototype(ctx, val); @@ -30972,21 +30885,21 @@ static JSValue js_object___defineGetter__(JSContext *ctx, JSValueConst this_val, JS_PROP_HAS_ENUMERABLE | JS_PROP_ENUMERABLE | JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE; if (magic) { - get = JS_UNDEFINED; + get = JS_NULL; set = value; flags |= JS_PROP_HAS_SET; } else { get = value; - set = JS_UNDEFINED; + set = JS_NULL; flags |= JS_PROP_HAS_GET; } - ret = JS_DefineProperty(ctx, obj, atom, JS_UNDEFINED, get, set, flags); + ret = JS_DefineProperty(ctx, obj, atom, JS_NULL, get, set, flags); JS_FreeValue(ctx, obj); JS_FreeAtom(ctx, atom); if (ret < 0) { return JS_EXCEPTION; } else { - return JS_UNDEFINED; + return JS_NULL; } } @@ -31013,7 +30926,7 @@ static JSValue js_object_getOwnPropertyDescriptor(JSContext *ctx, JSValueConst t atom = JS_ValueToAtom(ctx, prop); if (unlikely(atom == JS_ATOM_NULL)) goto exception; - ret = JS_UNDEFINED; + ret = JS_NULL; if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) { res = JS_GetOwnPropertyInternal(ctx, &desc, JS_VALUE_GET_OBJ(obj), atom); if (res < 0) @@ -31063,7 +30976,7 @@ static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValueConst JSPropertyEnum *props; uint32_t len, i; - r = JS_UNDEFINED; + r = JS_NULL; obj = JS_ToObject(ctx, argv[0]); if (JS_IsException(obj)) return JS_EXCEPTION; @@ -31084,11 +30997,11 @@ static JSValue js_object_getOwnPropertyDescriptors(JSContext *ctx, JSValueConst goto exception; args[0] = obj; args[1] = atomValue; - desc = js_object_getOwnPropertyDescriptor(ctx, JS_UNDEFINED, 2, args, 0); + desc = js_object_getOwnPropertyDescriptor(ctx, JS_NULL, 2, args, 0); JS_FreeValue(ctx, atomValue); if (JS_IsException(desc)) goto exception; - if (!JS_IsUndefined(desc)) { + if (!JS_IsNull(desc)) { if (JS_DefinePropertyValue(ctx, r, props[i].atom, desc, JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; @@ -31113,8 +31026,8 @@ static JSValue JS_GetOwnPropertyNames2(JSContext *ctx, JSValueConst obj1, JSPropertyEnum *atoms; uint32_t len, i, j; - r = JS_UNDEFINED; - val = JS_UNDEFINED; + r = JS_NULL; + val = JS_NULL; obj = JS_ToObject(ctx, obj1); if (JS_IsException(obj)) return JS_EXCEPTION; @@ -31318,8 +31231,6 @@ static JSValue js_object_toString(JSContext *ctx, JSValueConst this_val, if (JS_IsNull(this_val)) { tag = js_new_string8(ctx, "Null"); - } else if (JS_IsUndefined(this_val)) { - tag = js_new_string8(ctx, "Undefined"); } else { obj = JS_ToObject(ctx, this_val); if (JS_IsException(obj)) @@ -31375,16 +31286,16 @@ static JSValue js_object_assign(JSContext *ctx, JSValueConst this_val, JSValue obj, s; int i; - s = JS_UNDEFINED; + s = JS_NULL; obj = JS_ToObject(ctx, argv[0]); if (JS_IsException(obj)) goto exception; for (i = 1; i < argc; i++) { - if (!JS_IsNull(argv[i]) && !JS_IsUndefined(argv[i])) { + if (!JS_IsNull(argv[i]) && !JS_IsNull(argv[i])) { s = JS_ToObject(ctx, argv[i]); if (JS_IsException(s)) goto exception; - if (JS_CopyDataProperties(ctx, obj, s, JS_UNDEFINED, TRUE)) + if (JS_CopyDataProperties(ctx, obj, s, JS_NULL, TRUE)) goto exception; JS_FreeValue(ctx, s); } @@ -31435,8 +31346,8 @@ static JSValue js_object_seal(JSContext *ctx, JSValueConst this_val, js_free_desc(ctx, &desc); } } - if (JS_DefineProperty(ctx, obj, prop, JS_UNDEFINED, - JS_UNDEFINED, JS_UNDEFINED, desc_flags) < 0) + if (JS_DefineProperty(ctx, obj, prop, JS_NULL, + JS_NULL, JS_NULL, desc_flags) < 0) goto exception; } JS_FreePropertyEnum(ctx, props, len); @@ -31496,7 +31407,7 @@ exception: static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - JSValue obj, iter, next_method = JS_UNDEFINED; + JSValue obj, iter, next_method = JS_NULL; JSValueConst iterable; BOOL done; @@ -31523,8 +31434,8 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val, if (done) break; - key = JS_UNDEFINED; - value = JS_UNDEFINED; + key = JS_NULL; + value = JS_NULL; if (!JS_IsObject(item)) { JS_ThrowTypeErrorNotAnObject(ctx); goto fail1; @@ -31670,7 +31581,7 @@ static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj, ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor); if (JS_IsException(ctor)) return ctor; - if (JS_IsUndefined(ctor)) + if (JS_IsNull(ctor)) return JS_DupValue(ctx, defaultConstructor); if (!JS_IsObject(ctor)) { JS_FreeValue(ctx, ctor); @@ -31680,7 +31591,7 @@ static JSValue JS_SpeciesConstructor(JSContext *ctx, JSValueConst obj, JS_FreeValue(ctx, ctor); if (JS_IsException(species)) return species; - if (JS_IsUndefined(species) || JS_IsNull(species)) + if (JS_IsNull(species) || JS_IsNull(species)) return JS_DupValue(ctx, defaultConstructor); if (!JS_IsConstructor(ctx, species)) { JS_FreeValue(ctx, species); @@ -31712,14 +31623,14 @@ static JSValue js_object_get___proto__(JSContext *ctx, JSValueConst this_val) static JSValue js_object_set___proto__(JSContext *ctx, JSValueConst this_val, JSValueConst proto) { - if (JS_IsUndefined(this_val) || JS_IsNull(this_val)) + if (JS_IsNull(this_val) || JS_IsNull(this_val)) return JS_ThrowTypeErrorNotAnObject(ctx); if (!JS_IsObject(proto) && !JS_IsNull(proto)) - return JS_UNDEFINED; + return JS_NULL; if (JS_SetPrototypeInternal(ctx, this_val, proto, TRUE) < 0) return JS_EXCEPTION; else - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_object_isPrototypeOf(JSContext *ctx, JSValueConst this_val, @@ -31765,7 +31676,7 @@ exception: static JSValue js_object_propertyIsEnumerable(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - JSValue obj = JS_UNDEFINED, res = JS_EXCEPTION; + JSValue obj = JS_NULL, res = JS_EXCEPTION; JSAtom prop; JSPropertyDescriptor desc; int has_prop; @@ -31816,7 +31727,7 @@ static JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst this_val, if (desc.flags & JS_PROP_GETSET) res = JS_DupValue(ctx, setter ? desc.setter : desc.getter); else - res = JS_UNDEFINED; + res = JS_NULL; js_free_desc(ctx, &desc); break; } @@ -31824,7 +31735,7 @@ static JSValue js_object___lookupGetter__(JSContext *ctx, JSValueConst this_val, if (JS_IsException(obj)) goto exception; if (JS_IsNull(obj)) { - res = JS_UNDEFINED; + res = JS_NULL; break; } /* avoid infinite loop (possible with proxies) */ @@ -31894,7 +31805,7 @@ static const JSCFunctionListEntry js_object_proto_funcs[] = { static JSValue js_function_proto(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - return JS_UNDEFINED; + return JS_NULL; } /* XXX: add a specific eval mode so that Function("}), ({") is rejected */ @@ -31902,7 +31813,7 @@ static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic) { int i, n, ret; - JSValue s, proto, obj = JS_UNDEFINED; + JSValue s, proto, obj = JS_NULL; StringBuffer b_s, *b = &b_s; string_buffer_init(ctx, b, 0); @@ -31932,7 +31843,7 @@ static JSValue js_function_constructor(JSContext *ctx, JSValueConst new_target, JS_FreeValue(ctx, s); if (JS_IsException(obj)) goto fail1; - if (!JS_IsUndefined(new_target)) { + if (!JS_IsNull(new_target)) { /* set the prototype */ proto = JS_GetProperty(ctx, new_target, JS_ATOM_prototype); if (JS_IsException(proto)) @@ -32066,8 +31977,7 @@ static JSValue js_function_apply(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; this_arg = argv[0]; array_arg = argv[1]; - if ((JS_VALUE_GET_TAG(array_arg) == JS_TAG_UNDEFINED || - JS_VALUE_GET_TAG(array_arg) == JS_TAG_NULL) && magic != 2) { + if (JS_VALUE_GET_TAG(array_arg) == JS_TAG_NULL && magic != 2) { return JS_Call(ctx, this_val, this_arg, 0, NULL); } tab = build_arg_list(ctx, &len, array_arg); @@ -32086,7 +31996,7 @@ static JSValue js_function_call(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { if (argc <= 0) { - return JS_Call(ctx, this_val, JS_UNDEFINED, 0, NULL); + return JS_Call(ctx, this_val, JS_NULL, 0, NULL); } else { return JS_Call(ctx, this_val, argv[0], argc - 1, argv + 1); } @@ -32199,7 +32109,7 @@ static JSValue js_function_toString(JSContext *ctx, JSValueConst this_val, pref = "function "; suff = "() {\n [native code]\n}"; name = JS_GetProperty(ctx, this_val, JS_ATOM_name); - if (JS_IsUndefined(name)) + if (JS_IsNull(name)) name = JS_AtomToString(ctx, JS_ATOM_empty_string); return JS_ConcatString3(ctx, pref, name, suff); } @@ -32231,8 +32141,8 @@ static const JSCFunctionListEntry js_function_proto_funcs[] = { static JSValue iterator_to_array(JSContext *ctx, JSValueConst items) { - JSValue iter, next_method = JS_UNDEFINED; - JSValue v, r = JS_UNDEFINED; + JSValue iter, next_method = JS_NULL; + JSValue v, r = JS_NULL; int64_t k; BOOL done; @@ -32274,7 +32184,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, JSValueConst message, options; int arg_index; - if (JS_IsUndefined(new_target)) + if (JS_IsNull(new_target)) new_target = JS_GetActiveFunction(ctx); proto = JS_GetProperty(ctx, new_target, JS_ATOM_prototype); if (JS_IsException(proto)) @@ -32301,7 +32211,7 @@ static JSValue js_error_constructor(JSContext *ctx, JSValueConst new_target, arg_index = (magic == JS_AGGREGATE_ERROR); message = argv[arg_index++]; - if (!JS_IsUndefined(message)) { + if (!JS_IsNull(message)) { msg = JS_ToString(ctx, message); if (unlikely(JS_IsException(msg))) goto exception; @@ -32349,7 +32259,7 @@ static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val, if (!JS_IsObject(this_val)) return JS_ThrowTypeErrorNotAnObject(ctx); name = JS_GetProperty(ctx, this_val, JS_ATOM_name); - if (JS_IsUndefined(name)) + if (JS_IsNull(name)) name = JS_AtomToString(ctx, JS_ATOM_Error); else name = JS_ToStringFree(ctx, name); @@ -32357,7 +32267,7 @@ static JSValue js_error_toString(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; msg = JS_GetProperty(ctx, this_val, JS_ATOM_message); - if (JS_IsUndefined(msg)) + if (JS_IsNull(msg)) msg = JS_AtomToString(ctx, JS_ATOM_empty_string); else msg = JS_ToStringFree(ctx, msg); @@ -32486,17 +32396,17 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, int done, mapping; mapping = FALSE; - mapfn = JS_UNDEFINED; - this_arg = JS_UNDEFINED; - r = JS_UNDEFINED; - arrayLike = JS_UNDEFINED; - iter = JS_UNDEFINED; - enum_obj = JS_UNDEFINED; - next_method = JS_UNDEFINED; + mapfn = JS_NULL; + this_arg = JS_NULL; + r = JS_NULL; + arrayLike = JS_NULL; + iter = JS_NULL; + enum_obj = JS_NULL; + next_method = JS_NULL; if (argc > 1) { mapfn = argv[1]; - if (!JS_IsUndefined(mapfn)) { + if (!JS_IsNull(mapfn)) { if (check_function(ctx, mapfn)) goto exception; mapping = 1; @@ -32507,7 +32417,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, iter = JS_GetProperty(ctx, items, JS_ATOM_Symbol_iterator); if (JS_IsException(iter)) goto exception; - if (!JS_IsUndefined(iter) && !JS_IsNull(iter)) { + if (!JS_IsNull(iter) && !JS_IsNull(iter)) { if (!JS_IsFunction(ctx, iter)) { JS_ThrowTypeError(ctx, "value is not iterable"); goto exception; @@ -32554,7 +32464,7 @@ static JSValue js_array_from(JSContext *ctx, JSValueConst this_val, if (JS_IsConstructor(ctx, this_val)) { r = JS_CallConstructor(ctx, this_val, 1, args); } else { - r = js_array_constructor(ctx, JS_UNDEFINED, 1, args); + r = js_array_constructor(ctx, JS_NULL, 1, args); } JS_FreeValue(ctx, v); if (JS_IsException(r)) @@ -32650,7 +32560,7 @@ static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj, if (res < 0) return JS_EXCEPTION; if (!res) - return js_array_constructor(ctx, JS_UNDEFINED, 1, &len_val); + return js_array_constructor(ctx, JS_NULL, 1, &len_val); ctor = JS_GetProperty(ctx, obj, JS_ATOM_constructor); if (JS_IsException(ctor)) return ctor; @@ -32664,7 +32574,7 @@ static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj, if (realm != ctx && js_same_value(ctx, ctor, realm->array_ctor)) { JS_FreeValue(ctx, ctor); - ctor = JS_UNDEFINED; + ctor = JS_NULL; } } if (JS_IsObject(ctor)) { @@ -32674,10 +32584,10 @@ static JSValue JS_ArraySpeciesCreate(JSContext *ctx, JSValueConst obj, return species; ctor = species; if (JS_IsNull(ctor)) - ctor = JS_UNDEFINED; + ctor = JS_NULL; } - if (JS_IsUndefined(ctor)) { - return js_array_constructor(ctx, JS_UNDEFINED, 1, &len_val); + if (JS_IsNull(ctor)) { + return js_array_constructor(ctx, JS_NULL, 1, &len_val); } else { ret = JS_CallConstructor(ctx, ctor, 1, &len_val); JS_FreeValue(ctx, ctor); @@ -32701,7 +32611,7 @@ static int JS_isConcatSpreadable(JSContext *ctx, JSValueConst obj) val = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_isConcatSpreadable); if (JS_IsException(val)) return -1; - if (!JS_IsUndefined(val)) + if (!JS_IsNull(val)) return JS_ToBoolFree(ctx, val); return JS_IsArray(ctx, obj); } @@ -32724,7 +32634,7 @@ static JSValue js_array_at(JSContext *ctx, JSValueConst this_val, if (idx < 0) idx = len + idx; if (idx < 0 || idx >= len) { - ret = JS_UNDEFINED; + ret = JS_NULL; } else if (js_get_fast_array(ctx, obj, &arrp, &count) && idx < count) { ret = JS_DupValue(ctx, arrp[idx]); } else { @@ -32732,7 +32642,7 @@ static JSValue js_array_at(JSContext *ctx, JSValueConst this_val, if (present < 0) goto exception; if (!present) - ret = JS_UNDEFINED; + ret = JS_NULL; } JS_FreeValue(ctx, obj); return ret; @@ -32750,7 +32660,7 @@ static JSValue js_array_with(JSContext *ctx, JSValueConst this_val, uint32_t count32; ret = JS_EXCEPTION; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -32788,7 +32698,7 @@ static JSValue js_array_with(JSContext *ctx, JSValueConst this_val, if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) { fill_and_fail: for (; i < len; i++, pval++) - *pval = JS_UNDEFINED; + *pval = JS_NULL; goto exception; } } @@ -32798,7 +32708,7 @@ static JSValue js_array_with(JSContext *ctx, JSValueConst this_val, goto exception; ret = arr; - arr = JS_UNDEFINED; + arr = JS_NULL; exception: JS_FreeValue(ctx, arr); @@ -32814,7 +32724,7 @@ static JSValue js_array_concat(JSContext *ctx, JSValueConst this_val, int64_t len, k, n; int i, res; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (JS_IsException(obj)) goto exception; @@ -32887,13 +32797,13 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, int64_t len, k, n; int present; - ret = JS_UNDEFINED; - val = JS_UNDEFINED; + ret = JS_NULL; + val = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; func = argv[0]; - this_arg = JS_UNDEFINED; + this_arg = JS_NULL; if (argc > 1) this_arg = argv[1]; @@ -32966,7 +32876,7 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, break; } JS_FreeValue(ctx, val); - val = JS_UNDEFINED; + val = JS_NULL; } } done: @@ -32993,8 +32903,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, int64_t len, k, k1; int present; - acc = JS_UNDEFINED; - val = JS_UNDEFINED; + acc = JS_NULL; + val = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -33035,10 +32945,10 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, args[1] = val; args[2] = index_val; args[3] = obj; - acc1 = JS_Call(ctx, func, JS_UNDEFINED, 4, args); + acc1 = JS_Call(ctx, func, JS_NULL, 4, args); JS_FreeValue(ctx, index_val); JS_FreeValue(ctx, val); - val = JS_UNDEFINED; + val = JS_NULL; if (JS_IsException(acc1)) goto exception; JS_FreeValue(ctx, acc); @@ -33066,13 +32976,13 @@ static JSValue js_array_fill(JSContext *ctx, JSValueConst this_val, goto exception; start = 0; - if (argc > 1 && !JS_IsUndefined(argv[1])) { + if (argc > 1 && !JS_IsNull(argv[1])) { if (JS_ToInt64Clamp(ctx, &start, argv[1], 0, len, len)) goto exception; } end = len; - if (argc > 2 && !JS_IsUndefined(argv[2])) { + if (argc > 2 && !JS_IsNull(argv[2])) { if (JS_ToInt64Clamp(ctx, &end, argv[2], 0, len, len)) goto exception; } @@ -33245,8 +33155,8 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val, int64_t len, k, end; int dir; - index_val = JS_UNDEFINED; - val = JS_UNDEFINED; + index_val = JS_NULL; + val = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -33255,7 +33165,7 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val, if (check_function(ctx, func)) goto exception; - this_arg = JS_UNDEFINED; + this_arg = JS_NULL; if (argc > 1) this_arg = argv[1]; @@ -33300,7 +33210,7 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val, if (mode == ArrayFindIndex || mode == ArrayFindLastIndex) return JS_NewInt32(ctx, -1); else - return JS_UNDEFINED; + return JS_NULL; exception: JS_FreeValue(ctx, index_val); @@ -33335,7 +33245,7 @@ static JSValue js_array_toString(JSContext *ctx, JSValueConst this_val, static JSValue js_array_join(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int toLocaleString) { - JSValue obj, sep = JS_UNDEFINED, el; + JSValue obj, sep = JS_NULL, el; StringBuffer b_s, *b = &b_s; JSString *p = NULL; int64_t i, n; @@ -33346,7 +33256,7 @@ static JSValue js_array_join(JSContext *ctx, JSValueConst this_val, goto exception; c = ','; /* default separator */ - if (!toLocaleString && argc > 0 && !JS_IsUndefined(argv[0])) { + if (!toLocaleString && argc > 0 && !JS_IsNull(argv[0])) { sep = JS_ToString(ctx, argv[0]); if (JS_IsException(sep)) goto exception; @@ -33369,7 +33279,7 @@ static JSValue js_array_join(JSContext *ctx, JSValueConst this_val, el = JS_GetPropertyUint32(ctx, obj, i); if (JS_IsException(el)) goto fail; - if (!JS_IsNull(el) && !JS_IsUndefined(el)) { + if (!JS_IsNull(el) && !JS_IsNull(el)) { if (toLocaleString) { el = JS_ToLocaleStringFree(ctx, el); } @@ -33392,7 +33302,7 @@ exception: static JSValue js_array_pop(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int shift) { - JSValue obj, res = JS_UNDEFINED; + JSValue obj, res = JS_NULL; int64_t len, newLen; JSValue *arrp; uint32_t count32; @@ -33488,7 +33398,7 @@ static JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val, int l_present, h_present; uint32_t count32; - lval = JS_UNDEFINED; + lval = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -33520,10 +33430,10 @@ static JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val, if (l_present) { if (JS_SetPropertyInt64(ctx, obj, h, lval) < 0) { - lval = JS_UNDEFINED; + lval = JS_NULL; goto exception; } - lval = JS_UNDEFINED; + lval = JS_NULL; } else { if (JS_DeletePropertyInt64(ctx, obj, h, JS_PROP_THROW) < 0) goto exception; @@ -33533,10 +33443,10 @@ static JSValue js_array_reverse(JSContext *ctx, JSValueConst this_val, if (JS_DeletePropertyInt64(ctx, obj, l, JS_PROP_THROW) < 0) goto exception; if (JS_SetPropertyInt64(ctx, obj, h, lval) < 0) { - lval = JS_UNDEFINED; + lval = JS_NULL; goto exception; } - lval = JS_UNDEFINED; + lval = JS_NULL; } } } @@ -33561,7 +33471,7 @@ static JSValue js_array_toReversed(JSContext *ctx, JSValueConst this_val, uint32_t count32; ret = JS_EXCEPTION; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -33584,7 +33494,7 @@ static JSValue js_array_toReversed(JSContext *ctx, JSValueConst this_val, if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) { // Exception; initialize remaining elements. for (; i >= 0; i--, pval++) - *pval = JS_UNDEFINED; + *pval = JS_NULL; goto exception; } } @@ -33595,7 +33505,7 @@ static JSValue js_array_toReversed(JSContext *ctx, JSValueConst this_val, } ret = arr; - arr = JS_UNDEFINED; + arr = JS_NULL; exception: JS_FreeValue(ctx, arr); @@ -33612,7 +33522,7 @@ static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val, JSValue *arrp; uint32_t count32, i, item_count; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -33641,7 +33551,7 @@ static JSValue js_array_slice(JSContext *ctx, JSValueConst this_val, } else { item_count = 0; /* avoid warning */ final = len; - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { if (JS_ToInt64Clamp(ctx, &final, argv[1], 0, len, len)) goto exception; } @@ -33721,7 +33631,7 @@ static JSValue js_array_toSpliced(JSContext *ctx, JSValueConst this_val, pval = NULL; last = NULL; ret = JS_EXCEPTION; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) @@ -33785,11 +33695,11 @@ static JSValue js_array_toSpliced(JSContext *ctx, JSValueConst this_val, done: ret = arr; - arr = JS_UNDEFINED; + arr = JS_NULL; exception: while (pval != last) - *pval++ = JS_UNDEFINED; + *pval++ = JS_NULL; JS_FreeValue(ctx, arr); JS_FreeValue(ctx, obj); @@ -33813,7 +33723,7 @@ static JSValue js_array_copyWithin(JSContext *ctx, JSValueConst this_val, goto exception; final = len; - if (argc > 2 && !JS_IsUndefined(argv[2])) { + if (argc > 2 && !JS_IsNull(argv[2])) { if (JS_ToInt64Clamp(ctx, &final, argv[2], 0, len, len)) goto exception; } @@ -33852,7 +33762,7 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target, return -1; if (!present) continue; - if (!JS_IsUndefined(mapperFunction)) { + if (!JS_IsNull(mapperFunction)) { JSValueConst args[3] = { element, JS_NewInt64(ctx, sourceIndex), source }; element = JS_Call(ctx, mapperFunction, thisArg, 3, args); JS_FreeValue(ctx, (JSValue)args[0]); @@ -33870,7 +33780,7 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target, targetIndex = JS_FlattenIntoArray(ctx, target, element, elementLen, targetIndex, depth - 1, - JS_UNDEFINED, JS_UNDEFINED); + JS_NULL, JS_NULL); if (targetIndex < 0) goto fail; JS_FreeValue(ctx, element); @@ -33901,14 +33811,14 @@ static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val, int64_t sourceLen; int depthNum; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &sourceLen, obj)) goto exception; depthNum = 1; - mapperFunction = JS_UNDEFINED; - thisArg = JS_UNDEFINED; + mapperFunction = JS_NULL; + thisArg = JS_NULL; if (map) { mapperFunction = argv[0]; if (argc > 1) { @@ -33917,7 +33827,7 @@ static JSValue js_array_flatten(JSContext *ctx, JSValueConst this_val, if (check_function(ctx, mapperFunction)) goto exception; } else { - if (argc > 0 && !JS_IsUndefined(argv[0])) { + if (argc > 0 && !JS_IsNull(argv[0])) { if (JS_ToInt32Sat(ctx, &depthNum, argv[0]) < 0) goto exception; } @@ -33972,7 +33882,7 @@ static int js_array_cmp_generic(const void *a, const void *b, void *opaque) { goto cmp_same; argv[0] = ap->val; argv[1] = bp->val; - res = JS_Call(ctx, psc->method, JS_UNDEFINED, 2, argv); + res = JS_Call(ctx, psc->method, JS_NULL, 2, argv); if (JS_IsException(res)) goto exception; if (JS_VALUE_GET_TAG(res) == JS_TAG_INT) { @@ -34017,13 +33927,13 @@ static JSValue js_array_sort(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { struct array_sort_context asc = { ctx, 0, 0, argv[0] }; - JSValue obj = JS_UNDEFINED; + JSValue obj = JS_NULL; ValueSlot *array = NULL; size_t array_size = 0, pos = 0, n = 0; int64_t i, len, undefined_count = 0; int present; - if (!JS_IsUndefined(asc.method)) { + if (!JS_IsNull(asc.method)) { if (check_function(ctx, asc.method)) goto exception; asc.has_method = 1; @@ -34050,7 +33960,7 @@ static JSValue js_array_sort(JSContext *ctx, JSValueConst this_val, goto exception; if (present == 0) continue; - if (JS_IsUndefined(array[pos].val)) { + if (JS_IsNull(array[pos].val)) { undefined_count++; continue; } @@ -34078,7 +33988,7 @@ static JSValue js_array_sort(JSContext *ctx, JSValueConst this_val, } js_free(ctx, array); for (i = n; undefined_count-- > 0; i++) { - if (JS_SetPropertyInt64(ctx, obj, i, JS_UNDEFINED) < 0) + if (JS_SetPropertyInt64(ctx, obj, i, JS_NULL) < 0) goto fail; } for (; i < len; i++) { @@ -34112,12 +34022,12 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValueConst this_val, uint32_t count32; int ok; - ok = JS_IsUndefined(argv[0]) || JS_IsFunction(ctx, argv[0]); + ok = JS_IsNull(argv[0]) || JS_IsFunction(ctx, argv[0]); if (!ok) return JS_ThrowTypeError(ctx, "not a function"); ret = JS_EXCEPTION; - arr = JS_UNDEFINED; + arr = JS_NULL; obj = JS_ToObject(ctx, this_val); if (js_get_length64(ctx, &len, obj)) goto exception; @@ -34137,7 +34047,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValueConst this_val, for (; i < len; i++, pval++) { if (-1 == JS_TryGetPropertyInt64(ctx, obj, i, pval)) { for (; i < len; i++, pval++) - *pval = JS_UNDEFINED; + *pval = JS_NULL; goto exception; } } @@ -34153,7 +34063,7 @@ static JSValue js_array_toSorted(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, ret); ret = arr; - arr = JS_UNDEFINED; + arr = JS_NULL; exception: JS_FreeValue(ctx, arr); @@ -34252,7 +34162,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, it = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_ITERATOR); if (!it) goto fail1; - if (JS_IsUndefined(it->obj)) + if (JS_IsNull(it->obj)) goto done; if (js_get_length32(ctx, &len, it->obj)) { @@ -34264,10 +34174,10 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValueConst this_val, idx = it->idx; if (idx >= len) { JS_FreeValue(ctx, it->obj); - it->obj = JS_UNDEFINED; + it->obj = JS_NULL; done: *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } it->idx = idx + 1; *pdone = FALSE; @@ -34381,7 +34291,7 @@ static JSValue js_number_constructor(JSContext *ctx, JSValueConst new_target, break; } } - if (!JS_IsUndefined(new_target)) { + if (!JS_IsNull(new_target)) { obj = js_create_from_ctor(ctx, new_target, JS_CLASS_NUMBER); if (!JS_IsException(obj)) JS_SetObjectData(ctx, obj, val); @@ -34509,7 +34419,7 @@ static JSValue js_number_toString(JSContext *ctx, JSValueConst this_val, val = js_thisNumberValue(ctx, this_val); if (JS_IsException(val)) return val; - if (magic || JS_IsUndefined(argv[0])) { + if (magic || JS_IsNull(argv[0])) { base = 10; } else { base = js_get_radix(ctx, argv[0]); @@ -34573,7 +34483,7 @@ static JSValue js_number_toExponential(JSContext *ctx, JSValueConst this_val, if (!isfinite(d)) { return JS_ToStringFree(ctx, __JS_NewFloat64(ctx, d)); } - if (JS_IsUndefined(argv[0])) { + if (JS_IsNull(argv[0])) { flags = JS_DTOA_FORMAT_FREE; f = 0; } else { @@ -34597,7 +34507,7 @@ static JSValue js_number_toPrecision(JSContext *ctx, JSValueConst this_val, return val; if (JS_ToFloat64Free(ctx, &d, val)) return JS_EXCEPTION; - if (JS_IsUndefined(argv[0])) + if (JS_IsNull(argv[0])) goto to_string; if (JS_ToInt32Sat(ctx, &p, argv[0])) return JS_EXCEPTION; @@ -34667,7 +34577,7 @@ static JSValue js_boolean_constructor(JSContext *ctx, JSValueConst new_target, { JSValue val, obj; val = JS_NewBool(ctx, JS_ToBool(ctx, argv[0])); - if (!JS_IsUndefined(new_target)) { + if (!JS_IsNull(new_target)) { obj = js_create_from_ctor(ctx, new_target, JS_CLASS_BOOLEAN); if (!JS_IsException(obj)) JS_SetObjectData(ctx, obj, val); @@ -34734,8 +34644,8 @@ static int js_string_get_own_property(JSContext *ctx, ch = string_get(p1, idx); desc->flags = JS_PROP_ENUMERABLE; desc->value = js_new_string_char(ctx, ch); - desc->getter = JS_UNDEFINED; - desc->setter = JS_UNDEFINED; + desc->getter = JS_NULL; + desc->setter = JS_NULL; } return TRUE; } @@ -34811,7 +34721,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target, if (argc == 0) { val = JS_AtomToString(ctx, JS_ATOM_empty_string); } else { - if (JS_IsUndefined(new_target) && JS_IsSymbol(argv[0])) { + if (JS_IsNull(new_target) && JS_IsSymbol(argv[0])) { JSAtomStruct *p = JS_VALUE_GET_PTR(argv[0]); val = JS_ConcatString3(ctx, "Symbol(", JS_AtomToString(ctx, js_get_atom_index(ctx->rt, p)), ")"); } else { @@ -34820,7 +34730,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValueConst new_target, if (JS_IsException(val)) return val; } - if (!JS_IsUndefined(new_target)) { + if (!JS_IsNull(new_target)) { JSString *p1 = JS_VALUE_GET_STRING(val); obj = js_create_from_ctor(ctx, new_target, JS_CLASS_STRING); @@ -34913,7 +34823,7 @@ static JSValue js_string_raw(JSContext *ctx, JSValueConst this_val, int64_t i, n; string_buffer_init(ctx, b, 0); - raw = JS_UNDEFINED; + raw = JS_NULL; cooked = JS_ToObject(ctx, argv[0]); if (JS_IsException(cooked)) goto exception; @@ -35026,7 +34936,7 @@ static JSValue js_string_charAt(JSContext *ctx, JSValueConst this_val, idx += p->len; if (idx < 0 || idx >= p->len) { if (is_at) - ret = JS_UNDEFINED; + ret = JS_NULL; else ret = JS_AtomToString(ctx, JS_ATOM_empty_string); } else { @@ -35053,7 +34963,7 @@ static JSValue js_string_codePointAt(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } if (idx < 0 || idx >= p->len) { - ret = JS_UNDEFINED; + ret = JS_NULL; } else { c = string_getc(p, &idx); ret = JS_NewInt32(ctx, c); @@ -35283,7 +35193,7 @@ static int js_is_regexp(JSContext *ctx, JSValueConst obj); static JSValue js_string_includes(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic) { - JSValue str, v = JS_UNDEFINED; + JSValue str, v = JS_NULL; int i, len, v_len, pos, start, stop, ret; JSString *p; JSString *p1; @@ -35305,7 +35215,7 @@ static JSValue js_string_includes(JSContext *ctx, JSValueConst this_val, len = p->len; v_len = p1->len; pos = (magic == 2) ? len : 0; - if (argc > 1 && !JS_IsUndefined(argv[1])) { + if (argc > 1 && !JS_IsNull(argv[1])) { if (JS_ToInt32Clamp(ctx, &pos, argv[1], 0, len, 0)) goto fail; } @@ -35356,7 +35266,7 @@ static int check_regexp_g_flag(JSContext *ctx, JSValueConst regexp) flags = JS_GetProperty(ctx, regexp, JS_ATOM_flags); if (JS_IsException(flags)) return -1; - if (JS_IsUndefined(flags) || JS_IsNull(flags)) { + if (JS_IsNull(flags) || JS_IsNull(flags)) { JS_ThrowTypeError(ctx, "cannot convert to object"); return -1; } @@ -35382,10 +35292,10 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val, JSValue matcher, S, rx, result, str; int args_len; - if (JS_IsUndefined(O) || JS_IsNull(O)) + if (JS_IsNull(O) || JS_IsNull(O)) return JS_ThrowTypeError(ctx, "cannot convert to object"); - if (!JS_IsUndefined(regexp) && !JS_IsNull(regexp)) { + if (!JS_IsNull(regexp) && !JS_IsNull(regexp)) { matcher = JS_GetProperty(ctx, regexp, atom); if (JS_IsException(matcher)) return JS_EXCEPTION; @@ -35395,7 +35305,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } } - if (!JS_IsUndefined(matcher) && !JS_IsNull(matcher)) { + if (!JS_IsNull(matcher) && !JS_IsNull(matcher)) { return JS_CallFree(ctx, matcher, regexp, 1, &O); } } @@ -35404,7 +35314,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; args_len = 1; args[0] = regexp; - str = JS_UNDEFINED; + str = JS_NULL; if (atom == JS_ATOM_Symbol_matchAll) { str = js_new_string8(ctx, "g"); if (JS_IsException(str)) @@ -35450,7 +35360,7 @@ static JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst this_val string_buffer_init(ctx, b, 0); captures_len = 0; - if (!JS_IsUndefined(captures)) { + if (!JS_IsNull(captures)) { if (js_get_length32(ctx, &captures_len, captures)) goto exception; } @@ -35496,14 +35406,14 @@ static JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst this_val s = JS_GetPropertyInt64(ctx, captures, k); if (JS_IsException(s)) goto exception; - if (!JS_IsUndefined(s)) { + if (!JS_IsNull(s)) { if (string_buffer_concat_value_free(b, s)) goto exception; } } else { goto norep; } - } else if (c == '<' && !JS_IsUndefined(namedCaptures)) { + } else if (c == '<' && !JS_IsNull(namedCaptures)) { k = string_indexof_char(rp, '>', j); if (k < 0) goto norep; @@ -35513,7 +35423,7 @@ static JSValue js_string___GetSubstitution(JSContext *ctx, JSValueConst this_val capture = JS_GetPropertyValue(ctx, namedCaptures, name); if (JS_IsException(capture)) goto exception; - if (!JS_IsUndefined(capture)) { + if (!JS_IsNull(capture)) { if (string_buffer_concat_value_free(b, capture)) goto exception; } @@ -35544,14 +35454,14 @@ static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val, int pos, functionalReplace, endOfLastMatch; BOOL is_first; - if (JS_IsUndefined(O) || JS_IsNull(O)) + if (JS_IsNull(O) || JS_IsNull(O)) return JS_ThrowTypeError(ctx, "cannot convert to object"); - search_str = JS_UNDEFINED; - replaceValue_str = JS_UNDEFINED; - repl_str = JS_UNDEFINED; + search_str = JS_NULL; + replaceValue_str = JS_NULL; + repl_str = JS_NULL; - if (!JS_IsUndefined(searchValue) && !JS_IsNull(searchValue)) { + if (!JS_IsNull(searchValue) && !JS_IsNull(searchValue)) { JSValue replacer; if (is_replaceAll) { if (check_regexp_g_flag(ctx, searchValue) < 0) @@ -35560,7 +35470,7 @@ static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val, replacer = JS_GetProperty(ctx, searchValue, JS_ATOM_Symbol_replace); if (JS_IsException(replacer)) return JS_EXCEPTION; - if (!JS_IsUndefined(replacer) && !JS_IsNull(replacer)) { + if (!JS_IsNull(replacer) && !JS_IsNull(replacer)) { args[0] = O; args[1] = replaceValue; return JS_CallFree(ctx, replacer, searchValue, 2, args); @@ -35610,15 +35520,15 @@ static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val, args[0] = search_str; args[1] = JS_NewInt32(ctx, pos); args[2] = str; - repl_str = JS_ToStringFree(ctx, JS_Call(ctx, replaceValue, JS_UNDEFINED, 3, args)); + repl_str = JS_ToStringFree(ctx, JS_Call(ctx, replaceValue, JS_NULL, 3, args)); } else { args[0] = search_str; args[1] = str; args[2] = JS_NewInt32(ctx, pos); - args[3] = JS_UNDEFINED; - args[4] = JS_UNDEFINED; + args[3] = JS_NULL; + args[4] = JS_NULL; args[5] = replaceValue_str; - repl_str = js_string___GetSubstitution(ctx, JS_UNDEFINED, 6, args); + repl_str = js_string___GetSubstitution(ctx, JS_NULL, 6, args); } if (JS_IsException(repl_str)) goto exception; @@ -35655,19 +35565,19 @@ static JSValue js_string_split(JSContext *ctx, JSValueConst this_val, int64_t p, q, s, r, e; JSString *sp, *rp; - if (JS_IsUndefined(O) || JS_IsNull(O)) + if (JS_IsNull(O) || JS_IsNull(O)) return JS_ThrowTypeError(ctx, "cannot convert to object"); - S = JS_UNDEFINED; - A = JS_UNDEFINED; - R = JS_UNDEFINED; + S = JS_NULL; + A = JS_NULL; + R = JS_NULL; - if (!JS_IsUndefined(separator) && !JS_IsNull(separator)) { + if (!JS_IsNull(separator) && !JS_IsNull(separator)) { JSValue splitter; splitter = JS_GetProperty(ctx, separator, JS_ATOM_Symbol_split); if (JS_IsException(splitter)) return JS_EXCEPTION; - if (!JS_IsUndefined(splitter) && !JS_IsNull(splitter)) { + if (!JS_IsNull(splitter) && !JS_IsNull(splitter)) { args[0] = O; args[1] = limit; return JS_CallFree(ctx, splitter, separator, 2, args); @@ -35680,7 +35590,7 @@ static JSValue js_string_split(JSContext *ctx, JSValueConst this_val, if (JS_IsException(A)) goto exception; lengthA = 0; - if (JS_IsUndefined(limit)) { + if (JS_IsNull(limit)) { lim = 0xffffffff; } else { if (JS_ToUint32(ctx, &lim, limit) < 0) @@ -35696,7 +35606,7 @@ static JSValue js_string_split(JSContext *ctx, JSValueConst this_val, p = 0; if (lim == 0) goto done; - if (JS_IsUndefined(separator)) + if (JS_IsNull(separator)) goto add_tail; if (s == 0) { if (r != 0) @@ -35750,7 +35660,7 @@ static JSValue js_string_substring(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } b = p->len; - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { if (JS_ToInt32Clamp(ctx, &b, argv[1], 0, p->len, 0)) { JS_FreeValue(ctx, str); return JS_EXCEPTION; @@ -35785,7 +35695,7 @@ static JSValue js_string_substr(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } n = len - a; - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { if (JS_ToInt32Clamp(ctx, &n, argv[1], 0, len - a, 0)) { JS_FreeValue(ctx, str); return JS_EXCEPTION; @@ -35813,7 +35723,7 @@ static JSValue js_string_slice(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; } end = len; - if (!JS_IsUndefined(argv[1])) { + if (!JS_IsNull(argv[1])) { if (JS_ToInt32Clamp(ctx, &end, argv[1], 0, len, len)) { JS_FreeValue(ctx, str); return JS_EXCEPTION; @@ -35827,7 +35737,7 @@ static JSValue js_string_slice(JSContext *ctx, JSValueConst this_val, static JSValue js_string_pad(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int padEnd) { - JSValue str, v = JS_UNDEFINED; + JSValue str, v = JS_NULL; StringBuffer b_s, *b = &b_s; JSString *p, *p1 = NULL; int n, len, c = ' '; @@ -35841,7 +35751,7 @@ static JSValue js_string_pad(JSContext *ctx, JSValueConst this_val, len = p->len; if (len >= n) return str; - if (argc > 1 && !JS_IsUndefined(argv[1])) { + if (argc > 1 && !JS_IsNull(argv[1])) { v = JS_ToString(ctx, argv[1]); if (JS_IsException(v)) goto fail2; @@ -36143,7 +36053,7 @@ static JSValue js_string_normalize(JSContext *ctx, JSValueConst this_val, if (JS_IsException(val)) return val; - if (argc == 0 || JS_IsUndefined(argv[0])) { + if (argc == 0 || JS_IsNull(argv[0])) { n_type = UNICODE_NFC; } else { form = JS_ToCStringLen(ctx, &form_len, argv[0]); @@ -36321,16 +36231,16 @@ static JSValue js_string_iterator_next(JSContext *ctx, JSValueConst this_val, *pdone = FALSE; return JS_EXCEPTION; } - if (JS_IsUndefined(it->obj)) + if (JS_IsNull(it->obj)) goto done; p = JS_VALUE_GET_STRING(it->obj); idx = it->idx; if (idx >= p->len) { JS_FreeValue(ctx, it->obj); - it->obj = JS_UNDEFINED; + it->obj = JS_NULL; done: *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } start = idx; @@ -36744,7 +36654,7 @@ static JSValue js_compile_regexp(JSContext *ctx, JSValueConst pattern, char error_msg[64]; re_flags = 0; - if (!JS_IsUndefined(flags)) { + if (!JS_IsNull(flags)) { str = JS_ToCStringLen(ctx, &len, flags); if (!str) return JS_EXCEPTION; @@ -36864,7 +36774,7 @@ static int js_is_regexp(JSContext *ctx, JSValueConst obj) m = JS_GetProperty(ctx, obj, JS_ATOM_Symbol_match); if (JS_IsException(m)) return -1; - if (!JS_IsUndefined(m)) + if (!JS_IsNull(m)) return JS_ToBoolFree(ctx, m); return js_get_regexp(ctx, obj, FALSE) != NULL; } @@ -36882,10 +36792,10 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, pat_is_regexp = js_is_regexp(ctx, pat); if (pat_is_regexp < 0) return JS_EXCEPTION; - if (JS_IsUndefined(new_target)) { + if (JS_IsNull(new_target)) { /* called as a function */ new_target = JS_GetActiveFunction(ctx); - if (pat_is_regexp && JS_IsUndefined(flags1)) { + if (pat_is_regexp && JS_IsNull(flags1)) { JSValue ctor; BOOL res; ctor = JS_GetProperty(ctx, pat, JS_ATOM_constructor); @@ -36900,7 +36810,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, re = js_get_regexp(ctx, pat, FALSE); if (re) { pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->pattern)); - if (JS_IsUndefined(flags1)) { + if (JS_IsNull(flags1)) { bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re->bytecode)); goto no_compilation; } else { @@ -36909,12 +36819,12 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, goto fail; } } else { - flags = JS_UNDEFINED; + flags = JS_NULL; if (pat_is_regexp) { pattern = JS_GetProperty(ctx, pat, JS_ATOM_source); if (JS_IsException(pattern)) goto fail; - if (JS_IsUndefined(flags1)) { + if (JS_IsNull(flags1)) { flags = JS_GetProperty(ctx, pat, JS_ATOM_flags); if (JS_IsException(flags)) goto fail; @@ -36925,7 +36835,7 @@ static JSValue js_regexp_constructor(JSContext *ctx, JSValueConst new_target, pattern = JS_DupValue(ctx, pat); flags = JS_DupValue(ctx, flags1); } - if (JS_IsUndefined(pattern)) { + if (JS_IsNull(pattern)) { pattern = JS_AtomToString(ctx, JS_ATOM_empty_string); } else { val = pattern; @@ -36961,13 +36871,13 @@ static JSValue js_regexp_compile(JSContext *ctx, JSValueConst this_val, flags1 = argv[1]; re1 = js_get_regexp(ctx, pattern1, FALSE); if (re1) { - if (!JS_IsUndefined(flags1)) + if (!JS_IsNull(flags1)) return JS_ThrowTypeError(ctx, "flags must be undefined"); pattern = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->pattern)); bc = JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, re1->bytecode)); } else { - bc = JS_UNDEFINED; - if (JS_IsUndefined(pattern1)) + bc = JS_NULL; + if (JS_IsNull(pattern1)) pattern = JS_AtomToString(ctx, JS_ATOM_empty_string); else pattern = JS_ToString(ctx, pattern1); @@ -37089,7 +36999,7 @@ static JSValue js_regexp_get_flag(JSContext *ctx, JSValueConst this_val, int mas re = js_get_regexp(ctx, this_val, FALSE); if (!re) { if (js_same_value(ctx, this_val, ctx->class_proto[JS_CLASS_REGEXP])) - return JS_UNDEFINED; + return JS_NULL; else return JS_ThrowTypeErrorInvalidClass(ctx, JS_CLASS_REGEXP); } @@ -37252,9 +37162,9 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, ret = JS_EXCEPTION; obj = JS_NULL; - groups = JS_UNDEFINED; - indices = JS_UNDEFINED; - indices_groups = JS_UNDEFINED; + groups = JS_NULL; + indices = JS_NULL; + indices_groups = JS_NULL; capture = NULL; val = JS_GetProperty(ctx, this_val, JS_ATOM_lastIndex); @@ -37342,8 +37252,8 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, end = (match[1] - str_buf) >> shift; } - if (!JS_IsUndefined(indices)) { - val = JS_UNDEFINED; + if (!JS_IsNull(indices)) { + val = JS_NULL; if (start != -1) { val = JS_NewArray(ctx); if (JS_IsException(val)) @@ -37361,7 +37271,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, goto fail; } } - if (name && !JS_IsUndefined(indices_groups)) { + if (name && !JS_IsNull(indices_groups)) { val = JS_DupValue(ctx, val); if (JS_DefinePropertyValueStr(ctx, indices_groups, name, val, prop_flags) < 0) { @@ -37375,7 +37285,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, } } - val = JS_UNDEFINED; + val = JS_NULL; if (start != -1) { val = js_sub_string(ctx, str, start, end); if (JS_IsException(val)) @@ -37399,23 +37309,23 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_index, t, prop_flags) < 0) goto fail; - t = str_val, str_val = JS_UNDEFINED; + t = str_val, str_val = JS_NULL; if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_input, t, prop_flags) < 0) goto fail; - t = groups, groups = JS_UNDEFINED; + t = groups, groups = JS_NULL; if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_groups, t, prop_flags) < 0) { goto fail; } - if (!JS_IsUndefined(indices)) { - t = indices_groups, indices_groups = JS_UNDEFINED; + if (!JS_IsNull(indices)) { + t = indices_groups, indices_groups = JS_NULL; if (JS_DefinePropertyValue(ctx, indices, JS_ATOM_groups, t, prop_flags) < 0) { goto fail; } - t = indices, indices = JS_UNDEFINED; + t = indices, indices = JS_NULL; if (JS_DefinePropertyValue(ctx, obj, JS_ATOM_indices, t, prop_flags) < 0) { goto fail; @@ -37423,7 +37333,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValueConst this_val, } } ret = obj; - obj = JS_UNDEFINED; + obj = JS_NULL; fail: JS_FreeValue(ctx, indices_groups); JS_FreeValue(ctx, indices); @@ -37594,10 +37504,10 @@ static JSValue js_regexp_Symbol_match(JSContext *ctx, JSValueConst this_val, if (!JS_IsObject(rx)) return JS_ThrowTypeErrorNotAnObject(ctx); - A = JS_UNDEFINED; - flags = JS_UNDEFINED; - result = JS_UNDEFINED; - matchStr = JS_UNDEFINED; + A = JS_NULL; + flags = JS_NULL; + result = JS_NULL; + matchStr = JS_NULL; S = JS_ToString(ctx, argv[0]); if (JS_IsException(S)) goto exception; @@ -37702,7 +37612,7 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx, { JSRegExpStringIteratorData *it; JSValueConst R, S; - JSValue matchStr = JS_UNDEFINED, match = JS_UNDEFINED; + JSValue matchStr = JS_NULL, match = JS_NULL; JSString *sp; it = JS_GetOpaque2(ctx, this_val, JS_CLASS_REGEXP_STRING_ITERATOR); @@ -37710,7 +37620,7 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx, goto exception; if (it->done) { *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } R = it->iterating_regexp; S = it->iterated_string; @@ -37720,7 +37630,7 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx, if (JS_IsNull(match)) { it->done = TRUE; *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } else if (it->global) { matchStr = JS_ToStringFree(ctx, JS_GetPropertyInt64(ctx, match, 0)); if (JS_IsException(matchStr)) @@ -37763,10 +37673,10 @@ static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValueConst this_val, if (!JS_IsObject(R)) return JS_ThrowTypeErrorNotAnObject(ctx); - C = JS_UNDEFINED; - flags = JS_UNDEFINED; - matcher = JS_UNDEFINED; - iter = JS_UNDEFINED; + C = JS_NULL; + flags = JS_NULL; + matcher = JS_NULL; + iter = JS_NULL; S = JS_ToString(ctx, argv[0]); if (JS_IsException(S)) @@ -37918,12 +37828,12 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, string_buffer_init(ctx, b, 0); value_buffer_init(ctx, results); - rep_val = JS_UNDEFINED; - matched = JS_UNDEFINED; - tab = JS_UNDEFINED; - flags = JS_UNDEFINED; - rep_str = JS_UNDEFINED; - namedCaptures = JS_UNDEFINED; + rep_val = JS_NULL; + matched = JS_NULL; + tab = JS_NULL; + flags = JS_NULL; + rep_str = JS_NULL; + namedCaptures = JS_NULL; str = JS_ToString(ctx, argv[0]); if (JS_IsException(str)) @@ -38016,7 +37926,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, capN = JS_GetPropertyInt64(ctx, result, n); if (JS_IsException(capN)) goto exception; - if (!JS_IsUndefined(capN)) { + if (!JS_IsNull(capN)) { capN = JS_ToStringFree(ctx, capN); if (JS_IsException(capN)) goto exception; @@ -38034,22 +37944,22 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, goto exception; if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_DupValue(ctx, str), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; - if (!JS_IsUndefined(namedCaptures)) { + if (!JS_IsNull(namedCaptures)) { if (JS_DefinePropertyValueInt64(ctx, tab, n++, JS_DupValue(ctx, namedCaptures), JS_PROP_C_W_E | JS_PROP_THROW) < 0) goto exception; } - args[0] = JS_UNDEFINED; + args[0] = JS_NULL; args[1] = tab; JS_FreeValue(ctx, rep_str); rep_str = JS_ToStringFree(ctx, js_function_apply(ctx, rep, 2, args, 0)); } else { JSValue namedCaptures1; - if (!JS_IsUndefined(namedCaptures)) { + if (!JS_IsNull(namedCaptures)) { namedCaptures1 = JS_ToObject(ctx, namedCaptures); if (JS_IsException(namedCaptures1)) goto exception; } else { - namedCaptures1 = JS_UNDEFINED; + namedCaptures1 = JS_NULL; } args[0] = matched; args[1] = str; @@ -38058,7 +37968,7 @@ static JSValue js_regexp_Symbol_replace(JSContext *ctx, JSValueConst this_val, args[4] = namedCaptures1; args[5] = rep_val; JS_FreeValue(ctx, rep_str); - rep_str = js_string___GetSubstitution(ctx, JS_UNDEFINED, 6, args); + rep_str = js_string___GetSubstitution(ctx, JS_NULL, 6, args); JS_FreeValue(ctx, namedCaptures1); } if (JS_IsException(rep_str)) @@ -38098,9 +38008,9 @@ static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val, if (!JS_IsObject(rx)) return JS_ThrowTypeErrorNotAnObject(ctx); - result = JS_UNDEFINED; - currentLastIndex = JS_UNDEFINED; - previousLastIndex = JS_UNDEFINED; + result = JS_NULL; + currentLastIndex = JS_NULL; + previousLastIndex = JS_NULL; str = JS_ToString(ctx, argv[0]); if (JS_IsException(str)) goto exception; @@ -38124,7 +38034,7 @@ static JSValue js_regexp_Symbol_search(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, previousLastIndex); } else { if (JS_SetProperty(ctx, rx, JS_ATOM_lastIndex, previousLastIndex) < 0) { - previousLastIndex = JS_UNDEFINED; + previousLastIndex = JS_NULL; goto exception; } } @@ -38162,11 +38072,11 @@ static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_val, if (!JS_IsObject(rx)) return JS_ThrowTypeErrorNotAnObject(ctx); - ctor = JS_UNDEFINED; - splitter = JS_UNDEFINED; - A = JS_UNDEFINED; - flags = JS_UNDEFINED; - z = JS_UNDEFINED; + ctor = JS_NULL; + splitter = JS_NULL; + A = JS_NULL; + flags = JS_NULL; + z = JS_NULL; str = JS_ToString(ctx, argv[0]); if (JS_IsException(str)) goto exception; @@ -38193,7 +38103,7 @@ static JSValue js_regexp_Symbol_split(JSContext *ctx, JSValueConst this_val, if (JS_IsException(A)) goto exception; lengthA = 0; - if (JS_IsUndefined(argv[1])) { + if (JS_IsNull(argv[1])) { lim = 0xffffffff; } else { if (JS_ToUint32(ctx, &lim, argv[1]) < 0) @@ -38484,7 +38394,7 @@ JSValue JS_ParseJSON2(JSContext *ctx, const char *buf, size_t buf_len, const char *filename, int flags) { JSParseState s1, *s = &s1; - JSValue val = JS_UNDEFINED; + JSValue val = JS_NULL; js_parse_init(ctx, s, buf, buf_len, filename); s->ext_json = ((flags & JS_PARSE_JSON_EXT) != 0); @@ -38552,7 +38462,7 @@ static JSValue internalize_json_property(JSContext *ctx, JSValueConst holder, JS_FreeAtom(ctx, prop); goto fail; } - if (JS_IsUndefined(new_el)) { + if (JS_IsNull(new_el)) { ret = JS_DeleteProperty(ctx, val, prop, 0); } else { ret = JS_DefinePropertyValue(ctx, val, prop, new_el, JS_PROP_C_W_E); @@ -38651,7 +38561,7 @@ static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc, } } - if (!JS_IsUndefined(jsc->replacer_func)) { + if (!JS_IsNull(jsc->replacer_func)) { args[0] = key; args[1] = val; v = JS_Call(ctx, jsc->replacer_func, holder, 2, args); @@ -38679,7 +38589,7 @@ static JSValue js_json_check(JSContext *ctx, JSONStringifyContext *jsc, break; } JS_FreeValue(ctx, val); - return JS_UNDEFINED; + return JS_NULL; exception: JS_FreeValue(ctx, val); @@ -38696,11 +38606,11 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, int cl, ret; BOOL has_content; - indent1 = JS_UNDEFINED; - sep = JS_UNDEFINED; - sep1 = JS_UNDEFINED; - tab = JS_UNDEFINED; - prop = JS_UNDEFINED; + indent1 = JS_NULL; + sep = JS_NULL; + sep1 = JS_NULL; + tab = JS_NULL; + prop = JS_NULL; if (js_check_stack_overflow(ctx->rt, 0)) { JS_ThrowStackOverflow(ctx); @@ -38770,10 +38680,10 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, goto exception; v = js_json_check(ctx, jsc, val, v, prop); JS_FreeValue(ctx, prop); - prop = JS_UNDEFINED; + prop = JS_NULL; if (JS_IsException(v)) goto exception; - if (JS_IsUndefined(v)) + if (JS_IsNull(v)) v = JS_NULL; if (js_json_to_str(ctx, jsc, val, v, indent1)) goto exception; @@ -38784,10 +38694,10 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, } string_buffer_putc8(jsc->b, ']'); } else { - if (!JS_IsUndefined(jsc->property_list)) + if (!JS_IsNull(jsc->property_list)) tab = JS_DupValue(ctx, jsc->property_list); else - tab = js_object_keys(ctx, JS_UNDEFINED, 1, (JSValueConst *)&val, JS_ITERATOR_KIND_KEY); + tab = js_object_keys(ctx, JS_NULL, 1, (JSValueConst *)&val, JS_ITERATOR_KIND_KEY); if (JS_IsException(tab)) goto exception; if (js_get_length64(ctx, &len, tab)) @@ -38805,7 +38715,7 @@ static int js_json_to_str(JSContext *ctx, JSONStringifyContext *jsc, v = js_json_check(ctx, jsc, val, v, prop); if (JS_IsException(v)) goto exception; - if (!JS_IsUndefined(v)) { + if (!JS_IsNull(v)) { if (has_content) string_buffer_putc8(jsc->b, ','); prop = JS_ToQuotedStringFree(ctx, prop); @@ -38885,14 +38795,14 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj, int res; int64_t i, j, n; - jsc->replacer_func = JS_UNDEFINED; - jsc->stack = JS_UNDEFINED; - jsc->property_list = JS_UNDEFINED; - jsc->gap = JS_UNDEFINED; + jsc->replacer_func = JS_NULL; + jsc->stack = JS_NULL; + jsc->property_list = JS_NULL; + jsc->gap = JS_NULL; jsc->b = &b_s; jsc->empty = JS_AtomToString(ctx, JS_ATOM_empty_string); - ret = JS_UNDEFINED; - wrapper = JS_UNDEFINED; + ret = JS_NULL; + wrapper = JS_NULL; string_buffer_init(ctx, jsc->b, 0); jsc->stack = JS_NewArray(ctx); @@ -38987,8 +38897,8 @@ JSValue JS_JSONStringify(JSContext *ctx, JSValueConst obj, val = js_json_check(ctx, jsc, wrapper, val, jsc->empty); if (JS_IsException(val)) goto exception; - if (JS_IsUndefined(val)) { - ret = JS_UNDEFINED; + if (JS_IsNull(val)) { + ret = JS_NULL; goto done1; } if (js_json_to_str(ctx, jsc, wrapper, val, jsc->empty)) @@ -39249,7 +39159,7 @@ static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod, if (JS_IsException(method)) return NULL; if (JS_IsNull(method)) - method = JS_UNDEFINED; + method = JS_NULL; *pmethod = method; return s; } @@ -39263,7 +39173,7 @@ static JSValue js_proxy_get_prototype(JSContext *ctx, JSValueConst obj) s = get_proxy_method(ctx, &method, obj, JS_ATOM_getPrototypeOf); if (!s) return JS_EXCEPTION; - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_GetPrototype(ctx, s->target); ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target); if (JS_IsException(ret)) @@ -39307,7 +39217,7 @@ static int js_proxy_set_prototype(JSContext *ctx, JSValueConst obj, s = get_proxy_method(ctx, &method, obj, JS_ATOM_setPrototypeOf); if (!s) return -1; - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_SetPrototypeInternal(ctx, s->target, proto_val, FALSE); args[0] = s->target; args[1] = proto_val; @@ -39344,7 +39254,7 @@ static int js_proxy_is_extensible(JSContext *ctx, JSValueConst obj) s = get_proxy_method(ctx, &method, obj, JS_ATOM_isExtensible); if (!s) return -1; - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_IsExtensible(ctx, s->target); ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target); if (JS_IsException(ret)) @@ -39370,7 +39280,7 @@ static int js_proxy_prevent_extensions(JSContext *ctx, JSValueConst obj) s = get_proxy_method(ctx, &method, obj, JS_ATOM_preventExtensions); if (!s) return -1; - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_PreventExtensions(ctx, s->target); ret = JS_CallFree(ctx, method, s->handler, 1, (JSValueConst *)&s->target); if (JS_IsException(ret)) @@ -39400,7 +39310,7 @@ static int js_proxy_has(JSContext *ctx, JSValueConst obj, JSAtom atom) s = get_proxy_method(ctx, &method, obj, JS_ATOM_has); if (!s) return -1; - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_HasProperty(ctx, s->target, atom); atom_val = JS_AtomToValue(ctx, atom); if (JS_IsException(atom_val)) { @@ -39445,7 +39355,7 @@ static JSValue js_proxy_get(JSContext *ctx, JSValueConst obj, JSAtom atom, if (!s) return JS_EXCEPTION; /* Note: recursion is possible thru the prototype of s->target */ - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_GetPropertyInternal(ctx, s->target, atom, receiver, FALSE); atom_val = JS_AtomToValue(ctx, atom); if (JS_IsException(atom_val)) { @@ -39470,7 +39380,7 @@ static JSValue js_proxy_get(JSContext *ctx, JSValueConst obj, JSAtom atom, goto fail; } } else if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) == JS_PROP_GETSET) { - if (JS_IsUndefined(desc.getter) && !JS_IsUndefined(ret)) { + if (JS_IsNull(desc.getter) && !JS_IsNull(ret)) { fail: js_free_desc(ctx, &desc); JS_FreeValue(ctx, ret); @@ -39493,7 +39403,7 @@ static int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom, s = get_proxy_method(ctx, &method, obj, JS_ATOM_set); if (!s) return -1; - if (JS_IsUndefined(method)) { + if (JS_IsNull(method)) { return JS_SetPropertyInternal(ctx, s->target, atom, JS_DupValue(ctx, value), receiver, flags); @@ -39522,7 +39432,7 @@ static int js_proxy_set(JSContext *ctx, JSValueConst obj, JSAtom atom, if (!js_same_value(ctx, desc.value, value)) { goto fail; } - } else if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) == JS_PROP_GETSET && JS_IsUndefined(desc.setter)) { + } else if ((desc.flags & (JS_PROP_GETSET | JS_PROP_CONFIGURABLE)) == JS_PROP_GETSET && JS_IsNull(desc.setter)) { fail: js_free_desc(ctx, &desc); JS_ThrowTypeError(ctx, "proxy: inconsistent set"); @@ -39592,7 +39502,7 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc if (!s) return -1; p = JS_VALUE_GET_OBJ(s->target); - if (JS_IsUndefined(method)) { + if (JS_IsNull(method)) { return JS_GetOwnPropertyInternal(ctx, pdesc, p, prop); } prop_val = JS_AtomToValue(ctx, prop); @@ -39606,7 +39516,7 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc JS_FreeValue(ctx, prop_val); if (JS_IsException(trap_result_obj)) return -1; - if (!JS_IsObject(trap_result_obj) && !JS_IsUndefined(trap_result_obj)) { + if (!JS_IsObject(trap_result_obj) && !JS_IsNull(trap_result_obj)) { JS_FreeValue(ctx, trap_result_obj); goto fail; } @@ -39617,7 +39527,7 @@ static int js_proxy_get_own_property(JSContext *ctx, JSPropertyDescriptor *pdesc } if (target_desc_ret) js_free_desc(ctx, &target_desc); - if (JS_IsUndefined(trap_result_obj)) { + if (JS_IsNull(trap_result_obj)) { if (target_desc_ret) { if (!(target_desc.flags & JS_PROP_CONFIGURABLE) || !p->extensible) goto fail; @@ -39699,7 +39609,7 @@ static int js_proxy_define_own_property(JSContext *ctx, JSValueConst obj, s = get_proxy_method(ctx, &method, obj, JS_ATOM_defineProperty); if (!s) return -1; - if (JS_IsUndefined(method)) { + if (JS_IsNull(method)) { return JS_DefineProperty(ctx, s->target, prop, val, getter, setter, flags); } prop_val = JS_AtomToValue(ctx, prop); @@ -39791,7 +39701,7 @@ static int js_proxy_delete_property(JSContext *ctx, JSValueConst obj, s = get_proxy_method(ctx, &method, obj, JS_ATOM_deleteProperty); if (!s) return -1; - if (JS_IsUndefined(method)) { + if (JS_IsNull(method)) { return JS_DeleteProperty(ctx, s->target, atom, 0); } atom_val = JS_AtomToValue(ctx, atom);; @@ -39858,7 +39768,7 @@ static int js_proxy_get_own_property_names(JSContext *ctx, s = get_proxy_method(ctx, &method, obj, JS_ATOM_ownKeys); if (!s) return -1; - if (JS_IsUndefined(method)) { + if (JS_IsNull(method)) { return JS_GetOwnPropertyNamesInternal(ctx, ptab, plen, JS_VALUE_GET_OBJ(s->target), JS_GPN_STRING_MASK | JS_GPN_SYMBOL_MASK); @@ -39973,7 +39883,7 @@ static JSValue js_proxy_call_constructor(JSContext *ctx, JSValueConst func_obj, return JS_EXCEPTION; if (!JS_IsConstructor(ctx, s->target)) return JS_ThrowTypeError(ctx, "not a constructor"); - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_CallConstructor2(ctx, s->target, new_target, argc, argv); arg_array = js_create_array(ctx, argc, argv); if (JS_IsException(arg_array)) { @@ -40012,7 +39922,7 @@ static JSValue js_proxy_call(JSContext *ctx, JSValueConst func_obj, JS_FreeValue(ctx, method); return JS_ThrowTypeError(ctx, "not a function"); } - if (JS_IsUndefined(method)) + if (JS_IsNull(method)) return JS_Call(ctx, s->target, this_obj, argc, argv); arg_array = js_create_array(ctx, argc, argv); if (JS_IsException(arg_array)) { @@ -40116,7 +40026,7 @@ static JSValue js_proxy_revoke(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, func_data[0]); func_data[0] = JS_NULL; } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_proxy_revoke_constructor(JSContext *ctx, @@ -40128,9 +40038,9 @@ static JSValue js_proxy_revoke_constructor(JSContext *ctx, static JSValue js_proxy_revocable(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - JSValue proxy_obj, revoke_obj = JS_UNDEFINED, obj; + JSValue proxy_obj, revoke_obj = JS_NULL, obj; - proxy_obj = js_proxy_constructor(ctx, JS_UNDEFINED, argc, argv); + proxy_obj = js_proxy_constructor(ctx, JS_NULL, argc, argv); if (JS_IsException(proxy_obj)) goto fail; revoke_obj = js_proxy_revoke_constructor(ctx, proxy_obj); @@ -40186,9 +40096,9 @@ static JSValue js_symbol_constructor(JSContext *ctx, JSValueConst new_target, JSValue str; JSString *p; - if (!JS_IsUndefined(new_target)) + if (!JS_IsNull(new_target)) return JS_ThrowTypeError(ctx, "not a constructor"); - if (argc == 0 || JS_IsUndefined(argv[0])) { + if (argc == 0 || JS_IsNull(argv[0])) { p = NULL; } else { str = JS_ToString(ctx, argv[0]); @@ -40222,7 +40132,7 @@ static JSValue js_symbol_toString(JSContext *ctx, JSValueConst this_val, if (JS_IsException(val)) return val; /* XXX: use JS_ToStringInternal() with a flags */ - ret = js_string_constructor(ctx, JS_UNDEFINED, 1, (JSValueConst *)&val); + ret = js_string_constructor(ctx, JS_NULL, 1, (JSValueConst *)&val); JS_FreeValue(ctx, val); return ret; } @@ -40243,7 +40153,7 @@ static JSValue js_symbol_get_description(JSContext *ctx, JSValueConst this_val) return val; p = JS_VALUE_GET_PTR(val); if (p->len == 0 && p->is_wide_char != 0) { - ret = JS_UNDEFINED; + ret = JS_NULL; } else { ret = JS_AtomToString(ctx, js_get_atom_index(ctx->rt, p)); } @@ -40280,7 +40190,7 @@ static JSValue js_symbol_keyFor(JSContext *ctx, JSValueConst this_val, return JS_ThrowTypeError(ctx, "not a symbol"); p = JS_VALUE_GET_PTR(argv[0]); if (p->atom_type != JS_ATOM_TYPE_GLOBAL_SYMBOL) - return JS_UNDEFINED; + return JS_NULL; return JS_DupValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); } @@ -40297,7 +40207,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic) { JSMapState *s; - JSValue obj, adder = JS_UNDEFINED, iter = JS_UNDEFINED, next_method = JS_UNDEFINED; + JSValue obj, adder = JS_NULL, iter = JS_NULL, next_method = JS_NULL; JSValueConst arr; BOOL is_set; @@ -40317,10 +40227,10 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target, goto fail; s->record_count_threshold = 4; - arr = JS_UNDEFINED; + arr = JS_NULL; if (argc > 0) arr = argv[0]; - if (!JS_IsUndefined(arr) && !JS_IsNull(arr)) { + if (!JS_IsNull(arr) && !JS_IsNull(arr)) { JSValue item, ret; BOOL done; @@ -40354,8 +40264,8 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target, } else { JSValue key, value; JSValueConst args[2]; - key = JS_UNDEFINED; - value = JS_UNDEFINED; + key = JS_NULL; + value = JS_NULL; if (!JS_IsObject(item)) { JS_ThrowTypeErrorNotAnObject(ctx); goto fail1; @@ -40578,8 +40488,8 @@ static void map_delete_record(JSRuntime *rt, JSMapState *s, JSMapRecord *mr) } else { /* keep a zombie record for iterators */ mr->empty = TRUE; - mr->key = JS_UNDEFINED; - mr->value = JS_UNDEFINED; + mr->key = JS_NULL; + mr->value = JS_NULL; } s->record_count--; } @@ -40605,7 +40515,7 @@ static JSValue js_map_set(JSContext *ctx, JSValueConst this_val, return JS_EXCEPTION; key = map_normalize_key(ctx, argv[0]); if (magic & MAGIC_SET) - value = JS_UNDEFINED; + value = JS_NULL; else value = argv[1]; mr = map_find_record(ctx, s, key); @@ -40632,7 +40542,7 @@ static JSValue js_map_get(JSContext *ctx, JSValueConst this_val, key = map_normalize_key(ctx, argv[0]); mr = map_find_record(ctx, s, key); if (!mr) - return JS_UNDEFINED; + return JS_NULL; else return JS_DupValue(ctx, mr->value); } @@ -40702,7 +40612,7 @@ static JSValue js_map_clear(JSContext *ctx, JSValueConst this_val, mr = list_entry(el, JSMapRecord, link); map_delete_record(ctx->rt, s, mr); } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_map_get_size(JSContext *ctx, JSValueConst this_val, int magic) @@ -40728,7 +40638,7 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val, if (argc > 1) this_arg = argv[1]; else - this_arg = JS_UNDEFINED; + this_arg = JS_NULL; if (check_function(ctx, func)) return JS_EXCEPTION; /* Note: the list can be modified while traversing it, but the @@ -40758,7 +40668,7 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val, el = el->next; } } - return JS_UNDEFINED; + return JS_NULL; } static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, @@ -40779,18 +40689,18 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, if (JS_IsException(iter)) return JS_EXCEPTION; - key = JS_UNDEFINED; + key = JS_NULL; key_atom = JS_ATOM_NULL; - v = JS_UNDEFINED; - prop = JS_UNDEFINED; - groups = JS_UNDEFINED; + v = JS_NULL; + prop = JS_NULL; + groups = JS_NULL; next = JS_GetProperty(ctx, iter, JS_ATOM_next); if (JS_IsException(next)) goto exception; if (is_map) { - groups = js_map_constructor(ctx, JS_UNDEFINED, 0, NULL, 0); + groups = js_map_constructor(ctx, JS_NULL, 0, NULL, 0); } else { groups = JS_NewObjectProto(ctx, JS_NULL); } @@ -40806,7 +40716,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, if (JS_IsException(v)) goto exception; if (done) - break; // v is JS_UNDEFINED + break; // v is JS_NULL args[0] = v; args[1] = JS_NewInt64(ctx, idx); @@ -40819,7 +40729,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, } else { key_atom = JS_ValueToAtom(ctx, key); JS_FreeValue(ctx, key); - key = JS_UNDEFINED; + key = JS_NULL; if (key_atom == JS_ATOM_NULL) goto iterator_close_exception; prop = JS_GetProperty(ctx, groups, key_atom); @@ -40827,7 +40737,7 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, if (JS_IsException(prop)) goto exception; - if (JS_IsUndefined(prop)) { + if (JS_IsNull(prop)) { prop = JS_NewArray(ctx); if (JS_IsException(prop)) goto exception; @@ -40855,10 +40765,10 @@ static JSValue js_object_groupBy(JSContext *ctx, JSValueConst this_val, JS_FreeValue(ctx, key); JS_FreeAtom(ctx, key_atom); JS_FreeValue(ctx, v); - prop = JS_UNDEFINED; - key = JS_UNDEFINED; + prop = JS_NULL; + key = JS_NULL; key_atom = JS_ATOM_NULL; - v = JS_UNDEFINED; + v = JS_NULL; } JS_FreeValue(ctx, iter); @@ -41002,7 +40912,7 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val, *pdone = FALSE; return JS_EXCEPTION; } - if (JS_IsUndefined(it->obj)) + if (JS_IsNull(it->obj)) goto done; s = JS_GetOpaque(it->obj, JS_CLASS_MAP + magic); assert(s != NULL); @@ -41018,11 +40928,11 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValueConst this_val, /* no more record */ it->cur_record = NULL; JS_FreeValue(ctx, it->obj); - it->obj = JS_UNDEFINED; + it->obj = JS_NULL; done: /* end of enumeration */ *pdone = TRUE; - return JS_UNDEFINED; + return JS_NULL; } mr = list_entry(el, JSMapRecord, link); if (!mr->empty) @@ -41436,7 +41346,6 @@ static const JSCFunctionListEntry js_global_funcs[] = { JS_CFUNC_DEF("unescape", 1, js_global_unescape ), JS_PROP_DOUBLE_DEF("Infinity", 1.0 / 0.0, 0 ), JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ), - JS_PROP_UNDEFINED_DEF("undefined", 0 ), JS_PROP_STRING_DEF("[Symbol.toStringTag]", "global", JS_PROP_CONFIGURABLE ), }; @@ -41491,7 +41400,6 @@ static JSValue JS_ToBigIntCtorFree(JSContext *ctx, JSValue val) break; goto redo; case JS_TAG_NULL: - case JS_TAG_UNDEFINED: default: JS_FreeValue(ctx, val); return JS_ThrowTypeError(ctx, "cannot convert to BigInt"); @@ -41503,7 +41411,7 @@ static JSValue js_bigint_constructor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv) { - if (!JS_IsUndefined(new_target)) + if (!JS_IsNull(new_target)) return JS_ThrowTypeError(ctx, "not a constructor"); return JS_ToBigIntCtorFree(ctx, JS_DupValue(ctx, argv[0])); } @@ -41533,7 +41441,7 @@ static JSValue js_bigint_toString(JSContext *ctx, JSValueConst this_val, val = js_thisBigIntValue(ctx, this_val); if (JS_IsException(val)) return val; - if (argc == 0 || JS_IsUndefined(argv[0])) { + if (argc == 0 || JS_IsNull(argv[0])) { base = 10; } else { base = js_get_radix(ctx, argv[0]); @@ -41715,15 +41623,15 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) ctx->throw_type_error = JS_NewCFunction(ctx, js_throw_type_error, NULL, 0); /* add caller and arguments properties to throw a TypeError */ - JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_caller, JS_UNDEFINED, + JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_caller, JS_NULL, ctx->throw_type_error, ctx->throw_type_error, JS_PROP_HAS_GET | JS_PROP_HAS_SET | JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE); - JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_arguments, JS_UNDEFINED, + JS_DefineProperty(ctx, ctx->function_proto, JS_ATOM_arguments, JS_NULL, ctx->throw_type_error, ctx->throw_type_error, JS_PROP_HAS_GET | JS_PROP_HAS_SET | JS_PROP_HAS_CONFIGURABLE | JS_PROP_CONFIGURABLE); - JS_FreeValue(ctx, js_object_seal(ctx, JS_UNDEFINED, 1, (JSValueConst *)&ctx->throw_type_error, 1)); + JS_FreeValue(ctx, js_object_seal(ctx, JS_NULL, 1, (JSValueConst *)&ctx->throw_type_error, 1)); ctx->global_obj = JS_NewObject(ctx); ctx->global_var_obj = JS_NewObjectProto(ctx, JS_NULL); diff --git a/source/quickjs.h b/source/quickjs.h index 54b5518d..2c84b1bd 100644 --- a/source/quickjs.h +++ b/source/quickjs.h @@ -86,7 +86,7 @@ enum { JS_TAG_INT = 0, JS_TAG_BOOL = 1, JS_TAG_NULL = 2, - JS_TAG_UNDEFINED = 3, + // TAG_UNDEFINED JS_TAG_UNINITIALIZED = 4, JS_TAG_CATCH_OFFSET = 5, JS_TAG_EXCEPTION = 6, @@ -285,7 +285,6 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d) /* special values */ #define JS_NULL JS_MKVAL(JS_TAG_NULL, 0) -#define JS_UNDEFINED JS_MKVAL(JS_TAG_UNDEFINED, 0) #define JS_FALSE JS_MKVAL(JS_TAG_BOOL, 0) #define JS_TRUE JS_MKVAL(JS_TAG_BOOL, 1) #define JS_EXCEPTION JS_MKVAL(JS_TAG_EXCEPTION, 0) @@ -624,11 +623,6 @@ static inline JS_BOOL JS_IsNull(JSValueConst v) return JS_VALUE_GET_TAG(v) == JS_TAG_NULL; } -static inline JS_BOOL JS_IsUndefined(JSValueConst v) -{ - return JS_VALUE_GET_TAG(v) == JS_TAG_UNDEFINED; -} - static inline JS_BOOL JS_IsException(JSValueConst v) { return js_unlikely(JS_VALUE_GET_TAG(v) == JS_TAG_EXCEPTION); diff --git a/source/sprite.c b/source/sprite.c index ef0dc961..49937b69 100644 --- a/source/sprite.c +++ b/source/sprite.c @@ -3,7 +3,7 @@ sprite *make_sprite(void) { sprite *sprite = calloc(sizeof(*sprite),1); - sprite->image = JS_UNDEFINED; + sprite->image = JS_NULL; return sprite; } diff --git a/source/transform.c b/source/transform.c index c88e7be2..08f47c8f 100644 --- a/source/transform.c +++ b/source/transform.c @@ -18,8 +18,8 @@ transform *make_transform() { transform *t = malloc(sizeof(transform)); *t = model; - t->jsparent = JS_UNDEFINED; - t->change_hook = JS_UNDEFINED; + t->jsparent = JS_NULL; + t->change_hook = JS_NULL; return t; } @@ -53,7 +53,7 @@ void transform_clean(JSContext *js, transform *t) transform_clean(js, t->children[i]); } - if (!JS_IsUndefined(t->change_hook)) { + if (!JS_IsNull(t->change_hook)) { JSValue ret = JS_Call(js, t->change_hook, JS_DupValue(js,t->self), 0, NULL); JS_FreeValue(js,ret); } diff --git a/tests/blob.ce b/tests/blob.ce index 088c104e..8e26ed99 100644 --- a/tests/blob.ce +++ b/tests/blob.ce @@ -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 == null, "blob.stone should not be available as a method"); }); // Test 16: Invalid constructor arguments diff --git a/tests/comments.ce b/tests/comments.ce index d4a644b4..fe433db7 100644 --- a/tests/comments.ce +++ b/tests/comments.ce @@ -15,7 +15,7 @@ $_.receiver(tree => { var job = parseq.par_all({ comment: load_comment_from_api_requestor(tree.id), - children: cb => parseq.par_all(child_reqs, /*time*/undefined, /*thr*/10)(cb) + children: cb => parseq.par_all(child_reqs, /*time*/null, /*thr*/10)(cb) }) job((result, reason) => { diff --git a/tests/nota.ce b/tests/nota.ce index e5666018..9051c754 100644 --- a/tests/nota.ce +++ b/tests/nota.ce @@ -105,7 +105,7 @@ var testCases = [ { input: -1023, expectedHex: "ef7f" }, // Symbol tests - { input: undefined, expectedHex: "70" }, + { input: null, expectedHex: "70" }, { input: false, expectedHex: "72" }, { input: true, expectedHex: "73" }, diff --git a/tests/num_property_test.ce b/tests/num_property_test.ce index d94879c2..fc95f70d 100644 --- a/tests/num_property_test.ce +++ b/tests/num_property_test.ce @@ -12,7 +12,7 @@ log.console("arr[4] =", arr[4]); arr[0] = 15 log.console(arr[0]) -log.console("arr[10] =", arr[10]); // Should be undefined +log.console("arr[10] =", arr[10]); // Should be null log.console("arr.length =", arr.length); diff --git a/tests/qr_drag.ce b/tests/qr_drag.ce index bbef5ca8..02448638 100644 --- a/tests/qr_drag.ce +++ b/tests/qr_drag.ce @@ -18,7 +18,7 @@ var camera = { fov:50, near_z: 0, far_z: 1000, - surface: undefined, + surface: null, viewport: {x:0,y:0,width:1,height:1}, ortho:true, anchor:[0,0], @@ -82,7 +82,7 @@ var qr_rect_gutter = { width: qr_rect.width + gutter*2, height: qr_rect.height + gutter*2 } -blit_img.cpu.blit(qr_rect, bsurf, undefined, "nearest") +blit_img.cpu.blit(qr_rect, bsurf, null, "nearest") graphics.save_png("blit.png", blit_img.cpu.width, blit_img.cpu.height, blit_img.cpu.pixels(), blit_img.cpu.pitch) @@ -122,11 +122,11 @@ function parse_data(res) function extract_qr_surface(surface) { var qr = graphics.make_surface([qr_rect_gutter.width, qr_rect_gutter.height]) - qr.blit(undefined, surface, qr_rect_gutter) + qr.blit(null, surface, qr_rect_gutter) return qr } -var display = undefined +var display = null $_.receiver(e => { if (e.type == 'quit') diff --git a/tests/test_actor_access.ce b/tests/test_actor_access.ce index 92db5efb..85228d1f 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 $_ != 'null') { 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 f309ff0e..4eddf891 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 $_ != 'null') { 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 62958de7..be0ea6c3 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 $_ != 'null') { log.error("✗ Module incorrectly has access to $_!"); return "ERROR: Module has $_ access"; } else { diff --git a/tests/text.ce b/tests/text.ce index b6114b6c..886811b8 100644 --- a/tests/text.ce +++ b/tests/text.ce @@ -117,19 +117,19 @@ var str = "miskatonic" var substr_tests = [ {from: 0, to: 3, expected: "mis"}, {from: 3, to: 6, expected: "kat"}, - {from: 5, to: undefined, expected: "tonic"}, + {from: 5, to: null, expected: "tonic"}, {from: 0, to: -4, expected: "miskat"}, - {from: -3, to: undefined, expected: "nic"}, + {from: -3, to: null, expected: "nic"}, {from: 0, to: 0, expected: ""}, - {from: 10, to: undefined, expected: ""}, - {from: 11, to: undefined, expected: null}, + {from: 10, to: null, expected: ""}, + {from: 11, to: null, expected: null}, {from: 2, to: 1, expected: null} ] 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 + var result = test.to == null ? text(str, test.from) : text(str, test.from, test.to) + var args = test.to == null ? 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)) diff --git a/tests/unneeded.ce b/tests/unneeded.ce index c463bf9f..264b00ee 100644 --- a/tests/unneeded.ce +++ b/tests/unneeded.ce @@ -1,4 +1,4 @@ $_.unneeded(_ => { log.console("Unneded function fired."); - $_.start(undefined, "unneeded") + $_.start(null, "unneeded") }, 1); diff --git a/tests/wota.ce b/tests/wota.ce index ad47d01c..cdc2289a 100644 --- a/tests/wota.ce +++ b/tests/wota.ce @@ -124,7 +124,7 @@ var testCases = [ { input: Math.pow(2, 55) - 1, expectedHex: 'e0ffffffffffffff' }, { input: -Math.pow(2, 55), expectedHex: 'e000000000000000' }, - { input: undefined, expectedHex: '70' }, + { input: null, expectedHex: '70' }, { input: false, expectedHex: '72' }, { input: true, expectedHex: '73' }, @@ -189,7 +189,7 @@ for (var t of testCases) { } 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 != null ? t.expected : t.input var cmp = deep_compare(exp, dec) if (!cmp.passed) { passed = false; msgs.push(...cmp.messages) }