mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::js: Fix trap object production / object construction.
This commit is contained in:
parent
61017f4cdc
commit
411bed10b1
3 changed files with 59 additions and 18 deletions
44
include/ircd/js/ctor.h
Normal file
44
include/ircd/js/ctor.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Charybdis Development Team
|
||||
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice is present in all copies.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_JS_CTOR_H
|
||||
|
||||
namespace ircd {
|
||||
namespace js {
|
||||
|
||||
inline object
|
||||
ctor(const object::handle &proto,
|
||||
const vector<value>::handle &args = {})
|
||||
{
|
||||
return JS_New(*cx, proto, args);
|
||||
}
|
||||
|
||||
inline object
|
||||
ctor(trap &trap,
|
||||
const vector<value>::handle &args = {})
|
||||
{
|
||||
object proto(trap());
|
||||
return JS_New(*cx, proto, args);
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
} // namespace ircd
|
|
@ -88,6 +88,7 @@ inline JSVersion version(const char *const &v) { return JS_StringToVersion(v);
|
|||
#include "args.h"
|
||||
#include "trap.h"
|
||||
#include "trap_function.h"
|
||||
#include "ctor.h"
|
||||
#include "generator.h"
|
||||
#include "global.h"
|
||||
#include "contract.h"
|
||||
|
|
|
@ -35,6 +35,11 @@ class trap
|
|||
std::unique_ptr<JSClass> _class;
|
||||
std::map<std::string, trap *> children;
|
||||
|
||||
static trap &from(const JSObject &);
|
||||
static trap &from(const JS::HandleObject &);
|
||||
|
||||
void debug(const char *fmt, ...) const AFP(2, 3);
|
||||
|
||||
// Override these to define JS objects in C
|
||||
virtual value on_call(object::handle, value::handle, const args &);
|
||||
virtual value on_set(object::handle, id::handle, value::handle);
|
||||
|
@ -48,13 +53,9 @@ class trap
|
|||
virtual void on_gc(JSObject &);
|
||||
|
||||
private:
|
||||
void host_exception(const char *fmt, ...) const AFP(2, 3);
|
||||
void debug(const char *fmt, ...) const AFP(2, 3);
|
||||
void add_this();
|
||||
void del_this();
|
||||
|
||||
static trap &from(const JSObject &);
|
||||
static trap &from(const JS::HandleObject &);
|
||||
void host_exception(const char *fmt, ...) const AFP(2, 3);
|
||||
|
||||
// Internal callback interface
|
||||
static void handle_trace(JSTracer *, JSObject *) noexcept;
|
||||
|
@ -85,8 +86,8 @@ class trap
|
|||
operator const JSClass *() const { return &jsclass(); }
|
||||
|
||||
IRCD_OVERLOAD(prototyped)
|
||||
template<class... args> object operator()(prototyped_t, const object &parent, const object &proto, args&&...);
|
||||
template<class... args> object operator()(const object &parent, args&&...);
|
||||
object operator()(prototyped_t, const object &parent, const object &proto);
|
||||
object operator()(const object &parent = {});
|
||||
|
||||
trap(const std::string &path, const uint &flags = 0, const uint &prop_flags = 0);
|
||||
trap(trap &&) = delete;
|
||||
|
@ -96,20 +97,16 @@ class trap
|
|||
|
||||
extern __thread trap *tree;
|
||||
|
||||
template<class... args>
|
||||
object
|
||||
trap::operator()(const object &parent,
|
||||
args&&... a)
|
||||
inline object
|
||||
trap::operator()(const object &parent)
|
||||
{
|
||||
return operator()(prototyped, parent, object{}, std::forward<args>(a)...);
|
||||
return operator()(prototyped, parent, object{});
|
||||
}
|
||||
|
||||
template<class... args>
|
||||
object
|
||||
inline object
|
||||
trap::operator()(prototyped_t,
|
||||
const object &parent,
|
||||
const object &parent_proto,
|
||||
args&&... a)
|
||||
const object &parent_proto)
|
||||
{
|
||||
object proto(JS_InitClass(*cx,
|
||||
parent,
|
||||
|
@ -121,8 +118,7 @@ trap::operator()(prototyped_t,
|
|||
fs,
|
||||
nullptr,
|
||||
nullptr));
|
||||
|
||||
return JS_New(*cx, proto, vector<value>{std::forward<args>(a)...});
|
||||
return proto;
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
|
Loading…
Reference in a new issue