remove isa

This commit is contained in:
2026-01-06 11:17:07 -06:00
parent 63cf76dcf9
commit dd309b1a37
10 changed files with 43 additions and 78 deletions

View File

@@ -88,7 +88,7 @@ function print_config(obj, prefix = '') {
var val = obj[key] var val = obj[key]
var full_key = prefix ? prefix + '.' + key : key var full_key = prefix ? prefix + '.' + key : key
if (isa(val, object)) if (is_object(val))
print_config(val, full_key) print_config(val, full_key)
else else
log.console(full_key + ' = ' + format_value(val)) log.console(full_key + ' = ' + format_value(val))

View File

@@ -230,10 +230,10 @@ var json = use('json')
Check type or prototype chain. Check type or prototype chain.
```javascript ```javascript
isa(42, number) // true is_number(42) // true
isa("hi", text) // true is_text("hi") // true
isa([1,2], array) // true is_array([1,2]) // true
isa({}, object) // true is_object({}) // true
isa(child, parent) // true if parent is in prototype chain isa(child, parent) // true if parent is in prototype chain
``` ```

View File

@@ -10,7 +10,7 @@ var match_id = 0;
$portal(e => { $portal(e => {
log.console("NAT server: received connection request"); 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."}); send(e, {reason: "Must provide the actor you want to connect."});
if (waiting_client) { if (waiting_client) {

View File

@@ -92,43 +92,8 @@ var actor_mod = use_core('actor')
var wota = use_core('wota') var wota = use_core('wota')
var nota = use_core('nota') var nota = use_core('nota')
globalThis.isa = function(value, master) { globalThis.is_actor = function(value) {
if (master == null) return false return is_object(value) && value[ACTORDATA]
// 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
} }
var ENETSERVICE = 0.1 var ENETSERVICE = 0.1
@@ -240,7 +205,7 @@ $_.time_limit = function(requestor, seconds)
{ {
if (!pronto.is_requestor(requestor)) if (!pronto.is_requestor(requestor))
throw new Error('time_limit: first argument must be a 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'); throw new Error('time_limit: seconds must be a positive number');
return function time_limit_requestor(callback, value) { return function time_limit_requestor(callback, value) {
@@ -436,7 +401,7 @@ function handle_host(e) {
data.replycc[ACTORDATA].port = e.peer.port data.replycc[ACTORDATA].port = e.peer.port
} }
function populate_actor_addresses(obj) { function populate_actor_addresses(obj) {
if (!isa(obj, object)) return if (!is_object(obj)) return
if (obj[ACTORDATA] && !obj[ACTORDATA].address) { if (obj[ACTORDATA] && !obj[ACTORDATA].address) {
obj[ACTORDATA].address = e.peer.address obj[ACTORDATA].address = e.peer.address
obj[ACTORDATA].port = e.peer.port obj[ACTORDATA].port = e.peer.port
@@ -485,7 +450,7 @@ $_.stop = function stop(actor) {
need_stop = true need_stop = true
return return
} }
if (!isa(actor, actor)) if (!is_actor(actor))
throw new Error('Can only call stop on an actor.') throw new Error('Can only call stop on an actor.')
if (!underlings.has(actor[ACTORDATA].id)) if (!underlings.has(actor[ACTORDATA].id))
throw new Error('Can only call stop on an underling or self.') 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 if (actor[HEADER] && !actor[HEADER].replycc) // attempting to respond to a message but sender is not expecting; silently drop
return 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.') 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) { if (actor[HEADER] && actor[HEADER].replycc) {
var header = actor[HEADER] 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]}`) throw new Error(`Supplied actor had a return, but it's not a valid actor! ${actor[HEADER]}`)
actor = header.replycc actor = header.replycc

View File

@@ -338,7 +338,7 @@ Shop.extract_commit_hash = function(pkg, response) {
var data = json.decode(response) var data = json.decode(response)
if (info == 'gitea') { if (info == 'gitea') {
if (isa(data, array)) if (is_array(data))
data = data[0] data = data[0]
return data.commit && data.commit.id return data.commit && data.commit.id
} }

View File

@@ -418,9 +418,9 @@ function handle_actor_message(msg) {
var duration_ns = number.round((end_time - base_entry.start_time) * 1000000000) var duration_ns = number.round((end_time - base_entry.start_time) * 1000000000)
var results = [] var results = []
if (isa(msg, array)) { if (is_array(msg)) {
results = msg results = msg
} else if (msg && isa(msg.results, array)) { } else if (msg && is_array(msg.results)) {
results = msg.results results = msg.results
} else { } else {
results = [msg] results = [msg]

View File

@@ -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) stone_if_needed(expected); stone_if_needed(actual)
if (expected.length != actual.length) if (expected.length != actual.length)
return { passed: false, messages: [`blob length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } 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: [] } return { passed: true, messages: [] }
} }
if (isa(expected, array) && isa(actual, array)) { if (is_array(expected) && is_array(actual)) {
if (expected.length != actual.length) if (expected.length != actual.length)
return { return {
passed: false, passed: false,
@@ -64,7 +64,7 @@ function deepCompare(expected, actual, path) {
return { passed: messages.length == 0, messages: messages }; 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 expKeys = array(expected).sort();
var actKeys = array(actual).sort(); var actKeys = array(actual).sort();
if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) if (JSON.stringify(expKeys) != JSON.stringify(actKeys))
@@ -91,7 +91,7 @@ function deepCompare(expected, actual, path) {
function makeTest(test) { function makeTest(test) {
return function() { return function() {
var encoded = test.replacer ? nota.encode(test.input, test.replacer) : nota.encode(test.input); 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"; throw "encode() should return blob";
} }

View File

@@ -1018,38 +1018,38 @@ return {
// ============================================================================ // ============================================================================
test_isa_number: function() { test_isa_number: function() {
if (!isa(42, number)) throw "isa number failed" if (!is_number(42)) throw "isa number failed"
if (isa("42", number)) throw "isa string not number failed" if (is_number("42")) throw "isa string not number failed"
}, },
test_isa_text: function() { test_isa_text: function() {
if (!isa("hello", text)) throw "isa text failed" if (!is_text("hello")) throw "isa text failed"
if (isa(123, text)) throw "isa number not text failed" if (is_text(123)) throw "isa number not text failed"
}, },
test_isa_logical: function() { test_isa_logical: function() {
if (!isa(true, logical)) throw "isa true failed" if (!is_logical(true)) throw "isa true failed"
if (!isa(false, logical)) throw "isa false failed" if (!is_logical(false)) throw "isa false failed"
if (isa(1, logical)) throw "isa number not logical failed" if (is_logical(1)) throw "isa number not logical failed"
}, },
test_isa_array: function() { test_isa_array: function() {
if (!isa([], array)) throw "isa empty array failed" if (!is_array([], array)) throw "isa empty array failed"
if (!isa([1,2,3], array)) throw "isa array failed" if (!is_array([1,2,3], array)) throw "isa array failed"
if (isa({}, array)) throw "isa object not array failed" if (is_array({}, array)) throw "isa object not array failed"
}, },
test_isa_object: function() { test_isa_object: function() {
if (!isa({}, object)) throw "isa empty object failed" if (!is_object({}, object)) throw "isa empty object failed"
if (!isa({a:1}, object)) throw "isa object failed" if (!is_object({a:1}, object)) throw "isa object failed"
if (isa([], object)) throw "isa array not object failed" if (is_object([], object)) throw "isa array not object failed"
if (isa(null, object)) throw "isa null not object failed" if (is_object(null, object)) throw "isa null not object failed"
}, },
test_isa_null: function() { test_isa_null: function() {
if (isa(null, number)) throw "null not number" if (is_null(null)) throw "null not number"
if (isa(null, text)) throw "null not text" if (is_null(text)) throw "null not text"
if (isa(null, object)) throw "null not object" if (is_null(object)) throw "null not object"
}, },
// ============================================================================ // ============================================================================

View File

@@ -30,7 +30,7 @@ function deep_compare(expected, actual, path) {
return { passed: true, messages: [] } return { passed: true, messages: [] }
} }
if (isa(expected, array) && isa(actual, array)) { if (is_array(expected) && is_array(actual)) {
if (expected.length != actual.length) if (expected.length != actual.length)
return { passed: false, messages: [`Array length mismatch at ${path}: ${expected.length} vs ${actual.length}`] } return { passed: false, messages: [`Array length mismatch at ${path}: ${expected.length} vs ${actual.length}`] }
var msgs = [] var msgs = []
@@ -43,7 +43,7 @@ function deep_compare(expected, actual, path) {
return { passed: msgs.length == 0, messages: msgs } 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 expKeys = array(expected).sort()
var actKeys = array(actual).sort() var actKeys = array(actual).sort()
if (JSON.stringify(expKeys) != JSON.stringify(actKeys)) if (JSON.stringify(expKeys) != JSON.stringify(actKeys))

View File

@@ -51,7 +51,7 @@ function parse_toml(text) {
} else if (value == 'true' || value == 'false') { } else if (value == 'true' || value == 'false') {
// Boolean // Boolean
current_section[key] = value == 'true' current_section[key] = value == 'true'
} else if (isa(value, number)) { } else if (is_number(value)) {
// Number // Number
current_section[key] = Number(value) current_section[key] = Number(value)
} else { } else {
@@ -147,7 +147,7 @@ function encode_toml(obj) {
return value ? 'true' : 'false' return value ? 'true' : 'false'
} else if (is_number(value)) { } else if (is_number(value)) {
return text(value) return text(value)
} else if (isa(value, array)) { } else if (is_array(value)) {
var items = [] var items = []
for (var i = 0; i < value.length; i++) { for (var i = 0; i < value.length; i++) {
items.push(encode_value(value[i])) items.push(encode_value(value[i]))
@@ -169,7 +169,7 @@ function encode_toml(obj) {
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
var key = keys[i] var key = keys[i]
var value = obj[key] var value = obj[key]
if (!isa(value, object)) { if (!is_object(value)) {
result.push(quote_key(key) + ' = ' + encode_value(value)) result.push(quote_key(key) + ' = ' + encode_value(value))
} }
} }
@@ -182,7 +182,7 @@ function encode_toml(obj) {
var key = keys[i] var key = keys[i]
var value = obj[key] var value = obj[key]
if (isa(value, object)) { if (is_object(value)) {
// Nested object - create section // Nested object - create section
// We MUST quote the key segment if it has dots, otherwise it becomes a nested table path // We MUST quote the key segment if it has dots, otherwise it becomes a nested table path
var quoted = quote_key(key) var quoted = quote_key(key)