-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquickjsbind.h
More file actions
732 lines (629 loc) · 27 KB
/
quickjsbind.h
File metadata and controls
732 lines (629 loc) · 27 KB
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
#ifndef QUICKJS_BIND_H // !QUIKJS_BIND_H
#define QUICKJS_BIND_H
#include <quickjs/quickjs.h>
#include <string>
#include <vector>
#ifdef QUICKJSBIND_ENABLE_EXCEPTIONS
#define QTRY try
#define QCATCH(code) catch (const std::exception &e) code
#else
#define QTRY
#define QCATCH(code)
#endif // QUICKJSBIND_ENABLE_EXCEPTIONS
namespace quickjs
{
namespace Detail
{
template <typename... any_t>
struct Value
{
};
template <typename... any_t>
struct JSTypeTraits
{
};
template <>
struct JSTypeTraits<JSValue>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept { return value; }
};
template <>
struct JSTypeTraits<JSContext *>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, JSContext *) noexcept { return JS_UNDEFINED; }
static JSContext *Cast(JSContext *context, int argc, JSValue *args, JSValue) noexcept { return context; }
};
template <>
struct JSTypeTraits<std::nullptr_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, void *) noexcept { return JS_NULL; }
static void *Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept { return nullptr; }
};
template <>
struct JSTypeTraits<bool>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, bool value) noexcept { return JS_NewBool(context, value); }
static bool Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept { return JS_ToBool(context, value); }
};
template <>
struct JSTypeTraits<int8_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, int8_t value) noexcept { return JS_NewInt32(context, value); }
static int8_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int result = 0;
JS_ToInt32(context, &result, value);
return static_cast<int8_t>(result);
}
};
template <>
struct JSTypeTraits<uint8_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, uint8_t value) noexcept { return JS_NewInt32(context, value); }
static uint8_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int result = 0;
JS_ToInt32(context, &result, value);
return static_cast<uint8_t>(result);
}
};
template <>
struct JSTypeTraits<int16_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, int16_t value) noexcept { return JS_NewInt32(context, value); }
static int16_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int result = 0;
JS_ToInt32(context, &result, value);
return static_cast<int16_t>(result);
}
};
template <>
struct JSTypeTraits<uint16_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, uint16_t value) noexcept { return JS_NewInt32(context, value); }
static uint16_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int result = 0;
JS_ToInt32(context, &result, value);
return static_cast<uint16_t>(result);
}
};
template <>
struct JSTypeTraits<int32_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, int32_t value) noexcept { return JS_NewInt32(context, value); }
static int32_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int32_t result = 0;
JS_ToInt32(context, &result, value);
return result;
}
};
template <>
struct JSTypeTraits<uint32_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, uint32_t value) noexcept { return JS_NewUint32(context, value); }
static uint32_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
uint32_t result = 0;
JS_ToUint32(context, &result, value);
return result;
}
};
template <>
struct JSTypeTraits<int64_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, int64_t value) noexcept { return JS_NewInt64(context, value); }
static int64_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int64_t result = 0;
JS_ToInt64(context, &result, value);
return result;
}
};
template <>
struct JSTypeTraits<uint64_t>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, uint64_t value) noexcept { return JS_NewInt64(context, value); }
static uint64_t Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
int64_t result = 0;
JS_ToInt64(context, &result, value);
return static_cast<uint64_t>(result);
}
};
template <>
struct JSTypeTraits<float>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, float value) noexcept { return JS_NewFloat64(context, value); }
static float Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
double result = 0.0;
JS_ToFloat64(context, &result, value);
return static_cast<float>(result);
}
};
template <>
struct JSTypeTraits<double>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, double value) noexcept { return JS_NewFloat64(context, value); }
static double Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
double result = 0.0;
JS_ToFloat64(context, &result, value);
return result;
}
};
template <>
struct JSTypeTraits<std::string>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, std::string value) noexcept { return JS_NewStringLen(context, value.data(), value.length()); }
static std::string Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
size_t length = 0;
const char *data = JS_ToCStringLen(context, &length, value);
std::string result{data, length};
JS_FreeCString(context, data);
return result;
}
};
template <>
struct JSTypeTraits<void *>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, void *value) noexcept
{
auto object = JS_NewObject(context);
JS_SetOpaque(object, value);
return object;
}
static void *Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
return JS_GetOpaque(value, 1); // JS_CLASS_OBJECT
}
};
template <typename element_t>
struct JSTypeTraits<std::vector<element_t>>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, const std::vector<element_t> &value) noexcept
{
auto array = JS_NewArray(context);
for (size_t i = 0; i < value.size(); ++i)
JS_SetPropertyUint32(context, array, static_cast<uint32_t>(i), JSTypeTraits<element_t>::Cast(context, argc, args, value[i]));
return array;
}
static std::vector<element_t> Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
if (!JS_IsArray(context, value))
return {};
auto lengthValue = JS_GetPropertyStr(context, value, "length");
auto length = JSTypeTraits<size_t>::Cast(context, argc, args, lengthValue);
JS_FreeValue(context, lengthValue);
std::vector<element_t> result(length, 0);
for (size_t i = 0; i < length; ++i)
{
auto elementValue = JS_GetPropertyUint32(context, value, static_cast<uint32_t>(i));
result.push_back(JSTypeTraits<element_t>::Cast(context, argc, args, elementValue));
JS_FreeValue(context, elementValue);
}
return result;
}
};
template <typename any_t>
struct JSTypeTraits<Value<any_t>>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, Value<any_t> value) noexcept { return JSTypeTraits<any_t>::Cast(context, argc, args, value.value); }
static Value<any_t> Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept { return {context, JSTypeTraits<any_t>::Cast(context, argc, args, value)}; }
};
template <typename any_t>
struct Value<any_t>
{
JSContext *context;
any_t value;
};
template <>
struct Value<JSValue>
{
JSContext *context;
JSValue value;
template <typename any_t>
any_t Cast() const
{
return JSTypeTraits<any_t>::Cast(context, 0, nullptr, value);
}
bool IsNull() const
{
return JS_IsNull(value);
}
bool IsBoolean() const
{
return JS_IsBool(value);
}
bool IsNumber() const
{
return JS_IsNumber(value);
}
bool IsString() const
{
return JS_IsString(value);
}
bool IsObject() const
{
return JS_IsObject(value);
}
bool IsArray() const
{
return JS_IsArray(context, value);
}
bool IsFunction() const
{
return JS_IsFunction(context, value);
}
bool IsUndefined() const
{
return JS_IsUndefined(value);
}
operator void *() const
{
return Cast<void *>();
}
};
template <auto functionPointer>
struct FunctionInfoPacker
{
};
template <typename method_t, method_t methodPointer>
struct MethodInfoPacker
{
};
template <typename field_t, field_t fieldPointer>
struct FieldInfoPacker
{
};
template <typename... any_t>
struct JSFunctionCaster
{
};
template <typename... any_t>
struct JSMethodCaster
{
};
template <typename... any_t>
struct JSFieldCaster
{
};
template <typename tuple_t, size_t... i>
constexpr auto JSArgsTupleImpl(JSContext *context, int argc, JSValue *args, std::index_sequence<i...>) noexcept
{
return tuple_t{JSTypeTraits<std::tuple_element_t<i, tuple_t>>::Cast(context, argc, args, args[i])...};
}
template <typename... params_t>
constexpr auto JSArgsTuple(JSContext *context, int argc, JSValue *args)
{
return JSArgsTupleImpl<std::tuple<std::decay_t<params_t>...>>(context, argc, args, std::make_index_sequence<sizeof...(params_t)>{});
}
template <typename return_t, typename... params_t, return_t (*runnable)(params_t...)>
struct JSFunctionCaster<FunctionInfoPacker<runnable>>
{
static constexpr JSValue Cast(JSContext *context) noexcept
{
return JS_NewCFunction(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv)
{
QTRY
{
if constexpr (std::is_same_v<void, return_t>)
{
std::apply(runnable, JSArgsTuple<params_t...>(context, argc, argv));
return JS_UNDEFINED;
}
else
return JSTypeTraits<return_t>::Cast(context, argc, argv, std::apply(runnable, JSArgsTuple<params_t...>(context, argc, argv)));
}
QCATCH({
return JS_ThrowInternalError(context, "%s", e.what());
})
},
nullptr,
0);
}
};
template <typename class_t, typename return_t, typename... params_t, return_t (class_t::*runnable)(params_t...)>
struct JSMethodCaster<MethodInfoPacker<return_t (class_t::*)(params_t...), runnable>>
{
static constexpr JSValue Cast(JSContext *context) noexcept
{
return JS_NewCFunction(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv)
{
auto object = JS_GetOpaque(this_val, 1); // JS_CLASS_OBJECT
if (nullptr == object)
return JS_ThrowInternalError(context, "Call invalid object");
QTRY
{
if constexpr (std::is_same_v<void, return_t>)
{
std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv)));
return JS_UNDEFINED;
}
else
return JSTypeTraits<return_t>::Cast(context, argc, argv, std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv))));
}
QCATCH({
return JS_ThrowInternalError(context, "%s", e.what());
})
},
nullptr,
0);
}
};
template <typename class_t, typename return_t, typename... params_t, return_t (class_t::*runnable)(params_t...) const>
struct JSMethodCaster<MethodInfoPacker<return_t (class_t::*)(params_t...) const, runnable>>
{
static constexpr JSValue Cast(JSContext *context) noexcept
{
return JS_NewCFunction(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv)
{
auto object = JS_GetOpaque(this_val, 1); // JS_CLASS_OBJECT
if (nullptr == object)
return JS_ThrowInternalError(context, "Call invalid object");
QTRY
{
if constexpr (std::is_same_v<void, return_t>)
{
std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv)));
return JS_UNDEFINED;
}
else
return JSTypeTraits<return_t>::Cast(context, argc, argv, std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv))));
}
QCATCH({
return JS_ThrowInternalError(context, "%s", e.what());
})
},
nullptr,
0);
}
};
template <typename class_t, typename return_t, typename... params_t, return_t (*runnable)(class_t *, params_t...)>
struct JSMethodCaster<MethodInfoPacker<return_t (*)(class_t *, params_t...), runnable>>
{
static constexpr JSValue Cast(JSContext *context) noexcept
{
return JS_NewCFunction(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv)
{
auto object = JS_GetOpaque(this_val, 1); // JS_CLASS_OBJECT
if (nullptr == object)
return JS_ThrowInternalError(context, "Call invalid object");
QTRY
{
if constexpr (std::is_same_v<void, return_t>)
{
std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv)));
return JS_UNDEFINED;
}
else
return JSTypeTraits<return_t>::Cast(context, argc, argv, std::apply(runnable, std::tuple_cat(std::make_tuple(reinterpret_cast<class_t *>(object)), JSArgsTuple<params_t...>(context, argc, argv))));
}
QCATCH({
return JS_ThrowInternalError(context, "%s", e.what());
})
},
nullptr,
0);
}
};
template <typename value_t, typename class_t, value_t class_t::*field>
struct JSFieldCaster<FieldInfoPacker<value_t class_t::*, field>>
{
static constexpr std::pair<JSValue, JSValue> Cast(JSContext *context) noexcept
{
union PointerCaster
{
void *normal;
value_t class_t::*member;
};
auto dataPointerValue = JS_NewObject(context);
JS_SetOpaque(dataPointerValue, PointerCaster{.member = field}.normal);
auto getter = JS_NewCFunctionData(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) -> JSValue
{
auto object = reinterpret_cast<class_t *>(JS_GetOpaque(this_val, 1)); // JS_CLASS_OBJECT
if (nullptr == object)
return JS_ThrowInternalError(context, "Invalid object");
auto dataPointer = PointerCaster{.normal = JS_GetOpaque(func_data[0], 1)}.member; // JS_CLASS_OBJECT
return JSTypeTraits<value_t>::Cast(context, argc, argv, object->*dataPointer);
},
0, 0,
1, reinterpret_cast<JSValue *>(&dataPointerValue));
auto setter = JS_NewCFunctionData(
context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) -> JSValue
{
auto object = reinterpret_cast<class_t *>(JS_GetOpaque(this_val, 1)); // JS_CLASS_OBJECT
if (nullptr == object)
return JS_ThrowInternalError(context, "Invalid object");
auto dataPointer = PointerCaster{.normal = JS_GetOpaque(func_data[0], 1)}.member; // JS_CLASS_OBJECT
object->*dataPointer = JSTypeTraits<value_t>::Cast(context, argc, argv, argv[0]);
return JS_UNDEFINED;
},
0, 0,
1, reinterpret_cast<JSValue *>(&dataPointerValue));
JS_FreeValue(context, dataPointerValue);
return {getter, setter};
}
};
class JSObject
{
public:
static JSObject GetGlobal(JSContext *context)
{
JSObject result(context, true);
result.m_object = JS_GetGlobalObject(context);
return result;
}
public:
JSObject(JSContext *context, void *bindToObject)
: m_context(context)
{
m_object = JS_NewObject(context);
if (nullptr != bindToObject)
JS_SetOpaque(m_object, bindToObject);
}
JSObject(JSContext *context) : JSObject(context, nullptr) {}
JSObject(JSObject &) = delete;
JSObject(JSObject &&other)
: m_context(other.m_context),
m_object(other.m_object),
m_needDestroy(other.m_needDestroy)
{
other.m_needDestroy = false;
}
~JSObject()
{
if (m_needDestroy)
JS_FreeValue(m_context, m_object);
}
JSObject &Append(JSValue value)
{
JS_SetPropertyInt64(m_context, m_object, m_arrayIndex++, value);
return *this;
}
JSObject &AddObject(const char *name, JSValue object)
{
JS_SetPropertyStr(m_context, m_object, name, object);
return *this;
}
template <auto runnable>
constexpr JSObject &AddFunction(const char *name)
{
JS_SetPropertyStr(m_context, m_object, name, Detail::JSFunctionCaster<Detail::FunctionInfoPacker<runnable>>::Cast(m_context));
return *this;
}
template <typename pointer_t>
constexpr JSObject &AddProperty(const char *name, pointer_t *dataPointer)
{
auto nameAtom = JS_NewAtom(m_context, name);
auto dataPointerValue = JS_NewObject(m_context);
JS_SetOpaque(dataPointerValue, dataPointer);
auto getter = JS_NewCFunctionData(
m_context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) -> JSValue
{
auto dataPointer = reinterpret_cast<pointer_t *>(JS_GetOpaque(func_data[0], 1)); // JS_CLASS_OBJECT
return JSTypeTraits<pointer_t>::Cast(context, argc, argv, *dataPointer);
},
0, 0,
1, reinterpret_cast<JSValue *>(&dataPointerValue));
auto setter = JS_NewCFunctionData(
m_context,
[](JSContext *context, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) -> JSValue
{
auto dataPointer = reinterpret_cast<pointer_t *>(JS_GetOpaque(func_data[0], 1)); // JS_CLASS_OBJECT
*dataPointer = JSTypeTraits<pointer_t>::Cast(context, argc, argv, argv[0]);
return JS_UNDEFINED;
},
0, 0,
1, reinterpret_cast<JSValue *>(&dataPointerValue));
JS_DefinePropertyGetSet(m_context, m_object, nameAtom, getter, setter, JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE);
JS_FreeValue(m_context, dataPointerValue);
JS_FreeAtom(m_context, nameAtom);
return *this;
}
template <auto runnable>
constexpr JSObject &AddMethod(const char *name)
{
JS_SetPropertyStr(m_context, m_object, name, Detail::JSMethodCaster<Detail::MethodInfoPacker<decltype(runnable), runnable>>::Cast(m_context));
return *this;
}
template <auto field>
constexpr JSObject &AddField(const char *name)
{
auto nameAtom = JS_NewAtom(m_context, name);
auto [getter, setter] = JSFieldCaster<Detail::FieldInfoPacker<decltype(field), field>>::Cast(m_context);
JS_DefinePropertyGetSet(m_context, m_object, nameAtom, getter, setter, 0);
JS_FreeAtom(m_context, nameAtom);
return *this;
}
template <typename any_t>
JSObject &SetProperty(const char *name, any_t value)
{
JS_SetPropertyStr(m_context, m_object, name, Detail::JSTypeTraits<any_t>::Cast(m_context, 0, nullptr, value));
return *this;
}
template <typename any_t>
JSObject &SetProperty(size_t index, any_t value)
{
JS_SetPropertyInt64(m_context, m_object, index, Detail::JSTypeTraits<any_t>::Cast(m_context, 0, nullptr, value));
return *this;
}
operator JSValue() const
{
return m_object;
}
private:
JSObject(JSContext *context, bool m_needDestroy)
: m_context(context),
m_needDestroy(m_needDestroy)
{
}
private:
JSContext *m_context;
JSValue m_object;
bool m_needDestroy = false;
size_t m_arrayIndex = 0;
};
class JSArguments
{
public:
JSArguments(JSContext *context, int argc, JSValue *argv)
: m_context(context),
m_argc(argc),
m_argv(argv)
{
}
Value<JSValue> operator[](size_t index) const
{
return {m_context, m_argv[index]};
}
size_t Size() const
{
return m_argc;
}
operator JSContext *() const
{
return m_context;
}
private:
JSContext *m_context;
int m_argc;
JSValue *m_argv;
};
template <>
struct JSTypeTraits<JSArguments>
{
static JSValue Cast(JSContext *context, int argc, JSValue *args, JSArguments value) noexcept
{
return JS_UNDEFINED;
}
static JSArguments Cast(JSContext *context, int argc, JSValue *args, JSValue value) noexcept
{
return {context, argc, args};
}
};
}
template <typename value_t>
using Value = Detail::Value<value_t>;
using Object = Detail::JSObject;
using Args = Detail::JSArguments;
}
#undef QTRY
#undef QCATCH
#endif // !QUIKJS_BIND_H