blob: 74fd70905844acf3a5e2a20e7dcb9d46712c804b (
plain) (
blame)
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
|
{.push raises: [].}
import quickjs
type
JSPropertyEnumArray* = ptr UncheckedArray[JSPropertyEnum]
JSPropertyEnumList* = object
buffer*: JSPropertyEnumArray
size: uint32
len*: uint32
ctx: JSContext
JSPropertyEnumWrapper* = object
is_enumerable: bool
name: string
func newJSPropertyEnumList*(ctx: JSContext; size: uint32): JSPropertyEnumList =
let p = if size != 0:
js_malloc(ctx, csize_t(sizeof(JSPropertyEnum)) * csize_t(size))
else:
nil
return JSPropertyEnumList(
ctx: ctx,
buffer: cast[JSPropertyEnumArray](p),
size: size
)
proc grow(this: var JSPropertyEnumList) =
if this.size == 0:
this.size = 1
this.size *= 2
let p = js_realloc(this.ctx, this.buffer,
csize_t(sizeof(JSPropertyEnum)) * csize_t(this.size))
this.buffer = cast[JSPropertyEnumArray](p)
proc add*(this: var JSPropertyEnumList; val: uint32) =
let i = this.len
inc this.len
if this.size < this.len:
this.grow()
this.buffer[i].atom = JS_NewAtomUInt32(this.ctx, val)
proc add*(this: var JSPropertyEnumList; val: string) =
let i = this.len
inc this.len
if this.size < this.len:
this.grow()
this.buffer[i].atom = JS_NewAtomLen(this.ctx, cstring(val), csize_t(val.len))
{.pop.} # raises
|