CCF
Loading...
Searching...
No Matches
wrapped_property_enum.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
7
8#include <quickjs/quickjs.h>
9
10namespace ccf::js::core
11{
13 {
14 public:
15 JSWrappedPropertyEnum(JSContext* ctx_, const JSWrappedValue& value) :
16 ctx(ctx_)
17 {
18 if (!value.is_obj())
19 {
20 throw std::logic_error(
21 fmt::format("object value required for property enum"));
22 }
23
24 if (
25 JS_GetOwnPropertyNames(
26 ctx,
27 &prop_enum,
29 value.val,
30 JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) == -1)
31 {
32 throw std::logic_error(
33 fmt::format("Could not extract property names of enum"));
34 }
35 }
36
38 {
39 for (uint32_t i = 0; i < prop_count; i++)
40 {
41 JS_FreeAtom(ctx, prop_enum[i].atom);
42 }
43 js_free(ctx, prop_enum);
44 };
45
46 JSAtom& operator[](size_t i) const
47 {
48 return prop_enum[i].atom;
49 }
50
51 size_t size() const
52 {
53 return prop_count;
54 }
55
56 JSPropertyEnum* prop_enum = nullptr;
57 uint32_t prop_count = 0;
58 JSContext* ctx = nullptr;
59 };
60}
Definition wrapped_property_enum.h:13
JSAtom & operator[](size_t i) const
Definition wrapped_property_enum.h:46
JSPropertyEnum * prop_enum
Definition wrapped_property_enum.h:56
size_t size() const
Definition wrapped_property_enum.h:51
~JSWrappedPropertyEnum()
Definition wrapped_property_enum.h:37
JSContext * ctx
Definition wrapped_property_enum.h:58
uint32_t prop_count
Definition wrapped_property_enum.h:57
JSWrappedPropertyEnum(JSContext *ctx_, const JSWrappedValue &value)
Definition wrapped_property_enum.h:15
Definition constants.h:8
Definition wrapped_value.h:13
bool is_obj() const
Definition wrapped_value.cpp:166
JSValue val
Definition wrapped_value.h:15