summary refs log tree commit diff stats
path: root/go.mod
Commit message (Collapse)AuthorAgeFilesLines
* Reinitialize project and change module urlAndinus2020-03-241-3/+1
|
* Add notify functionality to cetusAndinus2020-03-231-0/+2
|
* Initialize programAndinus2020-03-111-0/+3
il.com> 2024-04-16 15:08:44 +0200 committer bptato <nincsnevem662@gmail.com> 2024-04-17 23:19:09 +0200 Update code style' href='/ahoang/chawan/commit/src/js/propertyenumlist.nim?id=66b9574b165be62e76c7397cf0eaa8d229d42675'>66b9574b ^
98865ac7 ^





66b9574b ^
98865ac7 ^




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














                                                           
                                                                               












                                                                         
                                                      





                                                       
                                                      




                                                                               
import bindings/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 = js_malloc(ctx, csize_t(sizeof(JSPropertyEnum)) * csize_t(size))
  let buffer = cast[JSPropertyEnumArray](p)
  return JSPropertyEnumList(
    ctx: ctx,
    buffer: buffer,
    size: size
  )

proc grow(this: var JSPropertyEnumList) =
  this.size *= 2
  let p = js_realloc(this.ctx, this.buffer, 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))