mirror of
https://github.com/matrix-construct/construct
synced 2024-12-31 18:04:06 +01:00
ircd::js: Fix the JS_EncodeScript -> JS::EncodeScript for latest esr52.
This commit is contained in:
parent
6ddbe2b25d
commit
cc85c1cd35
1 changed files with 28 additions and 6 deletions
34
ircd/js.cc
34
ircd/js.cc
|
@ -1402,15 +1402,37 @@ ircd::js::bytecodes(const JS::Handle<JSScript *> &s,
|
|||
uint8_t *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
uint32_t len(0);
|
||||
const custom_ptr<void> ptr
|
||||
JS::TranscodeBuffer tcbuf;
|
||||
const auto code
|
||||
{
|
||||
//JS_EncodeScript(*cx, s, &len), js_free
|
||||
JS::EncodeScript(*cx, tcbuf, s)
|
||||
};
|
||||
|
||||
const auto ret(std::min(size_t(len), max));
|
||||
memcpy(buf, ptr.get(), ret);
|
||||
return ret;
|
||||
switch(code)
|
||||
{
|
||||
case JS::TranscodeResult_Ok:
|
||||
{
|
||||
if(unlikely(tcbuf.length() > max))
|
||||
throw internal_error
|
||||
{
|
||||
"Insufficient buffer size %zu where %zu is required.",
|
||||
max,
|
||||
tcbuf.length()
|
||||
};
|
||||
|
||||
memcpy(buf, tcbuf.begin(), tcbuf.length());
|
||||
return tcbuf.length();
|
||||
}
|
||||
|
||||
case JS::TranscodeResult_Throw:
|
||||
throw jserror(jserror::pending);
|
||||
|
||||
default:
|
||||
throw internal_error
|
||||
{
|
||||
"Failed to encode script to XDR (error %d)", code
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
ircd::js::string
|
||||
|
|
Loading…
Reference in a new issue