ahk 0.6.1

The ahk language: a lexer, an AST, a parser and an interpreter for AutoHotkey-style scripts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
//! The `Buffer` class.
//!
//! A buffer is a block of memory. It is the one class of the runtime
//! that is not text.
//!
//! v2.0.19 gives a buffer three things: a size, an address, and a
//! constructor -- and nothing else. The reads and the writes of bytes
//! belong to the file, which reads into a buffer and writes out of one.
//! This dialect keeps the bytes of the buffer in the runtime, because
//! that is where a file reads them.
//!
//! The `NumGet` and the `NumPut` of v2 read a number out of a buffer
//! and write one into it. The bytes they touch are the bytes of the
//! buffer, so the module that owns them is the one that reads and
//! writes them.
//!
//! The bytes live in the property table of the object, under one key,
//! so that the module owns the whole of the state of a buffer.
use alloc::collections::BTreeMap;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;

use crate::classes::enumerator;
use crate::classes::object_with;
use crate::dll::NativeType;
use crate::runtime::{
    Detail, Object, Runtime, RuntimeError, RuntimeFailure, SharedCell, TypeName, Value, expected_type, put,
};

/// The key the state of a buffer lives under.
///
/// The key has a space in it, so that a script cannot reach the inside
/// of a buffer by name.
const STATE: &str = "buffer state";

/// The class of the object that carries the state of a buffer.
const STATE_CLASS: &str = "buffer-state";

/// The properties of a buffer.
const PROPERTIES: [&str; 2] = ["size", "ptr"];

/// The methods of a buffer: the constructor, and the ones every object
/// has.
const METHODS: [&str; 10] = [
    "__new",
    "ownprops",
    "hasownprop",
    "defineprop",
    "deleteprop",
    "getownpropdesc",
    "hasprop",
    "hasmethod",
    "getmethod",
    "hasbase",
];

/// The state of a buffer: the bytes.
struct Buffer {
    bytes: Vec<u8>,
}

pub(crate) fn names() -> Vec<&'static str> {
    PROPERTIES.iter().chain(METHODS.iter()).copied().collect()
}

pub(crate) fn construct(
    arguments: &[Value],
    _rt: &mut Runtime,
    line: u32,
) -> Result<Value, RuntimeFailure> {
    let buffer = new(arguments, line)?;
    Ok(object_with("buffer", vec![(STATE, stored(&buffer))]))
}

/// A buffer of the bytes of a file.
///
/// The `FileRead` answers with a buffer when the script asks for the raw
/// bytes of the file.
pub(crate) fn of_bytes(bytes: Vec<u8>) -> Value {
    object_with("buffer", vec![(STATE, stored(&Buffer { bytes }))])
}

/// A method of a `Buffer`.
///
/// `None` means the method is not one of this class's: the runtime then
/// says the value has no such method.
pub(crate) fn call(
    method: &str,
    this: &Value,
    arguments: &[Value],
    rt: &mut Runtime,
    line: u32,
) -> Option<Result<Value, RuntimeFailure>> {
    let method = method.to_lowercase();
    match method.as_str() {
        "__new" => Some(new(arguments, line).map(|buffer| {
            restore(this, &buffer);
            Value::Int(buffer.bytes.len() as i64)
        })),
        // The methods of the base object are answered here too: the
        // runtime knows nothing of the class types of the runtime.
        _ => base_method(&method, this, arguments, rt, line),
    }
}

/// A property of a `Buffer`.
///
/// `None` means the name is not a property of this class: the runtime
/// then looks in the property table of the object.
pub(crate) fn property(
    name: &str,
    this: &Value,
    rt: &mut Runtime,
    line: u32,
) -> Option<Result<Value, RuntimeFailure>> {
    match name.to_lowercase().as_str() {
        "size" => Some(state(this, line).map(|buffer| Value::Int(buffer.bytes.len() as i64))),
        "ptr" => Some(match ptr_of(this, line) {
            Ok(address) => {
                // `StrGet` and `StrPut` are given this address back, so the
                // runtime remembers which buffer it names.
                rt.remember_a_buffer_at(address, this.clone());
                Ok(Value::Int(address))
            }
            Err(failure) => Err(failure),
        }),
        _ => None,
    }
}

/// A property of a `Buffer` that is written.
///
/// `None` means the class does not own the name: the runtime then
/// writes it in the property table of the object.
pub(crate) fn set_property(
    name: &str,
    this: &Value,
    value: Value,
    _rt: &mut Runtime,
    line: u32,
) -> Option<Result<(), RuntimeFailure>> {
    match name.to_lowercase().as_str() {
        "size" => Some(resize(this, value, line)),
        _ => None,
    }
}

/// The bytes of another buffer, for the class that writes into one.
pub(crate) fn raw_bytes(value: &Value, line: u32) -> Result<Vec<u8>, RuntimeFailure> {
    match value {
        Value::Object(_) => Ok(state(value, line)?.bytes),
        Value::Text(text) => Ok(text.as_bytes().to_vec()),
        other => Err(fail(
            expected_type(TypeName::Object, other.type_name()),
            line,
        )),
    }
}

/// Put the bytes into a buffer.
///
/// The `File` class fills a buffer, so the module that owns a buffer
/// is the one that writes into it. The bytes go to the start of the
/// buffer: a buffer has no position of its own.
pub(crate) fn fill(value: &Value, bytes: &[u8], line: u32) -> Result<usize, RuntimeFailure> {
    write_at(value, 0, bytes, line)?;
    Ok(bytes.len())
}

/// How many bytes a buffer has.
pub(crate) fn size_of(value: &Value, line: u32) -> Result<i64, RuntimeFailure> {
    Ok(state(value, line)?.bytes.len() as i64)
}

/// The address of the memory of the buffer.
///
/// The bytes of a buffer live in the object of the script, and the
/// machine reads and writes a mirror of them: the address is the one of
/// the mirror, a real block of the heap, and it changes when the buffer
/// is made of another size, as v2 says of a buffer that is reallocated.
pub(crate) fn ptr_of(this: &Value, line: u32) -> Result<i64, RuntimeFailure> {
    if !matches!(this, Value::Object(_)) {
        return Err(fail("this value is not a buffer.", line));
    }
    #[cfg(feature = "std")]
    {
        let bytes = state(this, line)?.bytes;
        Ok(crate::memory::the_address_of_a_buffer(this, &bytes))
    }
    #[cfg(not(feature = "std"))]
    {
        let Value::Object(object) = this else {
            return Err(fail("this value is not a buffer.", line));
        };
        let inner = match object.borrow().value_of(STATE) {
            Some(Value::Object(inner)) => inner.clone(),
            _ => return Err(fail("this value is not a buffer.", line)),
        };
        Ok(SharedCell::as_ptr(&inner) as usize as i64)
    }
}

/// Give an object the zero-filled bytes of a struct of the v2.1, reusing
/// the state of a buffer so the reads, the writes and the address of it
/// are the ones this module already owns.
pub(crate) fn allocate(this: &Value, size: usize) {
    restore(this, &Buffer { bytes: vec![0u8; size] });
}

/// Read the bytes the machine left in the mirrors back into the objects
/// of the buffers: a `DllCall` writes into the machine memory, and
/// `NumGet` reads the object, so the two are made one again after the
/// call comes back.
#[cfg(feature = "std")]
pub(crate) fn the_buffers_are_read_back() {
    for (owner, bytes) in crate::memory::the_mirrors_are_read() {
        if let Value::Object(object) = &owner {
            let buffer = Buffer { bytes };
            put(&mut object.borrow_mut().properties, STATE, stored(&buffer));
        }
    }
}

/// The type of a number, out of the name the script writes.
///
/// The types of a number are the types of a native call, and the tree
/// keeps them in one table: `NumGet` and `NumPut` name them the way
/// `DllCall` does.
pub(crate) fn number_type(text: &str) -> Option<NativeType> {
    match text.trim().to_ascii_lowercase().as_str() {
        "uint" => Some(NativeType::UInt),
        "int" => Some(NativeType::Int),
        "int64" => Some(NativeType::Int64),
        "short" => Some(NativeType::Short),
        "ushort" => Some(NativeType::UShort),
        "char" => Some(NativeType::Char),
        "uchar" => Some(NativeType::UChar),
        "double" => Some(NativeType::Double),
        "float" => Some(NativeType::Float),
        "ptr" => Some(NativeType::Ptr),
        "uptr" => Some(NativeType::UPtr),
        _ => None,
    }
}

/// The number of a buffer, at an offset.
///
/// The type of the number says how wide it is, and the bytes of a
/// buffer are read here because this module owns them.
pub(crate) fn read_number(
    value: &Value,
    offset: i64,
    kind: NativeType,
    line: u32,
) -> Result<Value, RuntimeFailure> {
    let buffer = state(value, line)?;
    let start = start_of(offset, line)?;
    let end = start.saturating_add(kind.width());
    if end > buffer.bytes.len() {
        return Err(fail("the bytes do not fit in the buffer.", line));
    }
    Ok(number_from_bytes(&buffer.bytes[start..end], kind))
}

/// Put the numbers into a buffer, at an offset.
///
/// The numbers go out one after the other, the way v2 writes them, and
/// the answer is the address to the right of the last one of them.
pub(crate) fn write_numbers(
    value: &Value,
    offset: i64,
    numbers: &[(NativeType, Value)],
    line: u32,
) -> Result<i64, RuntimeFailure> {
    let mut bytes = Vec::new();
    for (kind, number) in numbers {
        bytes.extend_from_slice(&number_bytes(number, *kind));
    }
    write_at(value, offset, &bytes, line)?;
    // The answer of v2 is the address to the right of the last number:
    // the address of the buffer and the offset it stopped at.
    Ok(ptr_of(value, line)? + offset + bytes.len() as i64)
}

// -- the state ------------------------------------------------------------------

/// The failure of a buffer, with the line the script was on.
fn fail(message: impl Into<String>, line: u32) -> RuntimeFailure {
    RuntimeFailure::Error(RuntimeError {
        message: message.into(),
        line,
    })
}

/// The whole number an argument holds.
///
/// A float is truncated, the way AutoHotkey truncates it. A value that is
/// not a number is refused the way v2 refuses it, and the value that was
/// given goes in the `Extra` of the error.
fn whole(value: &Value, line: u32) -> Result<i64, RuntimeFailure> {
    match value {
        Value::Int(number) => Ok(*number),
        Value::Float(number) => Ok(*number as i64),
        other => Err(RuntimeFailure::Detailed(
            RuntimeError {
                message: expected_type(TypeName::Number, other.type_name()),
                line,
            },
            Detail {
                what: String::new(),
                extra: other.to_text(),
            },
        )),
    }
}

/// The whole number an argument of the constructor holds.
///
/// v2 names the constructor in the message, and the number of the
/// parameter is the number of the argument the script wrote.
fn whole_argument(value: &Value, index: usize, line: u32) -> Result<i64, RuntimeFailure> {
    match value {
        Value::Int(number) => Ok(*number),
        Value::Float(number) => Ok(*number as i64),
        other => Err(RuntimeFailure::Detailed(
            RuntimeError {
                message: crate::runtime::requires(
                    index + 1,
                    "Buffer.Prototype.__New",
                    TypeName::Number,
                    other,
                ),
                line,
            },
            Detail {
                what: "Buffer.Prototype.__New".to_string(),
                extra: other.to_text(),
            },
        )),
    }
}

/// The state of a buffer, as the object holds it.
fn state(this: &Value, line: u32) -> Result<Buffer, RuntimeFailure> {
    let Value::Object(object) = this else {
        return Err(fail("this value is not a buffer.", line));
    };
    let inner = match object.borrow().value_of(STATE) {
        Some(Value::Object(inner)) => inner.clone(),
        _ => return Err(fail("this value is not a buffer.", line)),
    };
    let inner = inner.borrow();
    let bytes = match inner.value_of("bytes") {
        Some(Value::List(items)) => items
            .iter()
            .map(|item| item.to_number().unwrap_or(0.0) as u8)
            .collect(),
        _ => Vec::new(),
    };
    Ok(Buffer { bytes })
}

/// The state of a buffer, as the property table holds it.
fn stored(buffer: &Buffer) -> Value {
    let bytes = Value::List(
        buffer
            .bytes
            .iter()
            .map(|byte| Value::Int(*byte as i64))
            .collect(),
    );
    object_with(STATE_CLASS, vec![("bytes", bytes)])
}

/// Put the state back into the object.
fn restore(this: &Value, buffer: &Buffer) {
    let Value::Object(object) = this else { return };
    put(&mut object.borrow_mut().properties, STATE, stored(buffer));
    // The machine copy of the buffer, when it has one, is kept current
    // with the object: a `DllCall` that comes later reads the new bytes.
    #[cfg(feature = "std")]
    crate::memory::the_mirror_is_updated(this, &buffer.bytes);
}

/// A new buffer: the bytes, and the position at the start of them.
fn new(arguments: &[Value], line: u32) -> Result<Buffer, RuntimeFailure> {
    let size = match arguments.first() {
        Some(value) => whole_argument(value, 0, line)?,
        None => 0,
    };
    if size < 0 {
        return Err(fail("Invalid value.", line));
    }
    // The bytes of a new buffer are zero, unless the script asks for
    // another byte to fill them with.
    //
    // Measured on the binary of v2.0.19: the fill is the byte
    // of the number, and a number that is not a byte is not refused: the
    // byte of it is the fill.
    let fill = match arguments.get(1) {
        Some(value) => whole_argument(value, 1, line)? as u8,
        None => 0,
    };
    Ok(Buffer {
        bytes: vec![fill; size as usize],
    })
}

/// Make the buffer of another size, the way v2 does: the bytes that
/// stay are kept, and the bytes that come are zero.
fn resize(this: &Value, value: Value, line: u32) -> Result<(), RuntimeFailure> {
    let size = whole(&value, line)?;
    if size < 0 {
        return Err(fail("the size of a buffer cannot be negative.", line));
    }
    let mut buffer = state(this, line)?;
    buffer.bytes.resize(size as usize, 0);
    restore(this, &buffer);
    Ok(())
}

/// Put the bytes into a buffer, at an offset.
///
/// The write of a number belongs to the module that owns the buffer,
/// the same way the read does.
fn write_at(value: &Value, offset: i64, bytes: &[u8], line: u32) -> Result<(), RuntimeFailure> {
    let mut buffer = state(value, line)?;
    let start = start_of(offset, line)?;
    let end = start.saturating_add(bytes.len());
    if end > buffer.bytes.len() {
        return Err(fail("the bytes do not fit in the buffer.", line));
    }
    buffer.bytes[start..end].copy_from_slice(bytes);
    restore(value, &buffer);
    Ok(())
}

/// The place in the bytes of a buffer that an offset names.
fn start_of(offset: i64, line: u32) -> Result<usize, RuntimeFailure> {
    if offset < 0 {
        return Err(fail("the offset of a number cannot be negative.", line));
    }
    match usize::try_from(offset) {
        Ok(start) => Ok(start),
        Err(_) => Err(fail("the bytes do not fit in the buffer.", line)),
    }
}

/// The bytes of a number, in the width its type asks for.
///
/// The numbers go out little-endian, the way the machines of x86 read
/// them, and a whole number is cut to the width of its type.
pub(crate) fn number_bytes(number: &Value, kind: NativeType) -> Vec<u8> {
    let mut bytes = Vec::with_capacity(kind.width());
    match kind {
        NativeType::Float => {
            bytes.extend_from_slice(&(number.to_number().unwrap_or(0.0) as f32).to_le_bytes())
        }
        NativeType::Double => {
            bytes.extend_from_slice(&number.to_number().unwrap_or(0.0).to_le_bytes())
        }
        _ => {
            let whole = match number {
                Value::Int(number) => *number,
                other => other.to_number().unwrap_or(0.0) as i64,
            };
            match kind.width() {
                1 => bytes.push(whole as u8),
                2 => bytes.extend_from_slice(&(whole as u16).to_le_bytes()),
                4 => bytes.extend_from_slice(&(whole as u32).to_le_bytes()),
                _ => bytes.extend_from_slice(&whole.to_le_bytes()),
            }
        }
    }
    bytes
}

/// The number of the bytes, read in the width its type asks for.
///
/// The bytes come in little-endian, the way they went out, and the type
/// says whether the number is signed: the sign is in the last byte of
/// the width.
pub(crate) fn number_from_bytes(bytes: &[u8], kind: NativeType) -> Value {
    match kind {
        NativeType::Float => {
            Value::Float(f32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) as f64)
        }
        NativeType::Double => {
            let mut whole = [0u8; 8];
            whole.copy_from_slice(&bytes[..8]);
            Value::Float(f64::from_le_bytes(whole))
        }
        _ => {
            let mut whole = 0i64;
            // The bytes come in little-endian, and the last byte of them
            // is the first of the number.
            for byte in bytes.iter().take(kind.width()).rev() {
                whole = (whole << 8) | *byte as i64;
            }
            let bits = kind.width() * 8;
            if bits < 64 && !kind.is_unsigned() {
                let sign = 1i64 << (bits - 1);
                if whole & sign != 0 {
                    whole -= sign << 1;
                }
            }
            Value::Int(whole)
        }
    }
}

// -- the base object ----------------------------------------------------------

/// The methods of the base object, answered for a buffer.
///
/// The runtime answers them for the classes of the script, and it knows
/// nothing of the class types of the runtime: a buffer has no method of
/// the script, and the bytes of a buffer are not a property of it.
fn base_method(
    method: &str,
    this: &Value,
    arguments: &[Value],
    rt: &mut Runtime,
    line: u32,
) -> Option<Result<Value, RuntimeFailure>> {
    let Value::Object(object) = this else {
        return None;
    };
    let failure = |message: &str| {
        Some(Err(RuntimeFailure::Error(RuntimeError {
            message: message.to_string(),
            line,
        })))
    };
    let name = arguments
        .first()
        .map(|value| value.to_text())
        .unwrap_or_default();
    let key = name.to_lowercase();
    match method {
        "ownprops" => {
            // Measured on the binary of v2.0.19: the own
            // properties of v2 are an enumerator, and it gives the name
            // when the caller wants one value.
            let pairs: Vec<(Value, Value)> = object
                .borrow()
                .properties
                .iter()
                .filter(|(name, _)| name.as_str() != STATE)
                .map(|(_, property)| (Value::Text(property.name.clone()), property.value.clone()))
                .collect();
            Some(Ok(enumerator::make(pairs, enumerator::Alone::TheKey)))
        }
        "hasownprop" => Some(Ok(Value::Int(own_property(object, &key) as i64))),
        "hasprop" => Some(Ok(Value::Int(
            (PROPERTIES.contains(&key.as_str())
                // The methods of the class are the properties of the value.
                //
                // Measured on the binary of v2.0.19:
                // `m.HasProp("Get")` answers 1.
                || METHODS.contains(&key.as_str())
                || own_property(object, &key)
                // Every value carries its class, and the base object has
                // the property of it.
                || key == "__class"
                // Every class has an initialiser, and every object has a
                // base.
                //
                // Measured on the binary of v2.0.19:
                // `m.HasProp("__Init")` and `m.HasProp("Base")` answer 1.
                || key == "__init"
                || key == "base") as i64,
        ))),
        "hasmethod" => Some(Ok(Value::Int(
            (METHODS.contains(&key.as_str())
                // Every class has an initialiser.
                //
                // Measured on the binary of v2.0.19:
                // `m.HasMethod("__Init")` answers 1.
                || key == "__init") as i64,
        ))),
        "getownpropdesc" => {
            let name = arguments
                .first()
                .map(|value| value.to_text())
                .unwrap_or_default();
            let value = object.borrow().value_of(&key);
            match value {
                Some(value) => {
                    // Measured on the binary of v2.0.19: the
                    // descriptor that comes back is an object with the
                    // members of it.
                    let table = match rt.the_members_of_a_descriptor(&value) {
                        Some(members) => members,
                        None => {
                            let mut table = BTreeMap::new();
                            put(&mut table, "value", value);
                            table
                        }
                    };
                    Some(Ok(Value::Object(SharedCell::new(Object {
                        class: "object".to_string(),
                        properties: table,
                    }))))
                }
                // The property is not there: v2 says so.
                None => Some(Err(rt.no_property(this, &name, line))),
            }
        }
        "defineprop" => {
            if key == STATE {
                return failure("the state of a buffer is not a property of it.");
            }
            // Measured on the binary of v2.0.19: the second
            // parameter is a descriptor, and a value that is not one is
            // refused with the reason.
            let descriptor = match rt.the_descriptor(arguments.get(1), line) {
                Ok(descriptor) => descriptor,
                Err(failure) => return Some(Err(failure)),
            };
            put(&mut object.borrow_mut().properties, &name, descriptor);
            // The answer of v2 is the object itself.
            Some(Ok(this.clone()))
        }
        "deleteprop" => {
            if key == STATE {
                return Some(Ok(Value::Text(String::new())));
            }
            let gone = object
                .borrow_mut()
                .properties
                .remove(&key)
                .map(|property| property.value);
            // Measured on the binary of v2.0.19: the answer
            // is the value of the property that is taken away, and an
            // empty text when there was none.
            Some(Ok(match gone {
                None => Value::Text(String::new()),
                Some(value) => match rt.the_value_of_the_descriptor(&value, this, &name, line) {
                    Ok(Some(value)) => value,
                    _ => value,
                },
            }))
        }
        _ => None,
    }
}

/// Whether the buffer has a property of that name.
///
/// The state of the buffer is not a property of it: it is the inside of
/// the buffer, and the script never wrote it.
fn own_property(object: &SharedCell<Object>, key: &str) -> bool {
    key != STATE && object.borrow().properties.contains_key(key)
}