Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
030e506c
Commit
030e506c
authored
Oct 06, 2020
by
Lukas Lihotzki
Browse files
use stackAlloc instead of allocate
parent
22f85d3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
javascript/olm_post.js
View file @
030e506c
...
...
@@ -2,12 +2,20 @@ var malloc = Module['_malloc'];
var
free
=
Module
[
'
_free
'
];
var
OLM_ERROR
;
function
filled_stack
(
size
,
filler
)
{
var
ptr
=
stackAlloc
(
size
);
filler
(
new
Uint8Array
(
Module
[
'
HEAPU8
'
].
buffer
,
ptr
,
size
));
return
ptr
;
}
/* allocate a number of bytes of storage on the stack.
*
* If size_or_array is a Number, allocates that number of zero-initialised bytes.
*/
function
stack
(
size_or_array
)
{
return
allocate
(
size_or_array
,
'
i8
'
,
Module
[
'
ALLOC_STACK
'
]);
return
(
typeof
size_or_array
==
'
number
'
)
?
filled_stack
(
size_or_array
,
function
(
x
)
{
x
.
fill
(
0
)
})
:
filled_stack
(
size_or_array
.
length
,
function
(
x
)
{
x
.
set
(
size_or_array
)
});
}
function
array_from_string
(
string
)
{
...
...
@@ -15,10 +23,7 @@ function array_from_string(string) {
}
function
random_stack
(
size
)
{
var
ptr
=
stack
(
size
);
var
array
=
new
Uint8Array
(
Module
[
'
HEAPU8
'
].
buffer
,
ptr
,
size
);
get_random_values
(
array
);
return
ptr
;
return
filled_stack
(
size
,
get_random_values
);
}
function
restore_stack
(
wrapped
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment