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
2e04868c
Commit
2e04868c
authored
Dec 14, 2016
by
Richard van der Hoff
Committed by
GitHub
Dec 14, 2016
Browse files
Merge pull request #38 from matrix-org/rav/handle_load_exceptions
Better handling of exceptions during loading, and import OLM_OPTIONS
parents
f6c05be8
51b141ec
Changes
2
Show whitespace changes
Inline
Side-by-side
javascript/olm_post.js
View file @
2e04868c
...
...
@@ -419,4 +419,22 @@ olm_exports["get_library_version"] = restore_stack(function() {
getValue
(
buf
+
2
,
'
i8
'
),
];
});
}();
})();
// export the olm functions into the environment.
//
// make sure that we do this *after* populating olm_exports, so that we don't
// get a half-built window.Olm if there is an exception.
if
(
typeof
module
!==
'
undefined
'
&&
module
.
exports
)
{
// node / browserify
module
.
exports
=
olm_exports
;
}
if
(
typeof
(
window
)
!==
'
undefined
'
)
{
// We've been imported directly into a browser. Define the global 'Olm' object.
// (we do this even if module.exports was defined, because it's useful to have
// Olm in the global scope for browserified and webpacked apps.)
window
[
"
Olm
"
]
=
olm_exports
;
}
javascript/olm_pre.js
View file @
2e04868c
...
...
@@ -2,32 +2,32 @@ var olm_exports = {};
var
get_random_values
;
var
process
;
// Shadow the process object so that emscripten won't get
// confused by browserify
if
(
typeof
(
global
)
!==
'
undefined
'
&&
global
[
"
window
"
])
{
// We're running with browserify
module
[
"
exports
"
]
=
olm_exports
;
global
[
"
window
"
][
"
Olm
"
]
=
olm_exports
;
get_random_values
=
function
(
buf
)
{
window
.
crypto
.
getRandomValues
(
buf
);
};
}
else
if
(
typeof
(
window
)
!==
'
undefined
'
)
{
// We've been imported directly into a browser.
window
[
"
Olm
"
]
=
olm_exports
;
if
(
typeof
(
window
)
!==
'
undefined
'
)
{
// We've in a browser (directly, via browserify, or via webpack).
get_random_values
=
function
(
buf
)
{
window
.
crypto
.
getRandomValues
(
buf
);
};
}
else
if
(
module
[
"
exports
"
])
{
// We're running in node.
module
[
"
exports
"
]
=
olm_exports
;
var
nodeCrypto
=
require
(
"
crypto
"
);
get_random_values
=
function
(
buf
)
{
var
bytes
=
nodeCrypto
.
randomBytes
(
buf
.
length
);
buf
.
set
(
bytes
);
}
}
;
process
=
global
[
"
process
"
];
}
else
{
throw
new
Error
(
"
Cannot find global to attach library to
"
);
}
var
init
=
function
()
{
var
module
;
// Shadow the Node 'module' object so that emscripten won't try
// to fiddle with it.
(
function
()
{
/* applications should define OLM_OPTIONS in the environment to override
* emscripten module settings */
var
Module
=
{};
if
(
typeof
(
OLM_OPTIONS
)
!==
'
undefined
'
)
{
for
(
var
key
in
OLM_OPTIONS
)
{
if
(
OLM_OPTIONS
.
hasOwnProperty
(
key
))
{
Module
[
key
]
=
OLM_OPTIONS
[
key
];
}
}
}
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