Skip to content

Commit a3d6bbd

Browse files
committed
feat: duktape uses native dom
1 parent a45679c commit a3d6bbd

File tree

2 files changed

+88
-333
lines changed

2 files changed

+88
-333
lines changed

include/mrdox/Support/JavaScript.hpp

+11-101
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class Prop
7474

7575
/** A reference to an instance of a JavaScript interpreter.
7676
*/
77-
class Context
77+
class MRDOX_DECL
78+
Context
7879
{
7980
struct Impl;
8081

@@ -89,15 +90,15 @@ class Context
8990

9091
/** Destructor.
9192
*/
92-
MRDOX_DECL ~Context();
93+
~Context();
9394

9495
/** Constructor.
9596
*/
96-
MRDOX_DECL Context();
97+
Context();
9798

9899
/** Constructor.
99100
*/
100-
MRDOX_DECL Context(Context const&) noexcept;
101+
Context(Context const&) noexcept;
101102
};
102103

103104
//------------------------------------------------
@@ -140,95 +141,6 @@ class Scope
140141

141142
//------------------------------------------------
142143

143-
/** A bound value which can be passed to JavaScript.
144-
145-
Objects of this type are used as parameter
146-
types in signatures of C++ functions. They
147-
should not be used anywhere else, otherwise
148-
the behavior is undefined.
149-
*/
150-
class MRDOX_DECL
151-
Param
152-
{
153-
enum class Kind
154-
{
155-
Undefined,
156-
Null,
157-
Boolean,
158-
Integer,
159-
Unsigned,
160-
Double,
161-
String,
162-
Value,
163-
DomArray,
164-
DomObject
165-
};
166-
167-
Kind kind_ = Kind::Undefined;
168-
169-
union
170-
{
171-
bool b_;
172-
int i_;
173-
unsigned int u_;
174-
double d_;
175-
int idx_; // for Value
176-
std::string_view s_;
177-
dom::Array arr_;
178-
dom::Object obj_;
179-
};
180-
181-
friend struct Access;
182-
void push(Scope&) const;
183-
Param(Param&&) noexcept;
184-
185-
public:
186-
~Param();
187-
Param(std::nullptr_t) noexcept;
188-
Param(int) noexcept;
189-
Param(unsigned int) noexcept;
190-
Param(double) noexcept;
191-
Param(std::string_view s) noexcept;
192-
Param(Value const& value) noexcept;
193-
Param(dom::Array const& arr) noexcept;
194-
Param(dom::Object const& obj) noexcept;
195-
Param(dom::Value const& value) noexcept;
196-
197-
Param(Param const&) = delete;
198-
Param& operator=(Param const&) = delete;
199-
200-
template<class Boolean>
201-
requires std::is_same_v<Boolean, bool>
202-
Param(Boolean const& b) noexcept
203-
: kind_(Kind::Boolean)
204-
, b_(b)
205-
{
206-
}
207-
208-
Param(char const* s) noexcept
209-
: Param(std::string_view(s))
210-
{
211-
}
212-
213-
template<class String>
214-
requires std::is_convertible_v<
215-
String, std::string_view>
216-
Param(String const& s)
217-
: Param(std::string_view(s))
218-
{
219-
}
220-
221-
template<class Enum>
222-
requires std::is_enum_v<Enum>
223-
Param(Enum v) noexcept
224-
: kind_(Kind::Integer)
225-
, i_(static_cast<int>(v))
226-
{
227-
}
228-
};
229-
230-
//------------------------------------------------
231-
232144
/** An ECMAScript value.
233145
*/
234146
class Value
@@ -262,14 +174,14 @@ class Value
262174
std::string getString() const;
263175

264176
void setlog();
177+
265178
/** Call a function.
266179
*/
267180
template<class... Args>
268181
Expected<Value>
269182
call(Args&&... args) const
270183
{
271-
std::array<Param, sizeof...(args)> va{ Param(args)... };
272-
return callImpl(va.data(), va.size());
184+
return callImpl({ dom::Value(std::forward<Args>(args))... });
273185
}
274186

275187
/** Call a function.
@@ -289,23 +201,21 @@ void setlog();
289201
std::string_view prop,
290202
Args&&... args) const
291203
{
292-
std::array<Param, sizeof...(args)> va{ Param(args)... };
293-
return callPropImpl(prop, va.data(), va.size());
204+
return callPropImpl(prop,
205+
{ dom::Value(std::forward<Args>(args))... });
294206
}
295207

296208
private:
297209
MRDOX_DECL
298210
Expected<Value>
299211
callImpl(
300-
Param const* data,
301-
std::size_t size) const;
212+
std::initializer_list<dom::Value> args) const;
302213

303214
MRDOX_DECL
304215
Expected<Value>
305216
callPropImpl(
306217
std::string_view prop,
307-
Param const* data,
308-
std::size_t size) const;
218+
std::initializer_list<dom::Value> args) const;
309219
};
310220

311221
inline bool Value::isUndefined() const noexcept

0 commit comments

Comments
 (0)