remove isa
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
4
test.ce
4
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]
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -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))
|
||||
|
||||
8
toml.cm
8
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)
|
||||
|
||||
Reference in New Issue
Block a user