From dd309b1a37ff64f51e0df942383e7c9d009f1154 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 6 Jan 2026 11:17:07 -0600 Subject: [PATCH] remove isa --- config.ce | 2 +- docs/cellscript.md | 8 ++++---- examples/nat.ce | 2 +- internal/engine.cm | 49 +++++++--------------------------------------- internal/shop.cm | 2 +- test.ce | 4 ++-- tests/nota.cm | 8 ++++---- tests/suite.cm | 34 ++++++++++++++++---------------- tests/wota.cm | 4 ++-- toml.cm | 8 ++++---- 10 files changed, 43 insertions(+), 78 deletions(-) diff --git a/config.ce b/config.ce index 9526e9cc..101b8fe4 100644 --- a/config.ce +++ b/config.ce @@ -88,7 +88,7 @@ function print_config(obj, prefix = '') { var val = obj[key] var full_key = prefix ? prefix + '.' + key : key - if (isa(val, object)) + if (is_object(val)) print_config(val, full_key) else log.console(full_key + ' = ' + format_value(val)) diff --git a/docs/cellscript.md b/docs/cellscript.md index c60d4e00..0db62e19 100644 --- a/docs/cellscript.md +++ b/docs/cellscript.md @@ -230,10 +230,10 @@ var json = use('json') Check type or prototype chain. ```javascript -isa(42, number) // true -isa("hi", text) // true -isa([1,2], array) // true -isa({}, object) // true +is_number(42) // true +is_text("hi") // true +is_array([1,2]) // true +is_object({}) // true isa(child, parent) // true if parent is in prototype chain ``` diff --git a/examples/nat.ce b/examples/nat.ce index 3595f9b7..ce9f262e 100644 --- a/examples/nat.ce +++ b/examples/nat.ce @@ -10,7 +10,7 @@ var match_id = 0; $portal(e => { log.console("NAT server: received connection request"); - if (!isa(e.actor, actor)) + if (!is_actor(e.actor)) send(e, {reason: "Must provide the actor you want to connect."}); if (waiting_client) { diff --git a/internal/engine.cm b/internal/engine.cm index e9591c45..d5ef4522 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -92,43 +92,8 @@ var actor_mod = use_core('actor') var wota = use_core('wota') var nota = use_core('nota') -globalThis.isa = function(value, master) { - if (master == null) return false - - // isa(value, function) - check if function.prototype is in chain - if (is_function(master)) { - // Special type checks - if (master == stone) return is_stone(value) - if (master == number) return is_number(value) - if (master == text) return is_text(value) - if (master == logical) return is_logical(value) - if (master == array) return is_array(value) - if (master == object) return is_object(value) - if (master == fn) return is_function(value) - if (master == actor) return is_object(value) && value[ACTORDATA] - - // Check prototype chain - if (master.prototype) { - var proto = _getPrototypeOf(value) - while (proto != null) { - if (proto == master.prototype) return true - proto = _getPrototypeOf(proto) - } - } - return false - } - - // isa(object, master_object) - check prototype chain - if (is_object(master)) { - var proto = _getPrototypeOf(value) - while (proto != null) { - if (proto == master) return true - proto = _getPrototypeOf(proto) - } - return false - } - - return false +globalThis.is_actor = function(value) { + return is_object(value) && value[ACTORDATA] } var ENETSERVICE = 0.1 @@ -240,7 +205,7 @@ $_.time_limit = function(requestor, seconds) { if (!pronto.is_requestor(requestor)) throw new Error('time_limit: first argument must be a requestor'); - if (!isa(seconds, number) || seconds <= 0) + if (!is_number(seconds) || seconds <= 0) throw new Error('time_limit: seconds must be a positive number'); return function time_limit_requestor(callback, value) { @@ -436,7 +401,7 @@ function handle_host(e) { data.replycc[ACTORDATA].port = e.peer.port } function populate_actor_addresses(obj) { - if (!isa(obj, object)) return + if (!is_object(obj)) return if (obj[ACTORDATA] && !obj[ACTORDATA].address) { obj[ACTORDATA].address = e.peer.address obj[ACTORDATA].port = e.peer.port @@ -485,7 +450,7 @@ $_.stop = function stop(actor) { need_stop = true return } - if (!isa(actor, actor)) + if (!is_actor(actor)) throw new Error('Can only call stop on an actor.') if (!underlings.has(actor[ACTORDATA].id)) throw new Error('Can only call stop on an underling or self.') @@ -541,7 +506,7 @@ function actor_send(actor, message) { if (actor[HEADER] && !actor[HEADER].replycc) // attempting to respond to a message but sender is not expecting; silently drop return - if (!isa(actor, actor) && !isa(actor.replycc, actor)) throw new Error(`Must send to an actor object. Attempted send to ${actor}`) + if (!is_actor(actor) && !is_actor(actor.replycc)) throw new Error(`Must send to an actor object. Attempted send to ${actor}`) if (!is_object(message)) throw new Error('Must send an object record.') @@ -620,7 +585,7 @@ globalThis.send = function send(actor, message, reply) { if (actor[HEADER] && actor[HEADER].replycc) { var header = actor[HEADER] - if (!header.replycc || !isa(header.replycc, actor)) + if (!header.replycc || !is_actor(header.replycc)) throw new Error(`Supplied actor had a return, but it's not a valid actor! ${actor[HEADER]}`) actor = header.replycc diff --git a/internal/shop.cm b/internal/shop.cm index 1aff5ad6..d81dea01 100644 --- a/internal/shop.cm +++ b/internal/shop.cm @@ -338,7 +338,7 @@ Shop.extract_commit_hash = function(pkg, response) { var data = json.decode(response) if (info == 'gitea') { - if (isa(data, array)) + if (is_array(data)) data = data[0] return data.commit && data.commit.id } diff --git a/test.ce b/test.ce index 99b2fbec..298a93fa 100644 --- a/test.ce +++ b/test.ce @@ -418,9 +418,9 @@ function handle_actor_message(msg) { var duration_ns = number.round((end_time - base_entry.start_time) * 1000000000) var results = [] - if (isa(msg, array)) { + if (is_array(msg)) { results = msg - } else if (msg && isa(msg.results, array)) { + } else if (msg && is_array(msg.results)) { results = msg.results } else { results = [msg] diff --git a/tests/nota.cm b/tests/nota.cm index 51da14a0..a70a19d5 100644 --- a/tests/nota.cm +++ b/tests/nota.cm @@ -37,7 +37,7 @@ function deepCompare(expected, actual, path) { }; } - if ((expected instanceof blob) && (actual instanceof blob)) { + if (is_blob(expected) && is_blob(actual)) { stone_if_needed(expected); stone_if_needed(actual) if (expected.length != actual.length) return { passed: false, messages: [`blob length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } @@ -48,7 +48,7 @@ function deepCompare(expected, actual, path) { return { passed: true, messages: [] } } - if (isa(expected, array) && isa(actual, array)) { + if (is_array(expected) && is_array(actual)) { if (expected.length != actual.length) return { passed: false, @@ -64,7 +64,7 @@ function deepCompare(expected, actual, path) { return { passed: messages.length == 0, messages: messages }; } - if (isa(expected, object) && isa(actual, object)) { + if (is_object(expected) && is_object(actual)) { var expKeys = array(expected).sort(); var actKeys = array(actual).sort(); if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) @@ -91,7 +91,7 @@ function deepCompare(expected, actual, path) { function makeTest(test) { return function() { var encoded = test.replacer ? nota.encode(test.input, test.replacer) : nota.encode(test.input); - if (!(encoded instanceof blob)){ + if (!is_blob(encoded)){ throw "encode() should return blob"; } diff --git a/tests/suite.cm b/tests/suite.cm index 124357f2..960760ea 100644 --- a/tests/suite.cm +++ b/tests/suite.cm @@ -1018,38 +1018,38 @@ return { // ============================================================================ test_isa_number: function() { - if (!isa(42, number)) throw "isa number failed" - if (isa("42", number)) throw "isa string not number failed" + if (!is_number(42)) throw "isa number failed" + if (is_number("42")) throw "isa string not number failed" }, test_isa_text: function() { - if (!isa("hello", text)) throw "isa text failed" - if (isa(123, text)) throw "isa number not text failed" + if (!is_text("hello")) throw "isa text failed" + if (is_text(123)) throw "isa number not text failed" }, test_isa_logical: function() { - if (!isa(true, logical)) throw "isa true failed" - if (!isa(false, logical)) throw "isa false failed" - if (isa(1, logical)) throw "isa number not logical failed" + if (!is_logical(true)) throw "isa true failed" + if (!is_logical(false)) throw "isa false failed" + if (is_logical(1)) throw "isa number not logical failed" }, test_isa_array: function() { - if (!isa([], array)) throw "isa empty array failed" - if (!isa([1,2,3], array)) throw "isa array failed" - if (isa({}, array)) throw "isa object not array failed" + if (!is_array([], array)) throw "isa empty array failed" + if (!is_array([1,2,3], array)) throw "isa array failed" + if (is_array({}, array)) throw "isa object not array failed" }, test_isa_object: function() { - if (!isa({}, object)) throw "isa empty object failed" - if (!isa({a:1}, object)) throw "isa object failed" - if (isa([], object)) throw "isa array not object failed" - if (isa(null, object)) throw "isa null not object failed" + if (!is_object({}, object)) throw "isa empty object failed" + if (!is_object({a:1}, object)) throw "isa object failed" + if (is_object([], object)) throw "isa array not object failed" + if (is_object(null, object)) throw "isa null not object failed" }, test_isa_null: function() { - if (isa(null, number)) throw "null not number" - if (isa(null, text)) throw "null not text" - if (isa(null, object)) throw "null not object" + if (is_null(null)) throw "null not number" + if (is_null(text)) throw "null not text" + if (is_null(object)) throw "null not object" }, // ============================================================================ diff --git a/tests/wota.cm b/tests/wota.cm index 62b1893d..9fcf239b 100644 --- a/tests/wota.cm +++ b/tests/wota.cm @@ -30,7 +30,7 @@ function deep_compare(expected, actual, path) { return { passed: true, messages: [] } } - if (isa(expected, array) && isa(actual, array)) { + if (is_array(expected) && is_array(actual)) { if (expected.length != actual.length) return { passed: false, messages: [`Array length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } var msgs = [] @@ -43,7 +43,7 @@ function deep_compare(expected, actual, path) { return { passed: msgs.length == 0, messages: msgs } } - if (isa(expected, object) && isa(actual, object)) { + if (is_object(expected) && is_object(actual)) { var expKeys = array(expected).sort() var actKeys = array(actual).sort() if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) diff --git a/toml.cm b/toml.cm index 4b1469d1..eb5e9960 100644 --- a/toml.cm +++ b/toml.cm @@ -51,7 +51,7 @@ function parse_toml(text) { } else if (value == 'true' || value == 'false') { // Boolean current_section[key] = value == 'true' - } else if (isa(value, number)) { + } else if (is_number(value)) { // Number current_section[key] = Number(value) } else { @@ -147,7 +147,7 @@ function encode_toml(obj) { return value ? 'true' : 'false' } else if (is_number(value)) { return text(value) - } else if (isa(value, array)) { + } else if (is_array(value)) { var items = [] for (var i = 0; i < value.length; i++) { items.push(encode_value(value[i])) @@ -169,7 +169,7 @@ function encode_toml(obj) { for (var i = 0; i < keys.length; i++) { var key = keys[i] var value = obj[key] - if (!isa(value, object)) { + if (!is_object(value)) { result.push(quote_key(key) + ' = ' + encode_value(value)) } } @@ -182,7 +182,7 @@ function encode_toml(obj) { var key = keys[i] var value = obj[key] - if (isa(value, object)) { + if (is_object(value)) { // Nested object - create section // We MUST quote the key segment if it has dots, otherwise it becomes a nested table path var quoted = quote_key(key)